2009-12-04 12:50:44 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.nix.gc;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
nix.gc = {
|
|
|
|
|
|
|
|
automatic = mkOption {
|
|
|
|
default = false;
|
2013-01-04 13:04:41 +00:00
|
|
|
type = types.bool;
|
2009-12-04 12:50:44 +00:00
|
|
|
description = "
|
|
|
|
Automatically run the garbage collector at specified dates.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
dates = mkOption {
|
|
|
|
default = "15 03 * * *";
|
2013-01-04 13:04:41 +00:00
|
|
|
type = types.string;
|
2009-12-04 12:50:44 +00:00
|
|
|
description = "
|
|
|
|
Run the garbage collector at specified dates to avoid full
|
|
|
|
hard-drives.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
options = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = "--max-freed $((64 * 1024**3))";
|
2013-01-04 13:04:41 +00:00
|
|
|
type = types.string;
|
2009-12-04 12:50:44 +00:00
|
|
|
description = "
|
|
|
|
Options given to <filename>nix-collect-garbage</filename> when the
|
|
|
|
garbage collector is run automatically.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-01-04 13:04:41 +00:00
|
|
|
config = {
|
|
|
|
|
|
|
|
services.cron.systemCronJobs = mkIf cfg.automatic (singleton
|
2013-01-16 12:17:57 +00:00
|
|
|
"${cfg.dates} root ${config.systemd.package}/bin/systemctl start nix-gc.service");
|
2013-01-04 13:04:41 +00:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services."nix-gc" =
|
2013-01-04 13:04:41 +00:00
|
|
|
{ description = "Nix Garbage Collector";
|
2013-01-05 00:35:26 +00:00
|
|
|
path = [ config.environment.nix ];
|
|
|
|
script = "exec nix-collect-garbage ${cfg.options}";
|
2013-01-04 13:04:41 +00:00
|
|
|
};
|
|
|
|
|
2009-12-04 12:50:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|