4 cfg = config.nix.optimise;
10 automatic = lib.mkOption {
12 type = lib.types.bool;
13 description = "Automatically run the nix store optimiser at a specific time.";
16 dates = lib.mkOption {
18 type = with lib.types; listOf str;
20 Specification (in the format described by
21 {manpage}`systemd.time(7)`) of the time at
22 which the optimiser will run.
31 assertion = cfg.automatic -> config.nix.enable;
32 message = ''nix.optimise.automatic requires nix.enable'';
36 systemd = lib.mkIf config.nix.enable {
37 services.nix-optimise = {
38 description = "Nix Store Optimiser";
39 # No point this if the nix daemon (and thus the nix store) is outside
40 unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
41 serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
42 startAt = lib.optionals cfg.automatic cfg.dates;
45 timers.nix-optimise = lib.mkIf cfg.automatic {
48 RandomizedDelaySec = 1800;