Crashing while rebuilding Config or installing packages

Hi,
I have a verry strange problem with my NixOS. Everytime i want to install a package via nix-env -i or rebuild a changend config via nixos-rebuild the system logs me out. Even if i am using tty and sudo.
The only way i can do it ist to log in as root on tty1. then everything works.

Ps: how can i upload my config so i can get better help?

Hello and welcome to NixOS!

Disclaimer: I’m probably not knowledgeable enough to help you because I’m relatively new to NixOS as well. Instead, I write this reply because I don’t fully understand your issue and want to help clarify it, so that others can better offer you assistance. A bit more context would probably be useful here, like e.g.:

  1. Which commands exactly do you try to run when the issue occurs?

  2. Do you get any error messages?

  3. What exactly happens when you run the command in question? Do you get logged out of your Desktop Environment (which one?) or does the system crash (as your title suggests?) - and if so, how specifically?

  4. Did it work before? What changes did you apply when the problem occurred for the first time?

1 Like

Got here with the same issue. Haven’t started bisecting, but it’s happening on >1 machine now.
I’ve never seen this in 2+ years of nix, and recently:

  • refactored some configurations into modules
  • updated nixpkgs to HEAD (I do this quite often)

So it’s either or, but I’m guessing it’s the former. Not sure if the order of modules getting loaded matters, will follow up here when I resolve it.

EDIT: an interesting point is that if I rebuild the same config from another machine, it builds OK. The current workaround is to build, nix-copy-closure from machine A to B, then on machine B sudo /nix/store/sha-to-your-new-system/bin/switch-to-configuration switch.

FWIW, can’t even do nix develop, whole DE crashes and logs me out back to tty.

Have any of you tried a nixos-rebuild boot instead of switch? There might be a service that’s being restarted that restarts all the user sessions (maybe gdm or systemd-logind?).

Yep just tried, crashes. I think the fact that it crashes with nix develop on a flake based system is pointing to a bug somewhere in nix itself, nix daemon? let me check something…

don't think it's this

Hm, might have a smoking gun:

$journalctl -eu nix-daemon.service
...
...
Feb 20 16:55:52 mufasa nix-daemon[15010]: terminate called after throwing an instance of 'nix::FileTransferError'
Feb 20 16:55:52 mufasa nix-daemon[15010]:   what():  error: download of 'https://cache.nixos.org/nar/0gfi9zra09lmm1gk9qvmsh0vwwq96s19lc38shb9y823sipm075z.nar.xz' was interrupted
Feb 20 16:55:52 mufasa nix-daemon[14805]: terminate called after throwing an instance of 'nix::EndOfFile'
Feb 20 16:55:52 mufasa nix-daemon[14805]:   what():  error: unexpected end-of-file
Feb 20 16:56:28 mufasa nix-daemon[1374]: accepted connection from pid 19394, user marin (trusted)
Feb 20 16:54:12 mufasa nix-daemon[14558]: unexpected Nix daemon error: error: writing to file: Broken pipe
Feb 20 16:54:35 mufasa nix-daemon[1374]: accepted connection from pid 14798, user marin (trusted)
Feb 20 16:55:50 mufasa nix-daemon[1374]: accepted connection from pid 15004, user marin (trusted)
Feb 20 16:55:52 mufasa nix-daemon[15010]: terminate called after throwing an instance of 'nix::FileTransferError'
Feb 20 16:55:52 mufasa nix-daemon[15010]:   what():  error: download of 'https://cache.nixos.org/nar/0gfi9zra09lmm1gk9qvmsh0vwwq96s19lc38shb9y823sipm075z.nar.xz' was interrupted
Feb 20 16:55:52 mufasa nix-daemon[14805]: terminate called after throwing an instance of 'nix::EndOfFile'
Feb 20 16:55:52 mufasa nix-daemon[14805]:   what():  error: unexpected end-of-file
Feb 20 16:56:28 mufasa nix-daemon[1374]: accepted connection from pid 19394, user marin (trusted)
Feb 20 16:56:29 mufasa nix-daemon[19400]: unexpected Nix daemon error: error: writing to file: Broken pipe
~

EDIT: not sure the above has to do much with it, tried rebuilding and reproducing the crash without fresh logs being appended to nix-daemon’s journal.

Here’s the output of strace, not sure if it contains anything much useful either:

@edolstra what would you recommend to do here? I believe I’ll need to compile nix from scratch and attach a debugger. Any suggestions how to attach before this crash (happens very fast on 14700k), or any other approaches I should take?

OK got set up this morning, as nix develop crashes the system, was able to enter dev shell with the old nix-shell and compile nix from scratch. So far I’m unable to pinpoint where exactly the crash happens, but the last of the stack I have is input resolution and parsing hashes.
It crashes sometimes after nix::hash::parseAnyPrefixed, but it’s hard to catch it since the whole system crashes.
More context: I don’t have a display-manager session, launching sway directly from tty via exec sway so not sure if it’s related to systemd services being unloaded/reloaded. Happens even if I do it directly from tty - logs me out. Nothing interesting in journalctl or dmesg.

Hey,
With the help of a Linux install party I figured out the problem: Trying to get Homemanager running I added my User to the nixbuild group/ as a nixbuild user, so the system always killed the User-Sessions when installing or rebuilding.
So I just had to remove my User from the nixbuild group/users in my config and everything works fine now
Also thanks for al your help

1 Like

Ugh, that was it. super hard to debug. thank you @Alaskar!
How did you figure it out?

@grahamc @edolstra @domenkozar Is there anything that could be done at the nix or nixos-rebuild level to assert this doesn’t happen? It puts the system into almost unusable state.

Like I said a whole evening together with two other guys and nothing helped just as we wanted to one of them pointed it out, tested and worked. We really tried anything and just packed our stuff together.
Glad we could help.
At least I am not the only one dumb enough to put my use into the build users

Thanks for posting the solution you found, I was facing a similar issue using only home-manager on Arch and the issue was that i had added my user to the nixbld group.