Merge pull request #232920 from SuperSandro2000/nix-optimise
nixos/nix-optimise: persist timer
This commit is contained in:
commit
135fef712e
1 changed files with 13 additions and 18 deletions
|
@ -1,28 +1,21 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.nix.optimise;
|
cfg = config.nix.optimise;
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
###### interface
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
nix.optimise = {
|
nix.optimise = {
|
||||||
|
automatic = lib.mkOption {
|
||||||
automatic = mkOption {
|
|
||||||
default = false;
|
default = false;
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
description = lib.mdDoc "Automatically run the nix store optimiser at a specific time.";
|
description = lib.mdDoc "Automatically run the nix store optimiser at a specific time.";
|
||||||
};
|
};
|
||||||
|
|
||||||
dates = mkOption {
|
dates = lib.mkOption {
|
||||||
default = ["03:45"];
|
default = ["03:45"];
|
||||||
type = types.listOf types.str;
|
type = with lib.types; listOf str;
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
Specification (in the format described by
|
Specification (in the format described by
|
||||||
{manpage}`systemd.time(7)`) of the time at
|
{manpage}`systemd.time(7)`) of the time at
|
||||||
|
@ -32,9 +25,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
###### implementation
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
|
@ -43,14 +33,19 @@ in
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.nix-optimise = lib.mkIf config.nix.enable
|
systemd = lib.mkIf config.nix.enable {
|
||||||
{ description = "Nix Store Optimiser";
|
services.nix-optimise = {
|
||||||
|
description = "Nix Store Optimiser";
|
||||||
# No point this if the nix daemon (and thus the nix store) is outside
|
# No point this if the nix daemon (and thus the nix store) is outside
|
||||||
unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
|
unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
|
||||||
serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
|
serviceConfig.ExecStart = "${config.nix.package}/bin/nix-store --optimise";
|
||||||
startAt = optionals cfg.automatic cfg.dates;
|
startAt = lib.optionals cfg.automatic cfg.dates;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
timers.nix-optimise.timerConfig = {
|
||||||
|
Persistent = true;
|
||||||
|
RandomizedDelaySec = 1800;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue