From 9ff95589907fd1c909db4597abb0e5caf2cb8bbd Mon Sep 17 00:00:00 2001 From: "Peter H. Hoeg" Date: Sat, 28 Jun 2025 10:43:58 +0200 Subject: [PATCH] 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` --- nixos/modules/services/misc/nix-optimise.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/misc/nix-optimise.nix b/nixos/modules/services/misc/nix-optimise.nix index 3581b95ce18a..93d36839f3fd 100644 --- a/nixos/modules/services/misc/nix-optimise.nix +++ b/nixos/modules/services/misc/nix-optimise.nix @@ -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; };