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;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "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;
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
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
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
timers.nix-optimise.timerConfig = {
|
|
|
|
Persistent = true;
|
|
|
|
RandomizedDelaySec = 1800;
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|