Commit 9ff95589 authored by Peter H. Hoeg's avatar Peter H. Hoeg
Browse files

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`
parent 30a61f05
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -65,9 +65,17 @@ in
    systemd = lib.mkIf config.nix.enable {
      services.nix-optimise = {
        description = "Nix Store Optimiser";
        unitConfig = {
          ConditionACPower = true;
          # 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";
          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;
      };