From d92f0e811767c3bb9e838489f3299b80845b4f99 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Sun, 5 Mar 2017 20:37:56 +0100 Subject: [PATCH] nix-gc: init service --- default.nix | 1 + modules/services/nix-gc.nix | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 modules/services/nix-gc.nix diff --git a/default.nix b/default.nix index 28316f7..4da081f 100644 --- a/default.nix +++ b/default.nix @@ -40,6 +40,7 @@ let ./modules/services/kwm.nix ./modules/services/emacs.nix ./modules/services/nix-daemon.nix + ./modules/services/nix-gc.nix ./modules/programs/bash.nix ./modules/programs/fish.nix ./modules/programs/nix-script.nix diff --git a/modules/services/nix-gc.nix b/modules/services/nix-gc.nix new file mode 100644 index 0000000..0dc704b --- /dev/null +++ b/modules/services/nix-gc.nix @@ -0,0 +1,55 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.nix.gc; +in + +{ + options = { + nix.gc = { + + automatic = mkOption { + default = false; + type = types.bool; + description = "Automatically run the garbage collector at a specific time."; + }; + + # TODO: parse dates + # dates = mkOption { + # default = "03:15"; + # type = types.str; + # description = '' + # Specification (in the format described by + # systemd.time + # 5) of the time at + # which the garbage collector will run. + # ''; + # }; + + options = mkOption { + default = ""; + example = "--max-freed $((64 * 1024**3))"; + type = types.str; + description = '' + Options given to nix-collect-garbage when the + garbage collector is run automatically. + ''; + }; + + }; + }; + + config = mkIf cfg.automatic { + + launchd.daemons.nix-gc = { + command = "${config.nix.package}/bin/nix-collect-garbage ${cfg.options}"; + serviceConfig.RunAtLoad = false; + serviceConfig.StartCalendarInterval = mkDefault + [ { Hour = 3; Minute = 15; } + ]; + }; + + }; +}