diff --git a/src/nix/profile-remove.md b/src/nix/profile-remove.md index e2dea3389..e7e5e0dfb 100644 --- a/src/nix/profile-remove.md +++ b/src/nix/profile-remove.md @@ -11,9 +11,16 @@ R""( * Remove all packages: ```console - # nix profile remove --regex '.*' + # nix profile remove --all ``` +* Remove packages by regular expression: + + ```console + # nix profile remove --regex '.*vim.*' + ``` + + * Remove a package by store path: ```console diff --git a/src/nix/profile-upgrade.md b/src/nix/profile-upgrade.md index e04ad109e..da7a668db 100644 --- a/src/nix/profile-upgrade.md +++ b/src/nix/profile-upgrade.md @@ -6,7 +6,7 @@ R""( reference: ```console - # nix profile upgrade --regex '.*' + # nix profile upgrade --all ``` * Upgrade a specific package by name: @@ -15,6 +15,12 @@ R""( # nix profile upgrade hello ``` +* Upgrade all packages that include 'vim' in their name: + + ```console + # nix profile upgrade --regex '.*vim.*' + ``` + # 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 c08d02e70..701c5cb29 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -458,6 +458,7 @@ enum MatcherType Regex, StorePath, Name, + All, }; struct Matcher @@ -500,6 +501,14 @@ Matcher createNameMatcher(const std::string & name) { }; } +Matcher all = { + .type = MatcherType::All, + .title = "--all", + .matches = [](const std::string &name, const ProfileElement & element) { + return true; + } +}; + class MixProfileElementMatchers : virtual Args, virtual StoreCommand { std::vector _matchers; @@ -508,6 +517,13 @@ public: MixProfileElementMatchers() { + addFlag({ + .longName = "all", + .description = "Match all packages in the profile.", + .handler = {[this]() { + _matchers.push_back(all); + }}, + }); addFlag({ .longName = "regex", .description = "A regular expression to match one or more packages in the profile.", diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index 67c8bcc98..b8513ac02 100644 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -77,6 +77,13 @@ nix profile upgrade --regex '.*' [[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]] nix profile rollback +# Test upgrading all packages +printf 2.2 > $flake1Dir/version +nix profile upgrade --all +[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.2/bin/hello ]] +nix profile rollback +printf 1.0 > $flake1Dir/version + # Test matching no packages using literal package name. assertStderr nix --offline profile upgrade this_package_is_not_installed << EOF warning: Package name 'this_package_is_not_installed' does not match any packages in the profile.