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 the segfault on nix profile install with conflict #8346

Merged

Conversation

thufschmitt
Copy link
Member

Motivation

nix profile install is currently segfaulting if

  1. There's a conflict between the installables, and
  2. One of these installables doesn't have a known flakeref

Besides, the error message shows the original flakeref but without the fragment part, meaning that it is wrong if the installable comes from a flake but isn't the default package of said flake.

Fix that by:

  • If the element comes from a flake, print the full flakeref (with the fragment part) and not just the reference to the flake itself
  • If the element doesn't come from a flake, print its store path(s)

This is a bit too verbose, but has the advantages of being correct (and not crashing), so it's strictly better than the previous situation

Context

Fix #8284

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 👍 to pull requests you find important.

This method isn't used to describe what the element is, but to return a
unique identifier for it whithin the current profile
- If the element comes from a flake, print the full flakeref (with the
  fragment part) and not just the reference to the flake itself
- If the element doesn't come from a flake, print its store path(s)

This is a bit too verbose, but has the advantages of being correct (and
not crashing), so it's strictly better than the previous situation

Fix NixOS#8284
@github-actions github-actions bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority labels May 16, 2023
@dermetfan
Copy link
Member

dermetfan commented May 16, 2023

I can confirm that this fixes the issue:

(setup)
❯ cat flake.nix
{
  inputs.nixpkgs.url = github:nixos/nixpkgs/nixos-22.11;

  outputs = { nixpkgs, ... }: {
    packages.x86_64-linux = let
      foo = name: nixpkgs.legacyPackages.x86_64-linux.runCommand "foo-${name}" {} ''
        mkdir $out
        echo ${nixpkgs.lib.escapeShellArg name} > $out/foo
      '';
    in {
      a = foo "a";
      b = foo "b";
    };
  };
}
❯ nix build .#a -o a
❯ nix build .#b -o b
❯ nix run github:nixos/nix/2.15-maintenance -- profile install --profile ./profile ./{a,b}
fish: Job 1, 'command nix $argv' terminated by signal SIGSEGV (Address boundary error)

❯ nix run github:tweag/nix/fix-nix-profile-install-conflict-segfault -- profile install --profile ./profile ./{a,b}
error: An existing package already provides the following file:

         /nix/store/s5z281h1xn24wzfwmdr6699lbdc4xbdi-foo-a/foo

       This is the conflicting file from the new package:

         /nix/store/7dlry4dhs100izx3mdjvbvmzq7mkdfgj-foo-b/foo

       To remove the existing package:

         nix profile remove /nix/store/s5z281h1xn24wzfwmdr6699lbdc4xbdi-foo-a

       The new package can also be installed next to the existing one by assigning a different priority.
       The conflicting packages have a priority of 5.
       To prioritise the new package:

         nix profile install /nix/store/7dlry4dhs100izx3mdjvbvmzq7mkdfgj-foo-b --priority 4

       To prioritise the existing package:

         nix profile install /nix/store/7dlry4dhs100izx3mdjvbvmzq7mkdfgj-foo-b --priority 6

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Thanks!

@Ericson2314 Ericson2314 merged commit 5fd1611 into NixOS:master May 16, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 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.

segfault on conflicting packages in profile
4 participants