nixos-rebuild: switch to tmpDir during rebuilds#150065
nixos-rebuild: switch to tmpDir during rebuilds#150065thiagokokada merged 1 commit intoNixOS:masterfrom thiagokokada:workaround-issue-144811
Conversation
This is a workaround for issue #144811 until this issue is either fixed on nix itself.
|
This issue affects both |
|
would pushd and popd be better here? |
The issue of |
figsoda
left a comment
There was a problem hiding this comment.
sorry I forgot to come back to this, fixes the issue for me
|
I really would like one more review here to make sure I am not breaking anything. |
|
Successfully created backport PR #150856 for |
|
Successfully created backport PR #150857 for |
|
This seems to break |
Let's revert it them. |
The removed lines converted the flake path passed by the command line from `/some/path` to `git+file:///some/path`. This technically shouldn't cause any issues, however running `nixos-rebuild switch` inside a directory `/nix/store` will cause the switch to fail and leave a partially construct generation (see issue #144811 for details). By itself this shouldn't be too much of an issue, however thanks to another issue in `systemd-boot-builder.py` this can leave the system in a broken state for those using `boot.loader.systemd-boot` (AFAIK the default), where future `nixos-rebuild switch` will fail (see issue #93694 for details). The issue can be fixed by running `nix-env -p /nix/var/nix/profiles/system --delete-generations old`, however this makes newbies very confused and it is showing in our support threads in Matrix and Discourse (see https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842). Keep in mind this is a workaround. The actual issue seems to be in nix itself (see: NixOS/nix#5510). See also #150065 for an alternative fix that caused other issues. Kudos for @figsoda for figuring out this fix. (cherry picked from commit c274d04)
Motivation for this change
Workaround issue: #144811
The idea of this fix is very simple: since running
nixos-rebuildinside a symbolic link directory pointing to/nix/storebroke thenixos-rebuild, what we are going to do instead is simply switch to another directory. We already create a temporary directorytmpDirfor some things, so we can switch to that directory without much loss.Keep in mind that this is a workaround. The actual issue seems to be how
nixhandles references withpath:: NixOS/nix#5510I did a
nixos-rebuild switchinside/run/opengl-driver/liband this workaround works fine. Also tested `nixos-rebuild {dry-build,dry-activate,build-vm,build-vm-with-bootloader,test,edit} commands and they seem to work fine, however I can't test remote builds and other functionality.Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes