Repair a botched upgrade

An upgrade (nixos-rebuild switch --upgrade) failed due to a dropped ssh connection. Yes, I realized after entering the command I wasn’t in tmux, but figured it would probably complete on its own, and didn’t want to cancel it. Well, it didn’t :frowning:

Now I get:

[brandon@brandon-nix:~]$ sudo nixos-rebuild  switch --upgrade
unpacking channels...
error: error parsing derivation '/nix/store/7lda5mv28rdvwypxnmhqax6ig1riwpxn-nix-2.3.4.drv': expected string 'Derive(['
building Nix...
error: error parsing derivation '/nix/store/7lda5mv28rdvwypxnmhqax6ig1riwpxn-nix-2.3.4.drv': expected string 'Derive(['

[brandon@brandon-nix:~]$ nix-store --delete /nix/store/7lda5mv28rdvwypxnmhqax6ig1riwpxn-nix-2.3.4.drv
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/rir6n3kzrkfvqz1vrswblk2371mrsmyc' to '/tmp/nixos-rebuild.d2Ubmc/nix.drv'
removing stale link from '/nix/var/nix/gcroots/auto/vy3xaf2zlgyrag9s92yvxw9z8ly3a5g7' to '/tmp/nixos-rebuild.zh5XGL/nix.drv'
removing stale link from '/nix/var/nix/gcroots/auto/31mww0hlx71b4qg48ndaqsqbq0fcmcyn' to '/tmp/nixos-rebuild.U7BbMi/nix.drv'
0 store paths deleted, 0.00 MiB freed
error: cannot delete path '/nix/store/7lda5mv28rdvwypxnmhqax6ig1riwpxn-nix-2.3.4.drv' since it is still alive

[brandon@brandon-nix:~]$ nix-store --delete --ignore-liveness /nix/store/7lda5mv28rdvwypxnmhqax6ig1riwpxn-nix-2.3.4.drv
0 store paths deleted, 0.00 MiB freed
error: you are not allowed to ignore liveness

I also tried sudo nix-store --verify --repair --check-contents, but this didn’t seem to improve the situation.

This was not the command that helped, but a similar command did work : nixos-rebuild switch --repair

See: NixOS 23.11 manual | Nix & NixOS

4 Likes

Future searchers: looks like this doesn’t exist anymore. On 23.05 (trying to upgrade to 23.11):

$ sudo nixos-rebuild switch --repair
error: unrecognised flag '--repair'