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

Wrap up nix-env in a way that handles conflicting, pre-installed packages #1467

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Feb 25, 2025

Description

If an installed package contains programs or paths named like nix, nix-env -i will fail due to the conflict.

Instead of a naive nix-env -i, this PR:

  • examines the default profile if it already exists
  • duplicates the profile into a scratch profile, to ensure we can operate atomically on the default profile
  • queries the installed packages
  • checks to see if the list of packages that will be installed will conflict with already-installed paths
  • if any do conflict, those conflicting packages are removed
  • installs the new packages
  • and finally, updates the default profile to point to the new profile.

Note that another approach could be to set the conflicting packages to a lower priority (higher numerical value.) However, that still requires most of the code here, and has the down side that it is dealing with more complexity of nix-env. The approach here -- while ... verbose ... should work in all cases.

Checklist
  • Formatted with cargo fmt
  • Built with nix build
  • Ran flake checks with nix flake check
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • Linked to related issues (leave unchecked if not applicable)
Validating with install.determinate.systems

If a maintainer has added the upload to s3 label to this PR, it will become available for installation via install.determinate.systems:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/pr/$PR_NUMBER | sh -s -- install

src/nixenv.rs Outdated
{
let output = tokio::process::Command::new(self.nix_store_path.join("bin/nix-env"))
.process_group(0)
.arg("--profile")
Copy link
Member

Choose a reason for hiding this comment

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

This may be problematic for any time we operate on profiles that may have been touched by the nix profile command:

$ nix-env --query --installed --out-path --json
error: profile '/home/vin/.local/state/nix/profiles/profile' is incompatible with 'nix-env'; please use 'nix profile' instead

(but we already have this problem, so maybe-fine to not deal with it now)

@grahamc grahamc enabled auto-merge (squash) February 25, 2025 21:05
Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

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

After that error change, seems fine to me

@cole-h cole-h added this to the 0.37.3 milestone Feb 25, 2025
@grahamc grahamc merged commit e370fa4 into main Feb 25, 2025
22 checks passed
@grahamc grahamc deleted the graham/fh-646-nix-installer-handle-the-case-where-a-nix-shaped-thing branch February 25, 2025 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants