aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-05-01 19:12:04 -0600
committerQyriad <qyriad@qyriad.me>2024-05-02 12:02:28 -0600
commite98fc952a81f89c86e871120aac6272dccdc83b9 (patch)
tree73df621cff223fabfc1abadfbbaf457c9c71b36c /src
parentf88423813f042cf40d9207409cd05cf4b75d87a0 (diff)
nix3-profile: remove indices
Based off of commit 3187bc9ac3dd193b9329ef68c73ac3cca794ed78 Upstream-PR: https://github.com/NixOS/nix/pull/9656 Co-authored-by: Eelco Dolstra <edolstra@gmail.com> Change-Id: I8ac4a33314cd1cf9de95404c20f58e883460acc7
Diffstat (limited to 'src')
-rw-r--r--src/nix/profile-list.md5
-rw-r--r--src/nix/profile-remove.md7
-rw-r--r--src/nix/profile-upgrade.md6
-rw-r--r--src/nix/profile.cc39
4 files changed, 9 insertions, 48 deletions
diff --git a/src/nix/profile-list.md b/src/nix/profile-list.md
index d807a69c6..9baea4ada 100644
--- a/src/nix/profile-list.md
+++ b/src/nix/profile-list.md
@@ -7,13 +7,11 @@ R""(
```console
# nix profile list
Name: gdb
- Index: 0
Flake attribute: legacyPackages.x86_64-linux.gdb
Original flake URL: flake:nixpkgs
Locked flake URL: github:NixOS/nixpkgs/7b38b03d76ab71bdc8dc325e3f6338d984cc35ca
Store paths: /nix/store/indzcw5wvlhx6vwk7k4iq29q15chvr3d-gdb-11.1
- Index: 1
Name: blender-bin
Flake attribute: packages.x86_64-linux.default
Original flake URL: flake:blender-bin
@@ -40,9 +38,6 @@ information:
package in invocations of `nix profile remove` and `nix profile
upgrade`.
-* `Index`: An integer that can be used to unambiguously identify the package in invocations of `nix profile remove` and `nix profile upgrade`.
- (*Deprecated, will be removed in a future version in favor of `Name`.*)
-
* `Flake attribute`: The flake output attribute path that provides the
package (e.g. `packages.x86_64-linux.hello`).
diff --git a/src/nix/profile-remove.md b/src/nix/profile-remove.md
index c76f4b09c..81f7e513a 100644
--- a/src/nix/profile-remove.md
+++ b/src/nix/profile-remove.md
@@ -8,13 +8,6 @@ R""(
# nix profile remove hello
```
-* Remove a package by index
- *(deprecated, will be removed in a future version)*:
-
- ```console
- $ nix profile remove 3
- ```
-
* Remove a package by attribute path:
```console
diff --git a/src/nix/profile-upgrade.md b/src/nix/profile-upgrade.md
index b13cb66bb..57983085f 100644
--- a/src/nix/profile-upgrade.md
+++ b/src/nix/profile-upgrade.md
@@ -19,12 +19,6 @@ R""(
# nix profile upgrade packages.x86_64-linux.hello
```
-* Upgrade a specific package by index:
-
- ```console
- # nix profile upgrade 0
- ```
-
# Description
This command upgrades a previously installed package in a Nix profile,
diff --git a/src/nix/profile.cc b/src/nix/profile.cc
index f702c7c06..131abb258 100644
--- a/src/nix/profile.cc
+++ b/src/nix/profile.cc
@@ -183,18 +183,15 @@ public:
std::string pattern;
std::regex reg;
};
- typedef std::variant<size_t, Path, RegexPattern> Matcher;
+ using Matcher = std::variant<Path, RegexPattern>;
std::vector<Matcher> getMatchers(ref<Store> store)
{
std::vector<Matcher> res;
- auto anyIndexMatchers = false;
-
for (auto & s : _matchers) {
if (auto n = string2Int<size_t>(s)) {
- res.push_back(*n);
- anyIndexMatchers = true;
+ throw Error("'nix profile' no longer supports indices ('%d')", *n);
} else if (store->isStorePath(s)) {
res.push_back(s);
} else {
@@ -202,23 +199,13 @@ public:
}
}
- if (anyIndexMatchers) {
- warn(
- "Indices are deprecated and be removed in a future version!\n"
- " Refer to packages by their `Name` printed by `nix profile list`.\n"
- );
- }
-
return res;
}
- bool matches(const Store & store, const ProfileElement & element, size_t pos, const std::vector<Matcher> & matchers)
+ bool matches(const Store & store, const ProfileElement & element, const std::vector<Matcher> & matchers)
{
for (auto & matcher : matchers) {
- if (auto n = std::get_if<size_t>(&matcher)) {
- if (*n == pos) return true;
-
- } else if (auto path = std::get_if<Path>(&matcher)) {
+ if (auto path = std::get_if<Path>(&matcher)) {
if (element.storePaths.count(store.parseStorePath(*path))) return true;
} else if (auto regex = std::get_if<RegexPattern>(&matcher)) {
if (std::regex_match(element.name, regex->reg)) {
@@ -255,7 +242,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem
for (size_t i = 0; i < oldManifest.elements.size(); ++i) {
auto & element(oldManifest.elements[i]);
- if (!matches(*store, element, i, matchers)) {
+ if (!matches(*store, element, matchers)) {
newManifest.elements.push_back(std::move(element));
} else {
notice("removing '%s'", element.identifier());
@@ -269,9 +256,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem
if (removedCount == 0) {
for (auto matcher: matchers) {
- if (const size_t * index = std::get_if<size_t>(&matcher)){
- warn("'%d' is not a valid index", *index);
- } else if (const Path * path = std::get_if<Path>(&matcher)){
+ if (const Path * path = std::get_if<Path>(&matcher)) {
warn("'%s' does not match any paths", *path);
} else if (const RegexPattern * regex = std::get_if<RegexPattern>(&matcher)){
warn("'%s' does not match any packages", regex->pattern);
@@ -311,7 +296,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
for (size_t i = 0; i < manifest.elements.size(); ++i) {
auto & element(manifest.elements[i]);
- if (!matches(*store, element, i, matchers)) {
+ if (!matches(*store, element, matchers)) {
continue;
}
@@ -390,11 +375,9 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
if (upgradedCount == 0) {
if (matchedCount == 0) {
for (auto & matcher : matchers) {
- if (const size_t * index = std::get_if<size_t>(&matcher)){
- warn("'%d' is not a valid index", *index);
- } else if (const Path * path = std::get_if<Path>(&matcher)){
+ if (const Path * path = std::get_if<Path>(&matcher)){
warn("'%s' does not match any paths", *path);
- } else if (const RegexPattern * regex = std::get_if<RegexPattern>(&matcher)){
+ } else if (const RegexPattern * regex = std::get_if<RegexPattern>(&matcher)) {
warn("'%s' does not match any packages", regex->pattern);
}
}
@@ -452,10 +435,6 @@ struct CmdProfileList : virtual EvalCommand, virtual StoreCommand, MixDefaultPro
element.name,
element.active ? "" : " " ANSI_RED "(inactive)" ANSI_NORMAL
);
- logger->cout(
- "Index: " ANSI_BOLD "%s" ANSI_NORMAL "%S",
- i
- );
if (element.source) {
logger->cout("Flake attribute: %s%s", element.source->attrPath, element.source->outputs.to_string());
logger->cout("Original flake URL: %s", element.source->originalRef.to_string());