From 46c665e34e3ec653406570fb77be928a10b01fad Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Sat, 9 Sep 2023 13:49:25 +0200 Subject: [PATCH 1/9] nix-env to nix profile: maintain priorities --- src/nix/profile.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 324fd6330..cb310156f 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include "strings.hh" @@ -186,6 +187,16 @@ struct ProfileManifest for (auto & packageInfo : packageInfos) { ProfileElement element; element.storePaths = {packageInfo.queryOutPath()}; + Value * priorityV = drvInfo.queryMeta("priority"); + if (priorityV && priorityV->type() == nString) { + auto result = std::from_chars( + priorityV->str().data(), + priorityV->str().data() + priorityV->str().size(), + element.priority); + if (result.ec != std::errc()) { + throw Error("profile manifest '%s' has invalid priority '%s'", manifestPath, priorityV->str()); + } + } addElement(std::move(element)); } } From 9e58b88084ec6806fedb9a8a0d61771f9c023cc4 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Sun, 10 Sep 2023 15:18:55 +0200 Subject: [PATCH 2/9] nix-env->nix profile prioirty: use queryMetaInt --- src/nix/profile.cc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index cb310156f..7a86e6b01 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -187,16 +187,7 @@ struct ProfileManifest for (auto & packageInfo : packageInfos) { ProfileElement element; element.storePaths = {packageInfo.queryOutPath()}; - Value * priorityV = drvInfo.queryMeta("priority"); - if (priorityV && priorityV->type() == nString) { - auto result = std::from_chars( - priorityV->str().data(), - priorityV->str().data() + priorityV->str().size(), - element.priority); - if (result.ec != std::errc()) { - throw Error("profile manifest '%s' has invalid priority '%s'", manifestPath, priorityV->str()); - } - } + element.priority = packageInfo.queryMetaInt("priority", defaultPriority); addElement(std::move(element)); } } From 049969553881028131c018b8200fe1c8e7d042a9 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Sun, 10 Sep 2023 15:24:03 +0200 Subject: [PATCH 3/9] nix-env -> nix profile priority: add test --- tests/functional/nix-profile.sh | 1 + tests/functional/user-envs.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index 7cf5fcb74..edfc71e50 100755 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -54,6 +54,7 @@ nix-env -f ./user-envs.nix -i foo-1.0 nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-1.0' nix profile install $flake1Dir -L nix profile list | grep -A4 'Name:.*flake1' | grep 'Locked flake URL:.*narHash' +grep '"priority":10' $TEST_HOME/.nix-profile/manifest.json [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]] [ -e $TEST_HOME/.nix-profile/share/man ] (! [ -e $TEST_HOME/.nix-profile/include ]) diff --git a/tests/functional/user-envs.nix b/tests/functional/user-envs.nix index cc63812c4..78aa03857 100644 --- a/tests/functional/user-envs.nix +++ b/tests/functional/user-envs.nix @@ -31,6 +31,7 @@ let // { meta = { description = "A silly test package with some \${escaped anti-quotation} in it"; + priority = 10; inherit platforms; }; } From a332118215af091007ee45ba018a4aff670aeb4e Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Sun, 10 Sep 2023 15:46:24 +0200 Subject: [PATCH 4/9] nix-env -> nix profile priority: fix test --- tests/functional/nix-profile.sh | 5 +++-- tests/functional/user-envs.nix | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index edfc71e50..a7606b9b0 100755 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -50,8 +50,9 @@ printf false > $flake1Dir/ca.nix cp "${config_nix}" $flake1Dir/ # Test upgrading from nix-env. -nix-env -f ./user-envs.nix -i foo-1.0 +nix-env -f ./user-envs.nix -i foo-1.0 foo-0.1 nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-1.0' +nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-0.1' nix profile install $flake1Dir -L nix profile list | grep -A4 'Name:.*flake1' | grep 'Locked flake URL:.*narHash' grep '"priority":10' $TEST_HOME/.nix-profile/manifest.json @@ -64,7 +65,7 @@ nix profile diff-closures | grep 'env-manifest.nix: ε → ∅' # Test XDG Base Directories support export NIX_CONFIG="use-xdg-base-directories = true" -nix profile remove flake1 2>&1 | grep 'removed 1 packages' +nix profile remove foo-0.1 flake1 foo 2>&1 | grep 'removed 1 packages' nix profile install $flake1Dir [[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]] unset NIX_CONFIG diff --git a/tests/functional/user-envs.nix b/tests/functional/user-envs.nix index 78aa03857..cc63812c4 100644 --- a/tests/functional/user-envs.nix +++ b/tests/functional/user-envs.nix @@ -31,7 +31,6 @@ let // { meta = { description = "A silly test package with some \${escaped anti-quotation} in it"; - priority = 10; inherit platforms; }; } From d77a5d3c3b13bb335fe105e7efa9b8f10c695476 Mon Sep 17 00:00:00 2001 From: elikoga Date: Wed, 27 Sep 2023 17:05:27 +0200 Subject: [PATCH 5/9] profile.cc: remove unused include --- src/nix/profile.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 7a86e6b01..b4e22084b 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include "strings.hh" From 664d21d1fde84017fbf9c04bfe89e54825261cbf Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Wed, 29 Jan 2025 11:42:27 +0100 Subject: [PATCH 6/9] profile.cc: use NixInt for priority value in packageInfo --- src/nix/profile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index b4e22084b..0b7c7402c 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -186,7 +186,7 @@ struct ProfileManifest for (auto & packageInfo : packageInfos) { ProfileElement element; element.storePaths = {packageInfo.queryOutPath()}; - element.priority = packageInfo.queryMetaInt("priority", defaultPriority); + element.priority = packageInfo.queryMetaInt("priority", NixInt{defaultPriority}); addElement(std::move(element)); } } From 50409bc8e080b72d8b6f49bf574a605939e15871 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Wed, 29 Jan 2025 11:50:47 +0100 Subject: [PATCH 7/9] profile.cc: extract value from NixInt for priority in packageInfo --- src/nix/profile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 0b7c7402c..e5e8d7154 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -186,7 +186,7 @@ struct ProfileManifest for (auto & packageInfo : packageInfos) { ProfileElement element; element.storePaths = {packageInfo.queryOutPath()}; - element.priority = packageInfo.queryMetaInt("priority", NixInt{defaultPriority}); + element.priority = packageInfo.queryMetaInt("priority", NixInt{defaultPriority}).value; addElement(std::move(element)); } } From 45970a18e6906a5c697bd3632b50fa4ad5c47ad6 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Wed, 29 Jan 2025 12:40:27 +0100 Subject: [PATCH 8/9] tests: update nix profile remove command to reflect correct package removal count --- tests/functional/nix-profile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index a7606b9b0..4324e4140 100755 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -65,7 +65,7 @@ nix profile diff-closures | grep 'env-manifest.nix: ε → ∅' # Test XDG Base Directories support export NIX_CONFIG="use-xdg-base-directories = true" -nix profile remove foo-0.1 flake1 foo 2>&1 | grep 'removed 1 packages' +nix profile remove foo-0.1 flake1 2>&1 | grep 'removed 2 packages' nix profile install $flake1Dir [[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]] unset NIX_CONFIG From 68f3b56b183ca12b64b7fcf0f31dffd62adfcf55 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Wed, 29 Jan 2025 21:47:45 +0100 Subject: [PATCH 9/9] tests: update nix profile remove command to reflect correct package removal count --- tests/functional/nix-profile.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index 4324e4140..26a3c213d 100755 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -62,10 +62,11 @@ grep '"priority":10' $TEST_HOME/.nix-profile/manifest.json nix profile history nix profile history | grep "packages.$system.default: ∅ -> 1.0" nix profile diff-closures | grep 'env-manifest.nix: ε → ∅' +nix profile remove --regex ".*foo-0.1" 2>&1 | grep 'removed 1 packages' # Test XDG Base Directories support export NIX_CONFIG="use-xdg-base-directories = true" -nix profile remove foo-0.1 flake1 2>&1 | grep 'removed 2 packages' +nix profile remove flake1 2>&1 | grep 'removed 1 packages' nix profile install $flake1Dir [[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]] unset NIX_CONFIG