But that doesn’t actually make the builds themselves use these nice values from what I’ve observed.
It appears to affect only the nix-daemon process itself.
Is there a way to also set nice for all build processes Nix daemon spawns?
if the nix daemon is spawning the build, in theory the sub process should inherit the parents nice value… unless its spawning the builder in such a way that it’s not honouring this.
it also may/may not - be effected by autogroup … I’ll look into this later when i get a min to try it out.
autogroup is enabled by default on nix/OS …so it maybe a contributing factor?
Sorry for resurrecting this old thread, but I think this information will be valuable for others coming here just like me.
I’m using NixOS on desktop and, while it was doing some automated system upgrade today, my desktop got a bit frozen. So, I got here. The solution was for NixOS 20.09, quite old now.
nix.daemonNiceLevel and nix.daemonIONiceLevel have been removed in favour of the new options nix.daemonCPUSchedPolicy, nix.daemonIOSchedClass and nix.daemonIOSchedPriority. Please refer to the options documentation and the sched(7) and ioprio_set(2) man pages for guidance on how to use them.
So, for more modern NixOS desktop usage, this module should make it snappier:
When rebuilding a lot, I usually run:
sudo watch --interval=5 ‘for i in $(seq 1 32); do renice 20 --pid `ps --no-heading -o tid --user nixbld$i`; done’
I believe the issue here is that if you’re doing the builds via something like sudo nixos-rebuild switch then the build is being run as root, directly as a child of that sudo, not via a request to the daemon.
This is why I have the systemd equivalents of those scheduling directives also in my autoupgrade service unit, because that runs as root and the same issue applies.
Perhaps you can compare the effect when running a nixos-rebuild build first as a regular unprivileged user, and then a second switch as root once the closure has already been finished.