2018-07-20 20:56:59 +00:00
|
|
|
{ config, lib, ... }:
|
2016-09-05 21:59:25 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.nix.optimise;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
nix.optimise = {
|
2023-05-20 00:24:32 +00:00
|
|
|
automatic = lib.mkOption {
|
2016-09-05 21:59:25 +00:00
|
|
|
default = false;
|
2023-05-20 00:24:32 +00:00
|
|
|
type = lib.types.bool;
|
2016-09-05 21:59:25 +00:00
|
|
|
description = "Automatically run the nix store optimiser at a specific time.";
|
|
|
|
};
|
|
|
|
|
2023-05-20 00:24:32 +00:00
|
|
|
dates = lib.mkOption {
|
2016-10-04 10:31:51 +00:00
|
|
|
default = ["03:45"];
|
2023-05-20 00:24:32 +00:00
|
|
|
type = with lib.types; listOf str;
|
2016-09-05 21:59:25 +00:00
|
|
|
description = ''
|
|
|
|
Specification (in the format described by
|
|
|
|
{manpage}`systemd.time(7)`) of the time at
|
|
|
|
which the optimiser will run.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2022-03-21 21:28:37 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.automatic -> config.nix.enable;
|
|
|
|
message = ''nix.optimise.automatic requires nix.enable'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-05-20 00:32:19 +00:00
|
|
|
systemd = lib.mkIf config.nix.enable {
|
|
|
|
services.nix-optimise = {
|
|
|
|
description = "Nix Store Optimiser";
|
|
|
|
# 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";
|
|
|
|
startAt = lib.optionals cfg.automatic cfg.dates;
|
|
|
|
};
|
|
|
|
|
2024-01-30 18:04:26 +00:00
|
|
|
timers.nix-optimise = lib.mkIf cfg.automatic {
|
|
|
|
timerConfig = {
|
|
|
|
Persistent = true;
|
|
|
|
RandomizedDelaySec = 1800;
|
|
|
|
};
|
2023-05-20 00:32:19 +00:00
|
|
|
};
|
2023-05-20 00:24:32 +00:00
|
|
|
};
|
2016-09-05 21:59:25 +00:00
|
|
|
};
|
|
|
|
}
|