2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.nix.optimise;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
nix.optimise = {
|
2023-07-15 17:15:38 +00:00
|
|
|
automatic = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2023-07-15 17:15:38 +00:00
|
|
|
type = lib.types.bool;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Automatically run the nix store optimiser at a specific time.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
dates = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = ["03:45"];
|
2023-07-15 17:15:38 +00:00
|
|
|
type = with lib.types; listOf str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Specification (in the format described by
|
2022-08-21 13:32:41 +00:00
|
|
|
{manpage}`systemd.time(7)`) of the time at
|
2020-04-24 23:36:52 +00:00
|
|
|
which the optimiser will run.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
config = {
|
2022-03-30 09:31:56 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.automatic -> config.nix.enable;
|
|
|
|
message = ''nix.optimise.automatic requires nix.enable'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
systemd = lib.mkIf config.nix.enable {
|
|
|
|
services.nix-optimise = {
|
|
|
|
description = "Nix Store Optimiser";
|
2020-04-24 23:36:52 +00:00
|
|
|
# No point this if the nix daemon (and thus the nix store) is outside
|
|
|
|
unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
|
|
|
|
serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
|
2023-07-15 17:15:38 +00:00
|
|
|
startAt = lib.optionals cfg.automatic cfg.dates;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
timers.nix-optimise = lib.mkIf cfg.automatic {
|
|
|
|
timerConfig = {
|
|
|
|
Persistent = true;
|
|
|
|
RandomizedDelaySec = 1800;
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|