diff --git a/modules/home-manager/services/archivebox.nix b/modules/home-manager/services/archivebox.nix index e0cb9ce5..65d8adca 100644 --- a/modules/home-manager/services/archivebox.nix +++ b/modules/home-manager/services/archivebox.nix @@ -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., archivebox add + $LINK) from . + ''; + 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; + }; } diff --git a/secrets/archive/borg-ssh-key b/secrets/archive/borg-ssh-key new file mode 100644 index 00000000..734930be Binary files /dev/null and b/secrets/archive/borg-ssh-key differ diff --git a/users/home-manager/foo-dogsquared/default.nix b/users/home-manager/foo-dogsquared/default.nix index 473d0ba7..70576cc7 100644 --- a/users/home-manager/foo-dogsquared/default.nix +++ b/users/home-manager/foo-dogsquared/default.nix @@ -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";