Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nix upgrade-nix profile search #12048

Merged
merged 2 commits into from
Dec 15, 2024
Merged

Conversation

gcurtis
Copy link
Contributor

@gcurtis gcurtis commented Dec 13, 2024

Motivation

I could no longer get nix upgrade-nix to work on macOS or Linux after upgrading to 2.25:

$ sudo -i nix upgrade-nix --debug
found Nix in '"/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin/nix"'
found profile '/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin'
error: directory '"/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin/nix"' does not appear to be part of a Nix profile

Fix the profile search logic so that it works again without needing to explicitly give --profile /nix/var/nix/profiles/default.

Context

Commit cfe66db (in #11218) updated nix upgrade-nix to use ExecutablePath::load().find, which broke the logic for finding the profile associated with the nix executable. This seems to happen for two reasons:

  1. The original PATH search resulted in a directory, but find returns the path to the executable. Fixed by getting the path's parent.
  2. The profile symlink cannot be found because ExecutablePath::load().find canonicalizes the executable path. I updated find to normalize the path instead, which seems more in line with how other programs resolve paths. I'm not sure if this affects other callers though.

I manually tested this on macOS and Linux, and it seemed to fix upgrading from 2.25.2 to 2.25.3.


Add 👍 to pull requests you find important.

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

@gcurtis gcurtis requested a review from edolstra as a code owner December 13, 2024 20:59
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Dec 13, 2024
@Mic92 Mic92 added the bug label Dec 14, 2024
@Mic92
Copy link
Member

Mic92 commented Dec 14, 2024

@mergify rebase

Commit cfe66db updated `nix upgrade-nix` to use
`ExecutablePath::load().find`, which broke the logic for finding the
profile associated with the nix executable. The error looks something
like:

```
$ sudo -i nix upgrade-nix --debug
found Nix in '"/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin/nix"'
found profile '/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin'
error: directory '"/nix/store/46p1z0w9ad605kky62dr53z4h24k2a5r-nix-2.25.2/bin/nix"' does not appear to be part of a Nix profile
```

This seems to happen for two reasons:

1. The original PATH search resulted in a directory, but `find` returns
   the path to the executable. Fixed by getting the path's parent.
2. The profile symlink cannot be found because
   `ExecutablePath::load().find` canonicalizes the executable path. I
   updated find to normalize the path instead, which seems more in line
   with how other programs resolve paths. I'm not sure if this affects
   other callers though.

I manually tested this on macOS and Linux, and it seemed to fix
upgrading from 2.25.2 to 2.25.3.
Copy link
Contributor

mergify bot commented Dec 14, 2024

rebase

✅ Branch has been successfully rebased

the format error already adds quotes.
@Mic92 Mic92 added the backport 2.25-maintenance Automatically creates a PR against the branch label Dec 15, 2024
@Mic92
Copy link
Member

Mic92 commented Dec 15, 2024

@mergify queue

Copy link
Contributor

mergify bot commented Dec 15, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 3663480

mergify bot added a commit that referenced this pull request Dec 15, 2024
@mergify mergify bot merged commit 3663480 into NixOS:master Dec 15, 2024
13 checks passed
mergify bot added a commit that referenced this pull request Dec 15, 2024
…2048

Fix `nix upgrade-nix` profile search (backport #12048)
@gcurtis gcurtis deleted the fix-upgrade-nix branch December 16, 2024 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.25-maintenance Automatically creates a PR against the branch bug new-cli Relating to the "nix" command
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants