nixos/nix-optimise: run with lower priority

It's painfully obvious to me on my anaemic system when `nix-optimise` kicks in,
so run it with much lower priority since it's not time critical anyway.

Additionally, do not run on battery power.

I can appreciate that these are oppinionated defaults but I am having a hard
imagining cases where this would be a show-stopper so there isn't much point in
making this directly configurable via the nixos module system as people can
always override the unit directly themselves via `systemd.services.nix-optimise`
This commit is contained in:
Peter H. Hoeg
2025-06-28 10:43:58 +02:00
parent 30a61f056a
commit 9ff9558990

View File

@@ -65,9 +65,17 @@ in
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";
unitConfig = {
ConditionACPower = true;
# No point this if the nix daemon (and thus the nix store) is outside
ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket";
};
serviceConfig = {
ExecStart = "${lib.getExe' config.nix.package "nix-store"} --optimise";
Nice = 19;
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
};
startAt = lib.optionals cfg.automatic cfg.dates;
};