Rebuild is failing due to permision denial

Every time I run nixos-rebuild switch, the rebuild ends with this error message:

error: creating symlink /nix/var/nix/profiles/system-24-link.tmp-26516-1804289383' -> '/nix/store/qf6rypbbfzriigzkhzl2izb73jxcslcq-nixos-system-lana-25.11.3860.1327e798cb05': Permission denied
Command 'nix-env -p /nix/var/nix/profiles/system --set /nix/store/qf6rypbbfzriigzkhzl2izb73jxcslcq-nixos-system-lana-25.11.3860.1327e798cb05' returned non-zero exit status 1.

This seems like to me it could be an accidental lock, but I don’t know enough about the OS as of current to really understand what’s happening. Does anyone have any idea of what’s going on here, and what I can do to fix it?

Not running with sudo? While the build itself doesn’t need sudo, executing the stuff invoked by switch-to-configuration requires elevated permissions.

2 Likes

Turns out that’s precisely it, thank you very much!

I’ve always ran switching without using sudo because it seemed to work fine without it. I’ll keep that in mind in case I get similar permission issues in the future.

afaik that’s basically impossible unless your user/group owns /nix or something (which would be quite broken). You always need root access somehow for boot/switch to work.