X-Git-Url: https://git.kernelpanic.cafe/?p=MarigoldOS%2F.git;a=blobdiff_plain;f=modules%2Farchivebox.nix;fp=modules%2Farchivebox.nix;h=2e2a903968939d2a01c6bde37ff4468c219daf47;hp=0000000000000000000000000000000000000000;hb=5be69113d25ab18f3381be6cc38f60bef8b687b2;hpb=754832f815bda4c941af3e7d27a5886a17dc6043 diff --git a/modules/archivebox.nix b/modules/archivebox.nix new file mode 100644 index 0000000..2e2a903 --- /dev/null +++ b/modules/archivebox.nix @@ -0,0 +1,55 @@ +{ config, pkgs, lib, ... }: +let + cfg = config.services.archivebox; +in +{ + options.services.archivebox = { + enable = lib.mkEnableOption "Archivebox server"; + port = lib.mkOption { + type = lib.types.port; + }; + dataDir = lib.mkOption { + type = lib.types.path; + default = "/var/lib/archivebox"; + }; + user = lib.mkOption { + type = lib.types.str; + default = "archivebox"; + }; + group = lib.mkOption { + type = lib.types.str; + default = "archivebox"; + }; + }; + config = { + systemd.tmpfiles.rules = lib.mkIf cfg.enable [ + "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group}" + "Z '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group}" + ]; + systemd.services.archivebox = lib.mkIf cfg.enable { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + description = "Archives webpages in multiple formats."; + serviceConfig = { + # DynamicUser = true; + User = cfg.user; + Group = cfg.group; + ExecStart = ''${pkgs.archivebox}/bin/archivebox server --init ${toString cfg.port}''; + Restart = "always"; + Type = "simple"; + RestartSec = 1; + StateDirectory = "archivebox"; + WorkingDirectory = "${cfg.dataDir}"; + }; + }; + users.users = lib.mkIf (cfg.user == "archivebox") { # "${cfg.user.default}") { + "${cfg.user}" = { + description = "Archivebox daemon user"; + isSystemUser = true; + group = cfg.group; + home = cfg.dataDir; + }; + }; + users.groups = lib.mkIf (cfg.group == "archivebox") { "${cfg.group}" = { }; }; # What a monstrosity of a line. I make me sick. + }; +}