I will be brief, after playing around with custom CPU flags I am unable to rebuild my system.
The process fails outputing a known error: “too many open files”.
My problem is that even after raising the number up to a ludicrous amount the error does not disappear.
As a note:
I had to define it with lib.mkForce because the value was already defined somewhere else. (Not by me.)
My default value was already higher than the one suggested in the issue.
Possibly you accidentally altered an OS limit somehow. If you cannot rollback to before your “playing around”, you may have to investigate all the bits which can restrict the number of open files. Ideally you can find something to tell you what is limiting the build – maybe in build logs or in the system journal.
Poking around on my system, I found these interesting bits
cat /proc/sys/fs/nr_open returns 1073741816
ulimit -Hn returns 524288
sudo grep -R NOFILE /etc returns many files including
At the risk of bumping an old thread, I encountered this issue while running a machine with quite a number of nixos containers.
I was able to fix it by increasing the systemd open files limit with:
systemd.extraConfig = "DefaultLimitNOFILE=2048"; # defaults to 1024 if unset
Also sorry to necrobump, but this is one of the most prominent search results for the problem.
If you’re encountering this issue whilst doing nixos-rebuild switch, you might have tried to up the limit on nix-daemon.service (which is ludicrous by default anyway) and realised that it doesn’t work.
Turns out: it seems like nixos-rebuild switch does not use the Nix daemon to do the build (I tried disabling the daemon and noticing that builds don’t fail).
Apply a new limit in your shell that is doing the rebuild instead: ulimit -n 4096 for example. Then run the rebuild.
I am no expert but I think the Nix daemon is just there for multi-user support and probably only is there to make building possible by unprivileged users without letting them inject fake files into the store and making sure the builds are pure.
When you are the root user, I guess this does not apply.
This worked for me.