mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +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,41 +1,168 @@
|
||||
{ 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 {
|
||||
options.services.archivebox = {
|
||||
enable = lib.mkEnableOption "Archivebox service";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
description = "The port number to be used for the server at localhost.";
|
||||
default = 8000;
|
||||
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 {
|
||||
systemd.user.services.archivebox-server = {
|
||||
Unit = {
|
||||
Description = "Archivebox server for ${cfg.archivePath}";
|
||||
After = "network.target";
|
||||
Documentation = [ "https://docs.archivebox.io/" ];
|
||||
};
|
||||
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";
|
||||
};
|
||||
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
research = {
|
||||
links = [
|
||||
"https://arxiv.org/rss/cs"
|
||||
"https://distill.pub/"
|
||||
];
|
||||
extraOptions = [ "--depth 1" ];
|
||||
startAt = "daily";
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${
|
||||
toString cfg.port
|
||||
}";
|
||||
WorkingDirectory = cfg.archivePath;
|
||||
Restart = "on-failure";
|
||||
withDependencies =
|
||||
lib.mkEnableOption "additional dependencies to be installed";
|
||||
|
||||
webserver = {
|
||||
enable = lib.mkEnableOption "web UI for Archivebox";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
description = "The port number to be used for the server at localhost.";
|
||||
default = 8000;
|
||||
example = 8888;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
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 = {
|
||||
Description = "Archivebox server for ${cfg.archivePath}";
|
||||
After = "network.target";
|
||||
Documentation = [ "https://docs.archivebox.io/" ];
|
||||
};
|
||||
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
|
||||
Service = {
|
||||
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${
|
||||
toString cfg.webserver.port
|
||||
}";
|
||||
WorkingDirectory = cfg.archivePath;
|
||||
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;
|
||||
};
|
||||
|
||||
services = {
|
||||
archivebox = {
|
||||
enable = true;
|
||||
archivePath = "%h/library/archives";
|
||||
services.archivebox = {
|
||||
enable = true;
|
||||
archivePath = "%h/library/archives";
|
||||
withDependencies = true;
|
||||
|
||||
jobs = {
|
||||
arts = {
|
||||
links = [
|
||||
"https://www.davidrevoy.com/feed/rss"
|
||||
"https://www.youtube.com/c/ronillust"
|
||||
];
|
||||
startAt = "weekly";
|
||||
};
|
||||
|
||||
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";
|
||||
};
|
||||
};
|
||||
bleachbit.enable = true;
|
||||
};
|
||||
|
||||
services.bleachbit.enable = true;
|
||||
|
||||
home.sessionVariables = {
|
||||
MANPAGER = "nvim +Man!";
|
||||
EDITOR = "nvim";
|
||||
|
Loading…
Reference in New Issue
Block a user