2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.nix.optimise;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
nix.optimise = {
|
|
|
|
|
|
|
|
automatic = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = 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
|
|
|
};
|
|
|
|
|
|
|
|
dates = mkOption {
|
|
|
|
default = ["03:45"];
|
|
|
|
type = types.listOf types.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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
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'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.nix-optimise = lib.mkIf config.nix.enable
|
2020-04-24 23:36:52 +00:00
|
|
|
{ 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 = optionals cfg.automatic cfg.dates;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|