From 2306e967674a7016c556e90e94e5f1e80171892a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Mar 2024 19:30:38 +0100 Subject: [PATCH 1/2] nix profile upgrade: Always upgrade unlocked flakerefs The "lockedRef" field is a misnomer, since it can be unlocked (e.g. for a dirty Git workdir). In that case, `nix profile upgrade` needs to assume that the package can have changed, and perform an upgrade. --- src/nix/profile.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index d39a24d36..60b58a78b 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -648,7 +648,9 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf assert(infop); auto & info = *infop; - if (element.source->lockedRef == info.flake.lockedRef) continue; + if (info.flake.lockedRef.input.isLocked() + && element.source->lockedRef == info.flake.lockedRef) + continue; printInfo("upgrading '%s' from flake '%s' to '%s'", element.source->attrPath, element.source->lockedRef, info.flake.lockedRef); From 32bf39c73a9681317c4288aab16038dc6b401900 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Mar 2024 19:37:43 +0100 Subject: [PATCH 2/2] nix flake metadata: Don't show locked URL if it's not locked This is the case for e.g. dirty Git workdirs, where we would get $ nix flake metadata Resolved URL: git+file:///home/eelco/Dev/nix-master Locked URL: git+file:///home/eelco/Dev/nix-master --- src/nix/flake.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 5fc3f4166..3cd702254 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -219,6 +219,8 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON j["resolvedUrl"] = flake.resolvedRef.to_string(); j["resolved"] = fetchers::attrsToJSON(flake.resolvedRef.toAttrs()); j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl + // "locked" is a misnomer - this is the result of the + // attempt to lock. j["locked"] = fetchers::attrsToJSON(flake.lockedRef.toAttrs()); if (auto rev = flake.lockedRef.input.getRev()) j["revision"] = rev->to_string(HashFormat::Base16, false); @@ -235,9 +237,10 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON logger->cout( ANSI_BOLD "Resolved URL:" ANSI_NORMAL " %s", flake.resolvedRef.to_string()); - logger->cout( - ANSI_BOLD "Locked URL:" ANSI_NORMAL " %s", - flake.lockedRef.to_string()); + if (flake.lockedRef.input.isLocked()) + logger->cout( + ANSI_BOLD "Locked URL:" ANSI_NORMAL " %s", + flake.lockedRef.to_string()); if (flake.description) logger->cout( ANSI_BOLD "Description:" ANSI_NORMAL " %s",