1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-09 18:27:00 +00:00
nix-darwin/modules/services/nix-optimise/default.nix

78 lines
1.8 KiB
Nix
Raw Normal View History

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;
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 {
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;
StartCalendarInterval = cfg.interval;
2024-03-25 16:34:10 -07:00
UserName = cfg.user;
};
};
};
}