Limit CPU usage when building

Is there a way to limit cpu usage / load when using nixos-rebuld switch? I’m not using the binary cache, and I keep getting OOM’ed ( the load average reaches over 70 on my 8 core cpu )

Your title is about CPU, but getting OOM’ed suggests it might (also) be about memory usage? This older thread could be helpful here Nix build ate my RAM 😭 :slight_smile:

Yes, its running outbof memory because it tries to do too much. I would like to limit the load to 8

nix = {
  settings = {
    cores = 8;
  };
};

For now cores and max-jobs are the options you can tune.

There’s a stalled attempt to allow configuring a load limit separately.

3 Likes

So I found you can do nixos-rebuild switch --options cores 1. I haven’t tried the rest of solutions but I’m sure they also work. Thanks :confounded:

flake version:
nixos-rebuild switch --flake .#nixos --option cores 3 --option max-jobs 6 --option max-memory-size 8G

1 Like

If you have fast ssd storage to spare, I suggest trying out the swapspace module.

this doesn’t work: max-memory-size 8G