diff options
| author | Malo Bourgon <mbourgon@gmail.com> | 2024-03-25 16:34:10 -0700 |
|---|---|---|
| committer | Malo Bourgon <mbourgon@gmail.com> | 2024-03-27 12:50:04 -0700 |
| commit | 398510f601cb1a1978a393814514f9ca9fbcfe72 (patch) | |
| tree | 5fbf5ed358041c70c9f50419b2e35504b9eff856 /modules/services | |
| parent | bcc8afd06e237df060c85bad6af7128e05fd61a3 (diff) | |
Add `nix.optimise` module
Diffstat (limited to 'modules/services')
| -rw-r--r-- | modules/services/nix-optimise/default.nix | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/modules/services/nix-optimise/default.nix b/modules/services/nix-optimise/default.nix new file mode 100644 index 0000000..5462bae --- /dev/null +++ b/modules/services/nix-optimise/default.nix @@ -0,0 +1,73 @@ +# Based off: +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/nix-optimise.nix +# When making changes please try to keep it in sync. +{ config, lib, ... }: + + +let + inherit (lib) + mdDoc + mkIf + mkOption + mkRemovedOptionModule + optionalString + types + ; + + cfg = config.nix.optimise; +in + +{ + imports = [ + (mkRemovedOptionModule [ "nix" "optimise" "dates" ] "Use `nix.optimise.interval` instead.") + ]; + + ###### interface + + options = { + + nix.optimise = { + + automatic = mkOption { + type = types.bool; + default = false; + description = mdDoc "Automatically run the nix store optimiser at a specific time."; + }; + + # Not in NixOS module + user = mkOption { + type = types.nullOr types.str; + default = null; + description = mdDoc "User that runs the store optimisation."; + }; + + interval = mkOption { + type = types.attrs; + default = { Hour = 3; Minute = 15; }; + description = mdDoc "The time interval at which the optimiser will run."; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.automatic { + + launchd.daemons.nix-optimise = { + environment.NIX_REMOTE = optionalString config.nix.useDaemon "daemon"; + serviceConfig = { + ProgramArguments = [ + "/bin/sh" "-c" + "/bin/wait4path ${config.nix.package} && exec ${config.nix.package}/bin/nix-store --optimise" + ]; + RunAtLoad = false; + StartCalendarInterval = [ cfg.interval ]; + UserName = cfg.user; + }; + }; + + }; +} |
