mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
archivebox: update the service module
It can now add and schedule archiving tasks. Since archivebox will use Crontab module (which uses `/usr/bin/crontab`), the scheduling with the interface is out of the question. What better way to make it possible than creating a home-manager module for it?
This commit is contained in:
parent
998f408fb2
commit
ac91cdc053
@ -1,26 +1,134 @@
|
|||||||
{ config, options, lib, pkgs, ... }:
|
{ config, options, lib, pkgs, ... }:
|
||||||
|
|
||||||
let cfg = config.services.archivebox;
|
let
|
||||||
|
cfg = config.services.archivebox;
|
||||||
|
jobType = { name, options, ... }: {
|
||||||
|
options = {
|
||||||
|
links = lib.mkOption {
|
||||||
|
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"
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraOptions = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
description = ''
|
||||||
|
Additional arguments for adding links (i.e., <literal>archivebox add
|
||||||
|
$LINK</literal>) from <option>links</option>.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
[ "--depth 1" ]
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
startAt = lib.mkOption {
|
||||||
|
type = with lib.types; str;
|
||||||
|
description = ''
|
||||||
|
Indicates how frequent the scheduled archiving will occur.
|
||||||
|
Should be a valid string format as described from systemd.time(5).
|
||||||
|
'';
|
||||||
|
default = "daily";
|
||||||
|
defaultText = "daily";
|
||||||
|
example = "*-*-01/2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.services.archivebox = {
|
options.services.archivebox = {
|
||||||
enable = lib.mkEnableOption "Archivebox service";
|
enable = lib.mkEnableOption "Archivebox service";
|
||||||
|
|
||||||
|
archivePath = lib.mkOption {
|
||||||
|
type = with lib.types; either path str;
|
||||||
|
description = "The path of the Archivebox archive.";
|
||||||
|
example = "\${config.xdg.dataHome}/archivebox";
|
||||||
|
};
|
||||||
|
|
||||||
|
jobs = lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf (submodule jobType);
|
||||||
|
description = "A map of archiving tasks for the service.";
|
||||||
|
default = { };
|
||||||
|
defaultText = lib.literalExpression "{}";
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
{
|
||||||
|
illustration = {
|
||||||
|
links = [
|
||||||
|
"https://www.davidrevoy.com/"
|
||||||
|
"https://www.youtube.com/c/ronillust"
|
||||||
|
];
|
||||||
|
startAt = "weekly";
|
||||||
|
};
|
||||||
|
|
||||||
|
research = {
|
||||||
|
links = [
|
||||||
|
"https://arxiv.org/rss/cs"
|
||||||
|
"https://distill.pub/"
|
||||||
|
];
|
||||||
|
extraOptions = [ "--depth 1" ];
|
||||||
|
startAt = "daily";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
withDependencies =
|
||||||
|
lib.mkEnableOption "additional dependencies to be installed";
|
||||||
|
|
||||||
|
webserver = {
|
||||||
|
enable = lib.mkEnableOption "web UI for Archivebox";
|
||||||
|
|
||||||
port = lib.mkOption {
|
port = lib.mkOption {
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
description = "The port number to be used for the server at localhost.";
|
description = "The port number to be used for the server at localhost.";
|
||||||
default = 8000;
|
default = 8000;
|
||||||
example = 8888;
|
example = 8888;
|
||||||
};
|
};
|
||||||
|
|
||||||
archivePath = lib.mkOption {
|
|
||||||
type = with lib.types; either path str;
|
|
||||||
description = "The path of the Archivebox archive.";
|
|
||||||
example = "\${config.xdg.dataHome}/archivebox";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
systemd.user.services.archivebox-server = {
|
assertions = [
|
||||||
|
(lib.hm.assertions.assertPlatform "services.archivebox" pkgs
|
||||||
|
lib.platforms.linux)
|
||||||
|
];
|
||||||
|
|
||||||
|
home.packages = [ pkgs.archivebox ] ++ (lib.optionals cfg.withDependencies
|
||||||
|
(with pkgs; [ chromium nodejs_latest wget curl youtube-dl ]));
|
||||||
|
|
||||||
|
systemd.user.services = lib.mkMerge [
|
||||||
|
(lib.mapAttrs' (name: value:
|
||||||
|
lib.nameValuePair "archivebox-add-${name}" {
|
||||||
|
Unit = {
|
||||||
|
Description = "Archivebox archive group '${name}' for ${cfg.archivePath}";
|
||||||
|
After = "network.target";
|
||||||
|
Documentation = [ "https://docs.archivebox.io/" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
Install.WantedBy = [ "default.target" ];
|
||||||
|
|
||||||
|
Service = let
|
||||||
|
scriptName = "archivebox-job-${config.home.username}-${name}";
|
||||||
|
script = pkgs.writeShellApplication {
|
||||||
|
name = scriptName;
|
||||||
|
runtimeInputs = with pkgs; [ coreutils archivebox ];
|
||||||
|
text = ''
|
||||||
|
echo "${lib.concatStringsSep "\n" value.links}" \
|
||||||
|
| archivebox add ${lib.concatStringsSep " " value.extraOptions}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
ExecStart = "${script}/bin/${scriptName}";
|
||||||
|
WorkingDirectory = cfg.archivePath;
|
||||||
|
};
|
||||||
|
}) cfg.jobs)
|
||||||
|
|
||||||
|
(lib.mkIf cfg.webserver.enable {
|
||||||
|
archivebox-server = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Archivebox server for ${cfg.archivePath}";
|
Description = "Archivebox server for ${cfg.archivePath}";
|
||||||
After = "network.target";
|
After = "network.target";
|
||||||
@ -31,11 +139,30 @@ in {
|
|||||||
|
|
||||||
Service = {
|
Service = {
|
||||||
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${
|
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${
|
||||||
toString cfg.port
|
toString cfg.webserver.port
|
||||||
}";
|
}";
|
||||||
WorkingDirectory = cfg.archivePath;
|
WorkingDirectory = cfg.archivePath;
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.user.timers = lib.mapAttrs' (name: value:
|
||||||
|
lib.nameValuePair "archivebox-add-${name}" {
|
||||||
|
Unit = {
|
||||||
|
Description = "Archivebox additions for ${cfg.archivePath}";
|
||||||
|
After = "network.target";
|
||||||
|
Documentation = [ "https://docs.archivebox.io/" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
Timer = {
|
||||||
|
Persistent = true;
|
||||||
|
OnCalendar = value.startAt;
|
||||||
|
RandomizedDelaySec = 120;
|
||||||
|
};
|
||||||
|
|
||||||
|
Install.WantedBy = [ "timers.target" ];
|
||||||
|
}) cfg.jobs;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
BIN
secrets/archive/borg-ssh-key
Normal file
BIN
secrets/archive/borg-ssh-key
Normal file
Binary file not shown.
@ -119,14 +119,43 @@ in {
|
|||||||
research.enable = true;
|
research.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
services.archivebox = {
|
||||||
archivebox = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
archivePath = "%h/library/archives";
|
archivePath = "%h/library/archives";
|
||||||
|
withDependencies = true;
|
||||||
|
|
||||||
|
jobs = {
|
||||||
|
arts = {
|
||||||
|
links = [
|
||||||
|
"https://www.davidrevoy.com/feed/rss"
|
||||||
|
"https://www.youtube.com/c/ronillust"
|
||||||
|
];
|
||||||
|
startAt = "weekly";
|
||||||
};
|
};
|
||||||
bleachbit.enable = true;
|
|
||||||
|
computer = {
|
||||||
|
links = [
|
||||||
|
"https://distill.pub/rss.xml"
|
||||||
|
"https://fasterthanli.me/index.xml"
|
||||||
|
"https://arxiv.org/rss/cs"
|
||||||
|
"https://awesomekling.github.io/feed.xml"
|
||||||
|
];
|
||||||
|
extraOptions = [ "--depth 1" ];
|
||||||
|
startAt = "daily";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
projects = {
|
||||||
|
links = [
|
||||||
|
"https://veloren.net/rss.xml"
|
||||||
|
"https://guix.gnu.org/feeds/blog.atom"
|
||||||
|
];
|
||||||
|
startAt = "*-*-1/2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.bleachbit.enable = true;
|
||||||
|
|
||||||
home.sessionVariables = {
|
home.sessionVariables = {
|
||||||
MANPAGER = "nvim +Man!";
|
MANPAGER = "nvim +Man!";
|
||||||
EDITOR = "nvim";
|
EDITOR = "nvim";
|
||||||
|
Loading…
Reference in New Issue
Block a user