diff --git a/mod.nix b/mod.nix index 73599c9..15de45d 100644 --- a/mod.nix +++ b/mod.nix @@ -38,6 +38,24 @@ in type = with types; listOf path; default = [ ]; }; + gc = { + enable = mkEnableOption "delete old snippets"; + dates = mkOption { + type = types.str; + default = "00:00"; + description = '' + Specification (in the format described by + systemd.time + 7) of the time at + which the garbage collector will run. + ''; + }; + maxAge = mkOption { + type = types.ints.positive; + default = 60 * 24 * 30; + description = "maximum age in minutes after which snippets will be garbage collected. Defaults to 30 days"; + }; + }; }; options.programs.brownpaper = { enable = mkEnableOption "brownpaper client"; @@ -72,6 +90,10 @@ in User = cfg.user; }; }; + systemd.services.brownpaper-gc = mkIf (cfg.enable && cfg.gc.enable) { + startAt = cfg.gc.dates; + script = "${pkgs.findutils}/bin/find ${cfg.dataDir} -maxdepth 1 -type f -mmin +${toString cfg.gc.maxAge} -delete"; + }; environment.systemPackages = optionals cfgc.enable [ (pkgs.writeShellScriptBin "brownpaper" '' BROWNPAPER_ENDPOINT='${cfgc.endpoint}' ${(pkgs.callPackage ./. { inherit pkgs; src = ./.; }).client}/bin/brownpaper "$@"