1
0

modules/clerie-gc-dir: regularly clean up downloads directory

This commit is contained in:
clerie 2023-07-01 11:59:12 +02:00
parent 4b40063bc2
commit 9dae541043
3 changed files with 75 additions and 0 deletions

View File

@ -22,4 +22,16 @@
dataDir = "/home/clerie";
configDir = "/home/clerie/.config/syncthing";
};
services.clerie-gc-dir.enable = true;
services.clerie-gc-dir.dirs = {
clerie-downloads = {
user = "clerie";
dir = "/home/clerie/Downloads";
};
clerie-tmp = {
user = "clerie";
dir = "/home/clerie/tmp";
};
};
}

View File

@ -0,0 +1,62 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.clerie-gc-dir;
gcdirServices = mapAttrs' (name: options:
nameValuePair "clerie-gc-dir-${name}" {
serviceConfig = {
Type = "oneshot";
User = options.user;
#Group = if (options.group) != null then options.group else config.users.user.${options.user}.group;
};
script = ''
find ${options.dir} -depth -mindepth 1 -mtime +20 -delete
'';
}
) cfg.dirs;
gcdirTimers = mapAttrs' (name: options:
nameValuePair "clerie-gc-dir-${name}" {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "hourly";
RandomizedDelaySec = "1h";
};
after = [ "network-online.target" ];
}
) cfg.dirs;
dirOptions = { ... }: {
options = {
user = mkOption {
type = types.str;
};
group = mkOption {
type = with types; nullOr str;
default = null;
};
dir = mkOption {
type = types.str;
};
};
};
in {
options = {
services.clerie-gc-dir = {
enable = mkEnableOption "clerie's Directory Garbage Collector";
dirs = mkOption {
type = with types; attrsOf (submodule dirOptions);
default = {};
};
};
};
config = mkIf cfg.enable {
systemd.services = gcdirServices;
systemd.timers = gcdirTimers;
};
}

View File

@ -7,6 +7,7 @@
./anycast_healthchecker
./backup
./clerie-firewall
./clerie-gc-dir
./gre-tunnel
./minecraft-server
./monitoring