Skip to content

nixos-rebuild: do not resolve flake path#153515

Merged
thiagokokada merged 2 commits intoNixOS:masterfrom
thiagokokada:workaround-issue-144811
Jan 8, 2022
Merged

nixos-rebuild: do not resolve flake path#153515
thiagokokada merged 2 commits intoNixOS:masterfrom
thiagokokada:workaround-issue-144811

Conversation

@thiagokokada
Copy link
Copy Markdown
Contributor

@thiagokokada thiagokokada commented Jan 4, 2022

Motivation for this change

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.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jan 4, 2022
@thiagokokada
Copy link
Copy Markdown
Contributor Author

thiagokokada commented Jan 4, 2022

Tested nixos-rebuild switch inside and outside /run/opengl-driver/lib, works fine.

@thiagokokada
Copy link
Copy Markdown
Contributor Author

BTW, this should be backported to release-21.05 and release-21.11 since it also affects them. However to avoid the issue from #150065, in case this is merged I will wait sometime before backporting this to the respective branches.

@thiagokokada
Copy link
Copy Markdown
Contributor Author

CC @edolstra and @cole-h since they're the folks that introduced the lines that are being deleted on this PR.

CC @colemickens @figsoda to help testing.

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.
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jan 4, 2022
Was only used in the code removed in commit
c274d04.
@thiagokokada
Copy link
Copy Markdown
Contributor Author

Also CC @TredwellGit to test if this cause issues with ZFS.

Copy link
Copy Markdown
Member

@figsoda figsoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes the issue for me
would like it see another review since the other workaround caused issue on zfs

@thiagokokada
Copy link
Copy Markdown
Contributor Author

fixes the issue for me would like it see another review since the other workaround caused issue on zfs

CC @TredwellGit.

@cole-h cole-h removed their request for review January 7, 2022 18:47
Copy link
Copy Markdown
Member

@TredwellGit TredwellGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with the ZFS modules.

@thiagokokada
Copy link
Copy Markdown
Contributor Author

Going to merge them and leave during some time on master branch to see if someone else detects some issues.

@thiagokokada thiagokokada merged commit 06235ce into NixOS:master Jan 8, 2022
@thiagokokada thiagokokada deleted the workaround-issue-144811 branch January 8, 2022 02:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 8, 2022

Successfully created backport PR #153935 for release-21.11.

@Enzime
Copy link
Copy Markdown
Member

Enzime commented Jan 8, 2022

Awesome work, I ran into this a couple of times but I was too lazy to debug it, glad to see it was fixed 🎉

thiagokokada added a commit to thiagokokada/nixpkgs that referenced this pull request Jun 16, 2025
PR NixOS#375493 was introduced to fix an issue of different behavior between
`nixos-rebuild repl` and `nixos-rebuild switch` by forcing usage of
`git+file://` protocol when evaluating the Flake. This sadly
reintroduced an older issue from the original `nixos-rebuild` that is
caused by a pretty nasty bug in `nix`:
- NixOS#144811

Let's do the same fix we did for `nixos-rebuild` and just stopping
normalizing the Flake (NixOS#153515).
This will bring back the original issues this code is supposed to fix,
but I argue that a difference between `nixos-rebuild repl` and
`nixos-rebuild switch` is better than having a broken system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants