2023-11-07 12:47:22 +00:00
|
|
|
{ config, lib, pkgs, utils, ... }:
|
2022-07-05 14:23:19 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.archivebox;
|
2023-11-07 12:47:22 +00:00
|
|
|
jobUnitName = name: "archivebox-job-${utils.escapeSystemdPath name}";
|
2022-07-05 14:23:19 +00:00
|
|
|
jobType = { name, options, ... }: {
|
|
|
|
options = {
|
2022-07-31 06:42:18 +00:00
|
|
|
urls = lib.mkOption {
|
2022-07-05 14:23:19 +00:00
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = "List of links to archive.";
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"https://guix.gnu.org/feeds/blog.atom"
|
|
|
|
"https://nixos.org/blog/announcements-rss.xml"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
2023-07-27 03:13:39 +00:00
|
|
|
Additional arguments for adding links (i.e., {command}`archivebox add
|
|
|
|
$LINK`) from {option}`links`.
|
2022-07-05 14:23:19 +00:00
|
|
|
'';
|
|
|
|
default = [ ];
|
|
|
|
example = lib.literalExpression ''
|
2022-07-31 06:42:18 +00:00
|
|
|
[ "--depth" "1" ]
|
2022-07-05 14:23:19 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
startAt = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
description = ''
|
2023-07-27 03:13:39 +00:00
|
|
|
Indicates how frequent the scheduled archiving will occur. Should be
|
|
|
|
a valid string format as described from {manpage}`systemd.time(5)`.
|
2022-07-05 14:23:19 +00:00
|
|
|
'';
|
|
|
|
default = "weekly";
|
|
|
|
defaultText = "weekly";
|
|
|
|
example = "*-*-01/2";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-10-27 05:23:37 +00:00
|
|
|
|
|
|
|
mkJobService = name: value:
|
|
|
|
lib.nameValuePair
|
|
|
|
(jobUnitName name)
|
|
|
|
{
|
2023-11-07 12:53:45 +00:00
|
|
|
description = "Archivebox download group '${name}'";
|
2023-10-27 05:23:37 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
documentation = [ "https://docs.archivebox.io/" ];
|
|
|
|
preStart = ''
|
2023-12-13 03:28:45 +00:00
|
|
|
mkdir -p ${lib.escapeShellArg cfg.archivePath}
|
2023-10-27 05:23:37 +00:00
|
|
|
'';
|
2023-11-07 12:51:47 +00:00
|
|
|
path = [ cfg.package ] ++ cfg.extraPackages;
|
2023-10-27 05:23:37 +00:00
|
|
|
script = ''
|
2023-11-07 12:53:45 +00:00
|
|
|
echo "${lib.concatStringsSep "\n" value.urls}" \
|
2023-11-08 13:09:05 +00:00
|
|
|
| archivebox add ${lib.escapeShellArgs value.extraArgs}
|
2023-10-27 05:23:37 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
2023-11-07 12:53:15 +00:00
|
|
|
User = "archivebox";
|
|
|
|
Group = "archivebox";
|
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
2023-11-07 12:53:45 +00:00
|
|
|
|
|
|
|
CapabilityBoundingSet = [ ];
|
|
|
|
AmbientCapabilities = [ ];
|
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
2023-11-07 12:53:45 +00:00
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
2023-11-07 12:53:45 +00:00
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_LOCAL"
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
|
|
|
|
SystemCallFilter = [ "@system-service" ];
|
2023-10-27 05:23:37 +00:00
|
|
|
SystemCallErrorNumber = "EPERM";
|
2023-11-07 12:38:00 +00:00
|
|
|
|
|
|
|
StateDirectory = "archivebox";
|
2023-10-27 05:23:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkTimerUnit = name: value:
|
|
|
|
lib.nameValuePair (jobUnitName name) {
|
|
|
|
description =
|
|
|
|
"Archivebox download job '${name}'";
|
2023-12-13 03:28:45 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
documentation = [ "https://docs.archivebox.io/" ];
|
|
|
|
timerConfig = {
|
|
|
|
Persistent = true;
|
|
|
|
OnCalendar = value.startAt;
|
|
|
|
RandomizedDelaySec = 120;
|
|
|
|
};
|
|
|
|
wantedBy = [ "timers.target" ];
|
2023-10-27 05:23:37 +00:00
|
|
|
};
|
2022-11-19 03:05:31 +00:00
|
|
|
in
|
|
|
|
{
|
2022-07-05 14:23:19 +00:00
|
|
|
options.services.archivebox = {
|
|
|
|
enable = lib.mkEnableOption "Archivebox service";
|
|
|
|
|
2023-11-07 12:51:47 +00:00
|
|
|
package = lib.mkPackageOption pkgs "archivebox" { };
|
|
|
|
|
2022-07-05 14:23:19 +00:00
|
|
|
jobs = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule jobType);
|
|
|
|
description = "A map of archiving tasks for the service.";
|
|
|
|
default = { };
|
|
|
|
defaultText = lib.literalExpression "{}";
|
2023-11-07 12:50:37 +00:00
|
|
|
example = {
|
|
|
|
illustration = {
|
|
|
|
urls = [
|
|
|
|
"https://www.davidrevoy.com/"
|
|
|
|
"https://www.youtube.com/c/ronillust"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
2022-07-05 14:23:19 +00:00
|
|
|
|
2023-11-07 12:50:37 +00:00
|
|
|
research = {
|
|
|
|
urls = [
|
|
|
|
"https://arxiv.org/rss/cs"
|
|
|
|
"https://distill.pub/"
|
|
|
|
];
|
2023-11-08 13:09:05 +00:00
|
|
|
extraArgs = [ "--depth" "1" ];
|
2023-11-07 12:50:37 +00:00
|
|
|
startAt = "daily";
|
|
|
|
};
|
|
|
|
};
|
2022-07-05 14:23:19 +00:00
|
|
|
};
|
|
|
|
|
2023-11-07 12:51:47 +00:00
|
|
|
extraPackages = lib.mkOption {
|
|
|
|
type = with lib.types; listOf package;
|
|
|
|
description = ''
|
|
|
|
A list of additional packages to be set within the download jobs. By
|
|
|
|
default, it sets the optional dependencies of ArchiveBox for additional
|
|
|
|
download formats and capabilities.
|
|
|
|
'';
|
|
|
|
default = with pkgs; [
|
|
|
|
chromium
|
|
|
|
nodejs_latest
|
|
|
|
wget
|
|
|
|
curl
|
|
|
|
yt-dlp
|
|
|
|
] ++ lib.optional config.programs.git.enable config.programs.git.package;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
with pkgs; [
|
|
|
|
curl
|
|
|
|
yt-dlp
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
2022-07-05 14:23:19 +00:00
|
|
|
|
|
|
|
webserver = {
|
2023-11-07 12:50:37 +00:00
|
|
|
enable = lib.mkEnableOption "ArchiveBox web server";
|
2022-07-05 14:23:19 +00:00
|
|
|
|
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
|
|
|
description = "The port number to be used for the server at localhost.";
|
|
|
|
default = 8000;
|
|
|
|
example = 8888;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
|
|
|
{
|
|
|
|
systemd.services = lib.mapAttrs' mkJobService cfg.jobs;
|
|
|
|
systemd.timers = lib.mapAttrs' mkTimerUnit cfg.jobs;
|
2023-11-07 12:53:15 +00:00
|
|
|
|
|
|
|
users.users.archivebox = {
|
|
|
|
group = config.users.groups.archivebox.name;
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/var/lib/archivebox";
|
|
|
|
};
|
2023-10-27 05:23:37 +00:00
|
|
|
}
|
2022-07-05 14:23:19 +00:00
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
(lib.mkIf cfg.webserver.enable {
|
|
|
|
systemd.services.archivebox-server = {
|
2023-11-07 12:53:45 +00:00
|
|
|
description = "Archivebox web server";
|
2023-10-27 05:23:37 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
documentation = [ "https://docs.archivebox.io/" ];
|
|
|
|
wantedBy = [ "graphical-session.target" ];
|
|
|
|
serviceConfig = {
|
2023-11-07 12:53:15 +00:00
|
|
|
User = "archivebox";
|
|
|
|
Group = "archivebox";
|
2023-11-07 12:53:45 +00:00
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${
|
|
|
|
toString cfg.webserver.port
|
|
|
|
}";
|
2023-11-07 12:53:45 +00:00
|
|
|
|
|
|
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
2023-11-07 12:53:45 +00:00
|
|
|
|
2023-10-27 05:23:37 +00:00
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
2023-11-07 12:53:45 +00:00
|
|
|
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_LOCAL"
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
|
|
|
|
SystemCallFilter = [ "@system-service" ];
|
2023-10-27 05:23:37 +00:00
|
|
|
SystemCallErrorNumber = "EPERM";
|
2023-11-07 12:38:00 +00:00
|
|
|
StateDirectory = "archivebox";
|
2023-10-27 05:23:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
2022-07-05 14:23:19 +00:00
|
|
|
}
|