Rebuild deleted my /etc/nixos

I enabled nixos-init which then errored as I needed to enable three other things for that to work (like systemd initrd). After enabling them and rebuilding, I came back to Neovim which had notified me that my config file no longer existed. I looked for it and found my /etc/nixos gone. After this, I tried rebuilding again and it failed because there’s no config. A few minutes later, my root password no longer worked. I also had some internet issues (dns, email) but I’m not sure of those were related or not. I decided to shut off my computer and turn it back on. I got to the login screen but it rejected my password. Not sure what to do from here so I came to the forums. I did manage to get my config onto a usb drive so my system isn’t completely lost.

In retrospect, I should’ve gone straight to root while it still worked and recreated the nixos directory but it’s a bit late for that.

I’m on 25.11 currently.

1 Like

Good for you for having a backup.

Assuming you’ve got (or can borrow) another spare USB stick and another computer, use the spare computer to make a nixos installer out of the spare USB stick, reinstall nixos, and then copy your configuration.nix from its backup. Then nixos-rebuild boot and reboot. You should be fine.

It’s possible that the /etc/nixos wasn’t deleted but rather masked by the etc-overlay that I assume you enabled. In any case, you can always nixos-install your config using a live image, which won’t affect your data.

2 Likes

Turns out a missing /etc/nixos doesn’t stop you from just going back a generation.

1 Like