2024-03-25 16:34:10 -07:00
|
|
|
# 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)
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
mkRemovedOptionModule
|
|
|
|
optionalString
|
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.nix.optimise;
|
2023-06-29 00:50:28 -07:00
|
|
|
launchdTypes = import ../../launchd/types.nix { inherit config lib; };
|
2024-03-25 16:34:10 -07:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "nix" "optimise" "dates" ] "Use `nix.optimise.interval` instead.")
|
|
|
|
];
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
nix.optimise = {
|
|
|
|
|
|
|
|
automatic = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-14 23:02:32 +02:00
|
|
|
description = "Automatically run the nix store optimiser at a specific time.";
|
2024-03-25 16:34:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
# Not in NixOS module
|
|
|
|
user = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2024-04-14 23:02:32 +02:00
|
|
|
description = "User that runs the store optimisation.";
|
2024-03-25 16:34:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
interval = mkOption {
|
2023-06-29 00:50:28 -07:00
|
|
|
type = launchdTypes.StartCalendarInterval;
|
|
|
|
default = [{ Weekday = 7; Hour = 4; Minute = 15; }];
|
|
|
|
description = ''
|
|
|
|
The calendar interval at which the optimiser will run.
|
|
|
|
See the {option}`serviceConfig.StartCalendarInterval` option of
|
|
|
|
the {option}`launchd` module for more info.
|
|
|
|
'';
|
2024-03-25 16:34:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### 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;
|
2023-06-29 00:50:28 -07:00
|
|
|
StartCalendarInterval = cfg.interval;
|
2024-03-25 16:34:10 -07:00
|
|
|
UserName = cfg.user;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|