From 4ae5091716fa023230a779db03c1cf1e5687c6fb Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Wed, 21 Feb 2024 21:55:51 +0100 Subject: [PATCH] nix profile: suggest removal using entry name When a file conflict arises during a package install a suggestion is made to remove the old entry. This was previously done using the installable URLs of the old entry. These URLs are quite verbose and often do not equal the URL of the existing entry. This change uses the recently introduced profile entry name for the suggestion, resulting in a simpler output. The improvement is easily seen in the change to the functional test. --- src/nix/profile.cc | 12 ++++++------ tests/functional/nix-profile.sh | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 812e703b4..fc669d5ed 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -400,13 +400,13 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile // See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102 auto findRefByFilePath = [&](Iterator begin, Iterator end) { for (auto it = begin; it != end; it++) { - auto & profileElement = it->second; + auto & [name, profileElement] = *it; for (auto & storePath : profileElement.storePaths) { if (conflictError.fileA.starts_with(store->printStorePath(storePath))) { - return std::pair(conflictError.fileA, profileElement.toInstallables(*store)); + return std::tuple(conflictError.fileA, name, profileElement.toInstallables(*store)); } if (conflictError.fileB.starts_with(store->printStorePath(storePath))) { - return std::pair(conflictError.fileB, profileElement.toInstallables(*store)); + return std::tuple(conflictError.fileB, name, profileElement.toInstallables(*store)); } } } @@ -415,9 +415,9 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile // There are 2 conflicting files. We need to find out which one is from the already installed package and // which one is the package that is the new package that is being installed. // The first matching package is the one that was already installed (original). - auto [originalConflictingFilePath, originalConflictingRefs] = findRefByFilePath(manifest.elements.begin(), manifest.elements.end()); + auto [originalConflictingFilePath, originalEntryName, originalConflictingRefs] = findRefByFilePath(manifest.elements.begin(), manifest.elements.end()); // The last matching package is the one that was going to be installed (new). - auto [newConflictingFilePath, newConflictingRefs] = findRefByFilePath(manifest.elements.rbegin(), manifest.elements.rend()); + auto [newConflictingFilePath, newEntryName, newConflictingRefs] = findRefByFilePath(manifest.elements.rbegin(), manifest.elements.rend()); throw Error( "An existing package already provides the following file:\n" @@ -443,7 +443,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile " nix profile install %4% --priority %7%\n", originalConflictingFilePath, newConflictingFilePath, - concatStringsSep(" ", originalConflictingRefs), + originalEntryName, concatStringsSep(" ", newConflictingRefs), conflictError.priority, conflictError.priority - 1, diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index 35a62fbe2..88b713d53 100644 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -166,7 +166,7 @@ error: An existing package already provides the following file: To remove the existing package: - nix profile remove path:${flake1Dir}#packages.${system}.default + nix profile remove flake1 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.