From 61295b910f2f2a6f2b0d288248c946713977ff1e Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 20 Feb 2022 23:46:11 -0600 Subject: [PATCH 1/2] Add verbosity to nix profile upgrade Followup of https://github.com/NixOS/nix/pull/6086. This time adding a warning if no packages are upgraded. --- src/nix/profile.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 55b5ff736..f0ce7eba8 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -410,12 +410,16 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf // FIXME: code duplication std::vector pathsToBuild; + auto upgradedCount = 0; + for (size_t i = 0; i < manifest.elements.size(); ++i) { auto & element(manifest.elements[i]); if (element.source && !element.source->originalRef.input.isImmutable() && matches(*store, element, i, matchers)) { + upgradedCount++; + Activity act(*logger, lvlChatty, actUnknown, fmt("checking '%s' for updates", element.source->attrPath)); @@ -448,6 +452,19 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf } } + if (upgradedCount == 0) { + for (auto matcher: matchers) { + if (const size_t* index = std::get_if(&matcher)){ + warn("'%d' is not a valid index in profile", *index); + } else if (const Path* path = std::get_if(&matcher)){ + warn("'%s' does not match any paths in profile", *path); + } else if (const RegexPattern* regex = std::get_if(&matcher)){ + warn("'%s' does not match any packages in profile", regex->pattern); + } + } + warn ("Try `nix profile list` to see the current profile."); + } + store->buildPaths(pathsToBuild); updateProfile(manifest.build(store)); From 3cd958849b820ba6ec80965afa6268f59c9bb650 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Mon, 21 Feb 2022 10:04:04 -0600 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Eelco Dolstra --- src/nix/profile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index f0ce7eba8..508cbd336 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -453,7 +453,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf } if (upgradedCount == 0) { - for (auto matcher: matchers) { + for (auto & matcher : matchers) { if (const size_t* index = std::get_if(&matcher)){ warn("'%d' is not a valid index in profile", *index); } else if (const Path* path = std::get_if(&matcher)){ @@ -462,7 +462,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf warn("'%s' does not match any packages in profile", regex->pattern); } } - warn ("Try `nix profile list` to see the current profile."); + warn ("Use 'nix profile list' to see the current profile."); } store->buildPaths(pathsToBuild);