Profile conflict error in nix upgrade-nix when upgrading from 2.20 #411

Closed
opened 2024-06-23 18:27:41 +00:00 by jade · 14 comments
Owner

still not sure what exact circumstances lead to this and which upgrade-nix but it seems to happen to our upgrade-nix so :(

building '/nix/store/9gd7xvjhdfsxjp5w9rkv04zh384y4hpy-user-environment.drv'...
error: Unable to build profile. There is a conflict for the following files:

         /nix/store/4xwvps7bnachw9686ac22jhczn04i44b-nix-2.20.5/bin/nix-prefetch-url
         /nix/store/z1bdccwsk34iv491aygh0mm1lgpf7yy1-lix-2.90.0-rc1/bin/nix-prefetch-url
error: builder for '/nix/store/9gd7xvjhdfsxjp5w9rkv04zh384y4hpy-user-environment.drv' failed with exit code 1
error: program '/nix/store/z1bdccwsk34iv491aygh0mm1lgpf7yy1-lix-2.90.0-rc1/bin/nix-env' failed with exit code 100
still not sure what exact circumstances lead to this and which upgrade-nix but it seems to happen to our upgrade-nix so :( ``` building '/nix/store/9gd7xvjhdfsxjp5w9rkv04zh384y4hpy-user-environment.drv'... error: Unable to build profile. There is a conflict for the following files: /nix/store/4xwvps7bnachw9686ac22jhczn04i44b-nix-2.20.5/bin/nix-prefetch-url /nix/store/z1bdccwsk34iv491aygh0mm1lgpf7yy1-lix-2.90.0-rc1/bin/nix-prefetch-url error: builder for '/nix/store/9gd7xvjhdfsxjp5w9rkv04zh384y4hpy-user-environment.drv' failed with exit code 1 error: program '/nix/store/z1bdccwsk34iv491aygh0mm1lgpf7yy1-lix-2.90.0-rc1/bin/nix-env' failed with exit code 100 ```
jade added the
bug
label 2024-06-23 18:27:41 +00:00
Author
Owner

cc @qyriad

This happens also with nix-2.11 -> lix-2.90.0-rc1 on macOS.

cc @qyriad This happens also with nix-2.11 -> lix-2.90.0-rc1 on macOS.
Owner

This occurs because when using a nix-env style profile, nix upgrade-nix simply runs nix-env --install with the newly provided derivation into the provided profile.

This works fine if both derivations have the same name (such as a normal upgrade from nix-<old.version> to nix-<new.version>), as with the flags provided, the install will simply replace the old version with the new (like an upgrade however missing the version resolution logic, a curiously underdocumented behavior). But in this case they don't, as one of them is named 'lix'. They both have the same default priority in the profile and provide the same file names, so the symlink step of building the environment fails.

With a nix profile style environment, Lix's nix upgrade-nix logic was improved to support this type of upgrade and searches for a package that provides bin/nix-env as a heuristic to identify the Nix implementation to replace, it then itself handles creating a new profile generation with the change and switching to it. Lix retains the older "just use nix-env directly" logic for older profiles, so Lix would have this error upgrading to a CppNix as well with those profiles.

Unfortunately we can't actually fix this case, as the underlying behavior is in CppNix , we'd need to add the same heuristic method to the nix-env style profile handling to fix Lix, and then get those changes merged into CppNix, and considering that we don't plan on having upgrade-nix be the proper way to install Lix, this seems unrealistic.

This occurs because when using a `nix-env` style profile, `nix upgrade-nix` simply runs `nix-env --install` with the newly provided derivation into the provided profile. This works fine if both derivations have the same name (such as a normal upgrade from `nix-<old.version>` to `nix-<new.version>`), as with the flags provided, the install will simply replace the old version with the new (like an upgrade however missing the version resolution logic, a curiously underdocumented behavior). But in this case they don't, as one of them is named 'lix'. They both have the same default priority in the profile and provide the same file names, so the symlink step of building the environment fails. With a `nix profile` style environment, Lix's `nix upgrade-nix` logic was improved to support this type of upgrade and searches for a package that provides `bin/nix-env` as a heuristic to identify the Nix implementation to replace, it then itself handles creating a new profile generation with the change and switching to it. Lix retains the older "just use `nix-env` directly" logic for older profiles, so Lix would have this error upgrading to a CppNix as well with those profiles. Unfortunately we can't actually fix this case, as the underlying behavior is in *CppNix* , we'd need to add the same heuristic method to the `nix-env` style profile handling to fix Lix, and then get those changes merged into CppNix, and considering that we don't plan on having `upgrade-nix` be the proper way to install Lix, this seems unrealistic.
Author
Owner

But this is unusable, since AFAICT every installer uses the nix-env style. So we do have to actually care about this bug, unfortunately.

However, this might be best achieved by just nuking upgrade-nix and making it tell you to use the installer, assuming it can repair existing installations in-place.

But this is *unusable*, since AFAICT every installer uses the `nix-env` style. So we do have to actually care about this bug, unfortunately. However, this might be best achieved by just nuking upgrade-nix and making it tell you to use the installer, assuming it can repair existing installations in-place.
Owner

However, this might be best achieved by just nuking upgrade-nix and making it tell you to use the installer, assuming it can repair existing installations in-place.

Yes this is what I meant about us (Lix) not considering nix upgrade-nix to be a reasonable way of upgrading to Lix. From what I can tell there is literally no way for us to fix this without patching Nix itself, which would be even more confusing as some copies of Nix will work and others won't.

We can ofc patch Lix to handle this case but it won't matter for Lix->Lix updates anyway, since it will replace the older Lix with the newer Lix as both have the package name lix, the issue is only caused because CppNix's package name is nix and so when you install Lix you get lix as the package name and both are installed rather than simply replacing the old nix package with a new nix package. If you already have a lix installed, the new lix package will safely replace it, even with nix-env style profiles, so we don't have to worry about that.

Afaik we consider the Lix installer to be the way to do this, it will need to be modified to remove any existing installs of Nix first if it's currently trying to do upgrades through nix upgrade-nix or similar. This will literally only affect Nix->Lix upgrades, Lix->Lix upgrades will work fine with nix-env style profiles as is.

I consider the correct way to upgrade a system to Lix to be either using NixOS and our various recommended approaches there, or installing fresh using the Lix installer. I haven't touched the installer code so I don't know how happy it will handle an existing store, if it doesn't handle that well we should update the Lix installer to better handle that case.

> However, this might be best achieved by just nuking upgrade-nix and making it tell you to use the installer, assuming it can repair existing installations in-place. Yes this is what I meant about us (Lix) not considering `nix upgrade-nix` to be a reasonable way of upgrading to Lix. From what I can tell there is literally no way for us to fix this without patching Nix itself, which would be even more confusing as *some* copies of Nix will work and others won't. We can ofc patch Lix to handle this case but it won't matter for Lix->Lix updates anyway, since it will replace the older Lix with the newer Lix as both have the package name `lix`, the issue is only caused because CppNix's package name is `nix` and so when you install Lix you get `lix` as the package name and both are installed rather than simply replacing the old `nix` package with a new `nix` package. If you already have a `lix` installed, the new `lix` package will safely replace it, even with `nix-env` style profiles, so we don't have to worry about that. Afaik we consider the Lix installer to be the way to do this, it will need to be modified to remove any existing installs of Nix first if it's currently trying to do upgrades through `nix upgrade-nix` or similar. This will literally only affect Nix->Lix upgrades, Lix->Lix upgrades will work fine with `nix-env` style profiles as is. I consider the correct way to upgrade a system to Lix to be either using NixOS and our various recommended approaches there, or installing fresh using the Lix installer. I haven't touched the installer code so I don't know how happy it will handle an existing store, if it doesn't handle that well we should update the Lix installer to better handle that case.
Author
Owner

If we think this is indeed the case, we should fix the website documentation to not suggest nix upgrade-nix anymore. But upgrade-nix would be sound if we just used the nix profile hack also for nix-env.

If we think this is indeed the case, we should fix the website documentation to not suggest `nix upgrade-nix` anymore. But `upgrade-nix` *would* be sound if we just used the `nix profile` hack also for `nix-env`.

@lunaphied I also ran into this — am I correct in assuming that the workaround for this is to uninstall Nix and then reinstall using the Lix install script?

@lunaphied I also ran into this — am I correct in assuming that the workaround for this is to uninstall Nix and then reinstall using the Lix install script?
Owner

@lunaphied I also ran into this — am I correct in assuming that the workaround for this is to uninstall Nix and then reinstall using the Lix install script?

@ethnt Correct

If we think this is indeed the case, we should fix the website documentation to not suggest nix upgrade-nix anymore. But upgrade-nix would be sound if we just used the nix profile hack also for nix-env.

That would only fix Lix->Nix, Nix->Lix can never work unless we get that code merged to CppNix itself, and then there'll be versions of CppNix that have the code and work, and versions that don't.

> @lunaphied I also ran into this — am I correct in assuming that the workaround for this is to uninstall Nix and then reinstall using the Lix install script? @ethnt Correct > If we think this is indeed the case, we should fix the website documentation to not suggest `nix upgrade-nix` anymore. But `upgrade-nix` *would* be sound if we just used the `nix profile` hack also for `nix-env`. That would only fix Lix->Nix, Nix->Lix can never work unless we get that code merged to CppNix itself, and then there'll be versions of CppNix that have the code and work, and versions that don't.

Hi, just found this issue and wanted to check if this is also expected for Lix -> Lix upgrades (it sounds unexpected, from reading the previous discussion). I tried to upgrade from 2.90.0-beta.1 and saw a similar message:

$ nix upgrade-nix
installing 'lix-2.90.0'
warning: Ignoring the client-specified setting 'sandbox', because it is a restricted setting and you are not a trusted user
building '/nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv'...
error: Unable to build profile. There is a conflict for the following files:

         /nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix
         /nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0/bin/nix
error: builder for '/nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv' failed with exit code 1;
       last 4 log lines:
       > error: Unable to build profile. There is a conflict for the following files:
       >
       >          /nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix
       >          /nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0/bin/nix
       For full logs, run 'nix log /nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv'.
error: program '/nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix-env' failed with exit code 1

Maybe this is just an artifact of how beta.1 was installed (lix-installer 0.17.1), and I'm assuming from reading e.g. #267 that this isn't really a planned workflow long-term anyway? I mainly just wanted to confirm this is part of the same problem (and same workaround) and not something that deserves a separate issue.

Hi, just found this issue and wanted to check if this is also expected for Lix -> Lix upgrades (it sounds unexpected, from reading the previous discussion). I tried to upgrade from `2.90.0-beta.1` and saw a similar message: ``` $ nix upgrade-nix installing 'lix-2.90.0' warning: Ignoring the client-specified setting 'sandbox', because it is a restricted setting and you are not a trusted user building '/nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv'... error: Unable to build profile. There is a conflict for the following files: /nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix /nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0/bin/nix error: builder for '/nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv' failed with exit code 1; last 4 log lines: > error: Unable to build profile. There is a conflict for the following files: > > /nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix > /nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0/bin/nix For full logs, run 'nix log /nix/store/j2b3lapkbqr99544b7q3508r7y1j6nqq-user-environment.drv'. error: program '/nix/store/dajhmsik4z5s2nn9gbiv8bxv1j641bl4-nix-2.90.0-beta.1/bin/nix-env' failed with exit code 1 ``` Maybe this is just an artifact of how `beta.1` was installed (`lix-installer 0.17.1`), and I'm assuming from reading e.g. #267 that this isn't really a planned workflow long-term anyway? I mainly just wanted to confirm this is part of the same problem (and same workaround) and not something that deserves a separate issue.
Author
Owner

Yep, same problem, beta 1 had a derivation name of "nix" so you see the same symptom.

Yep, same problem, beta 1 had a derivation name of "nix" so you see the same symptom.

I've found a workaround for the Unable to build profile error, though I'm not sure, if it broke something along the way:

oldnixbin="$(readlink -f "$(which nix)")"

sudo nix profile remove nix
sudo "${oldnixbin}" profile install "git+https://git.lix.systems/lix-project/lix?ref=refs/tags/2.90.0#nix"
I've found a workaround for the `Unable to build profile` error, though I'm not sure, if it broke something along the way: ``` oldnixbin="$(readlink -f "$(which nix)")" sudo nix profile remove nix sudo "${oldnixbin}" profile install "git+https://git.lix.systems/lix-project/lix?ref=refs/tags/2.90.0#nix" ```
Owner

Yes that is absolutely the correct workaround

Yes that is absolutely the correct workaround
Owner

If you're getting a profile conflict with Lix's upgrade-nix, that means that it's using the wrong nix-env (either from CppNix or from a version of Lix that didn't have this fix). Lix's upgrade-nix is supposed to use the nix-env from the Lix that's currently being invoked, so the nix run $lix -- upgrade-nix pattern works. If it's not, that means our "find nix-env" logic wasn't implemented correctly.

If you're getting a profile conflict with Lix's `upgrade-nix`, that means that it's using the *wrong* `nix-env` (either from CppNix or from a version of Lix that didn't have this fix). Lix's `upgrade-nix` is *supposed* to use the `nix-env` from the Lix that's currently being invoked, so the `nix run $lix -- upgrade-nix` pattern works. If it's not, that means our "find nix-env" logic wasn't implemented correctly.
qyriad reopened this issue 2024-07-12 18:55:58 +00:00
Owner

This being said, we agree that upgrade-nix really should just be killed, and we should just use the installer for upgrades.

This being said, we agree that `upgrade-nix` really should just be killed, and we should just use the installer for upgrades.
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/1604 ("nix3-upgrade-nix: always use the /new/ nix-env to perform the installation")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/1604", "number": 1604, "kind": "commit message"}], "cl_meta": {"1604": {"change_title": "nix3-upgrade-nix: always use the /new/ nix-env to perform the installation"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/1604](https://gerrit.lix.systems/c/lix/+/1604) ("nix3-upgrade-nix: always use the /new/ nix-env to perform the installation")
Sign in to join this conversation.
No milestone
No project
No assignees
7 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#411
No description provided.