Skip to content

upgrade-nix: fix profile symlink resolution#15438

Open
amaanq wants to merge 1 commit intoNixOS:masterfrom
obsidiansystems:fix-upgrade-nix
Open

upgrade-nix: fix profile symlink resolution#15438
amaanq wants to merge 1 commit intoNixOS:masterfrom
obsidiansystems:fix-upgrade-nix

Conversation

@amaanq
Copy link
Member

@amaanq amaanq commented Mar 9, 2026

Motivation

canonPath(profileDir, true) (which resolves symlinks) was converted
to canonPath(profileDir) (which doesn't) in a5a2562, so the profile
path was never resolved to its store target. This is fixed by using
store->followLinksToStorePath instead.

The while loop that attempted to chase symlinks into /profiles/ is
removed. It called readLink, which returns relative targets for
nix-env generation links (e.g. .local-1-link), crashing canonPath
with "not an absolute path". The loop is also unnecessary now that
followLinksToStorePath is used, since it resolves the full symlink
chain to the store path regardless of whether the profile is under
/profiles/.

A NixOS VM test was added, which is based on nixpkgs' nixosTests.nix-upgrade,
with three variants; one for stable, latest, and current.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@amaanq amaanq requested a review from edolstra as a code owner March 9, 2026 23:55
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Mar 9, 2026
@xokdvium xokdvium added the backport 2.34-maintenance Automatically creates a PR against the branch label Mar 10, 2026
@xokdvium
Copy link
Contributor

Would be nice to have some nixos upgrade tests in hydra...

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Mar 10, 2026
@xokdvium
Copy link
Contributor

Let's instead use a much better end-to-end test from nixpkgs: nixosTests.nix-upgrade (if that's possible). We can just import the file nixos/tests/nix/upgrade.nix. Frankly this test is absolutely useless (forgive me if I'm being harsh, but frankly this LLM nonsense is becoming annoying).

@amaanq amaanq force-pushed the fix-upgrade-nix branch 4 times, most recently from 71b53ae to f04fe2f Compare March 11, 2026 19:43
@amaanq amaanq force-pushed the fix-upgrade-nix branch 6 times, most recently from 2eba5c9 to 7213bdc Compare March 11, 2026 22:11
`canonPath(profileDir, true)` (which resolves symlinks) was converted
to `canonPath(profileDir)` (which doesn't) in a5a2562, so the profile
path was never resolved to its store target. This is fixed by using
`store->followLinksToStorePath` instead.

The while loop that attempted to chase symlinks into `/profiles/` is
removed. It called `readLink`, which returns relative targets for
`nix-env` generation links (e.g. `.local-1-link`), crashing `canonPath`
with "not an absolute path". The loop is also unnecessary now that
`followLinksToStorePath` is used, since it resolves the full symlink
chain to the store path regardless of whether the profile is under
`/profiles/`.

A NixOS VM test was added, which is based on nixpkgs' `nixosTests.nix-upgrade`,
with three variants; one for stable, latest, and current.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.34-maintenance Automatically creates a PR against the branch new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

upgrade-nix produces error: path "/nix/var/nix/profiles/default" is not in the Nix store

3 participants