From f4a6f9e84bd51611a924aecf6c7c23e149f13215 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 4 Dec 2009 12:50:44 +0000 Subject: [PATCH] * Add options to handle automatic calls to the garbage collector. These options avoid manual references to pkgs.nixUnstable which might be changed with environment.nix option. svn path=/nixos/trunk/; revision=18798 --- modules/module-list.nix | 1 + modules/services/misc/nix-gc.nix | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 modules/services/misc/nix-gc.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index f80d4d6a586..d793c715202 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -54,6 +54,7 @@ ./services/misc/disnix.nix ./services/misc/gpsd.nix ./services/misc/nix-daemon.nix + ./services/misc/nix-gc.nix ./services/misc/nixos-manual.nix ./services/misc/rogue.nix ./services/misc/synergy.nix diff --git a/modules/services/misc/nix-gc.nix b/modules/services/misc/nix-gc.nix new file mode 100644 index 00000000000..942e7996da0 --- /dev/null +++ b/modules/services/misc/nix-gc.nix @@ -0,0 +1,54 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + nix = config.environment.nix; + cfg = config.nix.gc; +in + +{ + + ###### interface + + options = { + nix.gc = { + + automatic = mkOption { + default = false; + example = true; + description = " + Automatically run the garbage collector at specified dates. + "; + }; + + dates = mkOption { + default = "15 03 * * *"; + description = " + Run the garbage collector at specified dates to avoid full + hard-drives. + "; + }; + + options = mkOption { + default = ""; + example = "--max-freed $((64 * 1024**3))"; + description = " + Options given to nix-collect-garbage when the + garbage collector is run automatically. + "; + }; + + }; + }; + + + ###### implementation + + config = mkIf cfg.automatic { + services.cron.systemCronJobs = [ + "${cfg.dates} root ${nix}/bin/nix-collect-garbage ${cfg.options} > /var/log/gc.log 2>&1" + ]; + }; + +}