modules/clerie-gc-dir: regularly clean up downloads directory
This commit is contained in:
parent
4b40063bc2
commit
9dae541043
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
62
modules/clerie-gc-dir/default.nix
Normal file
62
modules/clerie-gc-dir/default.nix
Normal 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;
|
||||
};
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
./anycast_healthchecker
|
||||
./backup
|
||||
./clerie-firewall
|
||||
./clerie-gc-dir
|
||||
./gre-tunnel
|
||||
./minecraft-server
|
||||
./monitoring
|
||||
|
Loading…
Reference in New Issue
Block a user