Do you know specifically which package is un-cached? You can use a very useful tool called nix-output-monitor to better visualize the build tree.
# with bash
$ nixos-rebuild build |& nom
# with fish
$ nixos-rebuild build &| nom
PS: I personally use nh, which is a replacement for nixos-rebuild and uses nom by default.
You can check out Tuning Cores and Jobs - Nix Reference Manual which can help with CPU-intensive builds.
With a Ryzen 7 6800H + 16GB RAM, I use:
# Limit build resources
nix.settings = {
max-jobs = 4;
cores = 12;
};
# NOTE: run `sudo systemctl restart nix-daemon.service` the first time you apply this.
systemd.services.nix-daemon.serviceConfig = {
# kill Nix builds instead of important services when OOM
OOMScoreAdjust = 1000;
};
Although my PC still freezes sometimes, it’s been manageable as the build is always killed after a while.