From 9060d0fe46f081ce63441cedc5e16c47f31f4590 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 Jan 2025 16:21:30 +0100 Subject: [PATCH 1/2] Fix missing format argument --- src/nix/flake.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 4d5cad1a8b7..384c23d8c97 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -103,7 +103,7 @@ struct CmdFlakeUpdate : FlakeCommand throw e; } if (lockFlags.inputUpdates.contains(inputPath)) - warn("Input '%s' was specified multiple times. You may have done this by accident."); + warn("Input '%s' was specified multiple times. You may have done this by accident.", printInputPath(inputPath)); lockFlags.inputUpdates.insert(inputPath); } }}, From 7dfff58292475d0aed3dc3e98236ba495c45f261 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 Jan 2025 16:34:35 +0100 Subject: [PATCH 2/2] Rename InputPath -> InputAttrPath Fixes #12098. --- src/libcmd/command.hh | 2 +- src/libcmd/installables.cc | 12 ++-- src/libexpr/call-flake.nix | 2 +- src/libflake/flake/flake.cc | 126 ++++++++++++++++----------------- src/libflake/flake/flake.hh | 6 +- src/libflake/flake/lockfile.cc | 56 +++++++-------- src/libflake/flake/lockfile.hh | 22 +++--- src/nix/flake.cc | 14 ++-- 8 files changed, 120 insertions(+), 120 deletions(-) diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 23529848f6b..9570ce3e7ac 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -347,7 +347,7 @@ struct MixEnvironment : virtual Args void setEnviron(); }; -void completeFlakeInputPath( +void completeFlakeInputAttrPath( AddCompletions & completions, ref evalState, const std::vector & flakeRefs, diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index ab3ab31045c..81eb883daba 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -33,7 +33,7 @@ namespace nix { namespace fs { using namespace std::filesystem; } -void completeFlakeInputPath( +void completeFlakeInputAttrPath( AddCompletions & completions, ref evalState, const std::vector & flakeRefs, @@ -117,10 +117,10 @@ MixFlakeOptions::MixFlakeOptions() .labels = {"input-path"}, .handler = {[&](std::string s) { warn("'--update-input' is a deprecated alias for 'flake update' and will be removed in a future version."); - lockFlags.inputUpdates.insert(flake::parseInputPath(s)); + lockFlags.inputUpdates.insert(flake::parseInputAttrPath(s)); }}, .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) { - completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); + completeFlakeInputAttrPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); }} }); @@ -129,15 +129,15 @@ MixFlakeOptions::MixFlakeOptions() .description = "Override a specific flake input (e.g. `dwarffs/nixpkgs`). This implies `--no-write-lock-file`.", .category = category, .labels = {"input-path", "flake-url"}, - .handler = {[&](std::string inputPath, std::string flakeRef) { + .handler = {[&](std::string inputAttrPath, std::string flakeRef) { lockFlags.writeLockFile = false; lockFlags.inputOverrides.insert_or_assign( - flake::parseInputPath(inputPath), + flake::parseInputAttrPath(inputAttrPath), parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()), true)); }}, .completer = {[&](AddCompletions & completions, size_t n, std::string_view prefix) { if (n == 0) { - completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); + completeFlakeInputAttrPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); } else if (n == 1) { completeFlakeRef(completions, getEvalState()->store, prefix); } diff --git a/src/libexpr/call-flake.nix b/src/libexpr/call-flake.nix index 964ba25219e..3a7a249c673 100644 --- a/src/libexpr/call-flake.nix +++ b/src/libexpr/call-flake.nix @@ -25,7 +25,7 @@ let then getInputByPath lockFile.root inputSpec else inputSpec; - # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the + # Follow an input attrpath (e.g. ["dwarffs" "nixpkgs"]) from the # root node, returning the final node. getInputByPath = nodeName: path: if path == [] diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index 06260c67a5d..9dc73d053d6 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -105,7 +105,7 @@ static std::map parseFlakeInputs( EvalState & state, Value * value, const PosIdx pos, - const InputPath & lockRootPath, + const InputAttrPath & lockRootAttrPath, const SourcePath & flakeDir); static FlakeInput parseFlakeInput( @@ -113,7 +113,7 @@ static FlakeInput parseFlakeInput( std::string_view inputName, Value * value, const PosIdx pos, - const InputPath & lockRootPath, + const InputAttrPath & lockRootAttrPath, const SourcePath & flakeDir) { expectType(state, nAttrs, *value, pos); @@ -137,7 +137,7 @@ static FlakeInput parseFlakeInput( else if (attr.value->type() == nPath) { auto path = attr.value->path(); if (path.accessor != flakeDir.accessor) - throw Error("input path '%s' at %s must be in the same source tree as %s", + throw Error("input attribute path '%s' at %s must be in the same source tree as %s", path, state.positions[attr.pos], flakeDir); url = "path:" + flakeDir.path.makeRelative(path.path); } @@ -149,11 +149,11 @@ static FlakeInput parseFlakeInput( expectType(state, nBool, *attr.value, attr.pos); input.isFlake = attr.value->boolean(); } else if (attr.name == sInputs) { - input.overrides = parseFlakeInputs(state, attr.value, attr.pos, lockRootPath, flakeDir); + input.overrides = parseFlakeInputs(state, attr.value, attr.pos, lockRootAttrPath, flakeDir); } else if (attr.name == sFollows) { expectType(state, nString, *attr.value, attr.pos); - auto follows(parseInputPath(attr.value->c_str())); - follows.insert(follows.begin(), lockRootPath.begin(), lockRootPath.end()); + auto follows(parseInputAttrPath(attr.value->c_str())); + follows.insert(follows.begin(), lockRootAttrPath.begin(), lockRootAttrPath.end()); input.follows = follows; } else { // Allow selecting a subset of enum values @@ -220,7 +220,7 @@ static std::map parseFlakeInputs( EvalState & state, Value * value, const PosIdx pos, - const InputPath & lockRootPath, + const InputAttrPath & lockRootAttrPath, const SourcePath & flakeDir) { std::map inputs; @@ -233,7 +233,7 @@ static std::map parseFlakeInputs( state.symbols[inputAttr.name], inputAttr.value, inputAttr.pos, - lockRootPath, + lockRootAttrPath, flakeDir)); } @@ -246,7 +246,7 @@ static Flake readFlake( const FlakeRef & resolvedRef, const FlakeRef & lockedRef, const SourcePath & rootDir, - const InputPath & lockRootPath) + const InputAttrPath & lockRootAttrPath) { auto flakeDir = rootDir / CanonPath(resolvedRef.subdir); auto flakePath = flakeDir / "flake.nix"; @@ -270,7 +270,7 @@ static Flake readFlake( auto sInputs = state.symbols.create("inputs"); if (auto inputs = vInfo.attrs()->get(sInputs)) - flake.inputs = parseFlakeInputs(state, inputs->value, inputs->pos, lockRootPath, flakeDir); + flake.inputs = parseFlakeInputs(state, inputs->value, inputs->pos, lockRootAttrPath, flakeDir); auto sOutputs = state.symbols.create("outputs"); @@ -347,12 +347,12 @@ static Flake getFlake( const FlakeRef & originalRef, bool useRegistries, FlakeCache & flakeCache, - const InputPath & lockRootPath) + const InputAttrPath & lockRootAttrPath) { auto [storePath, resolvedRef, lockedRef] = fetchOrSubstituteTree( state, originalRef, useRegistries, flakeCache); - return readFlake(state, originalRef, resolvedRef, lockedRef, state.rootPath(state.store->toRealPath(storePath)), lockRootPath); + return readFlake(state, originalRef, resolvedRef, lockedRef, state.rootPath(state.store->toRealPath(storePath)), lockRootAttrPath); } Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool useRegistries) @@ -407,12 +407,12 @@ LockedFlake lockFlake( { FlakeInput input; SourcePath sourcePath; - std::optional parentInputPath; // FIXME: rename to inputPathPrefix? + std::optional parentInputAttrPath; // FIXME: rename to inputAttrPathPrefix? }; - std::map overrides; - std::set explicitCliOverrides; - std::set overridesUsed, updatesUsed; + std::map overrides; + std::set explicitCliOverrides; + std::set overridesUsed, updatesUsed; std::map, SourcePath> nodePaths; for (auto & i : lockFlags.inputOverrides) { @@ -436,9 +436,9 @@ LockedFlake lockFlake( std::function node, - const InputPath & inputPathPrefix, + const InputAttrPath & inputAttrPathPrefix, std::shared_ptr oldNode, - const InputPath & followsPrefix, + const InputAttrPath & followsPrefix, const SourcePath & sourcePath, bool trustLock)> computeLocks; @@ -450,7 +450,7 @@ LockedFlake lockFlake( /* The node whose locks are to be updated.*/ ref node, /* The path to this node in the lock file graph. */ - const InputPath & inputPathPrefix, + const InputAttrPath & inputAttrPathPrefix, /* The old node, if any, from which locks can be copied. */ std::shared_ptr oldNode, @@ -458,59 +458,59 @@ LockedFlake lockFlake( interpreted. When a node is initially locked, it's relative to the node's flake; when it's already locked, it's relative to the root of the lock file. */ - const InputPath & followsPrefix, + const InputAttrPath & followsPrefix, /* The source path of this node's flake. */ const SourcePath & sourcePath, bool trustLock) { - debug("computing lock file node '%s'", printInputPath(inputPathPrefix)); + debug("computing lock file node '%s'", printInputAttrPath(inputAttrPathPrefix)); /* Get the overrides (i.e. attributes of the form 'inputs.nixops.inputs.nixpkgs.url = ...'). */ for (auto & [id, input] : flakeInputs) { for (auto & [idOverride, inputOverride] : input.overrides) { - auto inputPath(inputPathPrefix); - inputPath.push_back(id); - inputPath.push_back(idOverride); - overrides.emplace(inputPath, + auto inputAttrPath(inputAttrPathPrefix); + inputAttrPath.push_back(id); + inputAttrPath.push_back(idOverride); + overrides.emplace(inputAttrPath, OverrideTarget { .input = inputOverride, .sourcePath = sourcePath, - .parentInputPath = inputPathPrefix + .parentInputAttrPath = inputAttrPathPrefix }); } } /* Check whether this input has overrides for a non-existent input. */ - for (auto [inputPath, inputOverride] : overrides) { - auto inputPath2(inputPath); - auto follow = inputPath2.back(); - inputPath2.pop_back(); - if (inputPath2 == inputPathPrefix && !flakeInputs.count(follow)) + for (auto [inputAttrPath, inputOverride] : overrides) { + auto inputAttrPath2(inputAttrPath); + auto follow = inputAttrPath2.back(); + inputAttrPath2.pop_back(); + if (inputAttrPath2 == inputAttrPathPrefix && !flakeInputs.count(follow)) warn( "input '%s' has an override for a non-existent input '%s'", - printInputPath(inputPathPrefix), follow); + printInputAttrPath(inputAttrPathPrefix), follow); } /* Go over the flake inputs, resolve/fetch them if necessary (i.e. if they're new or the flakeref changed from what's in the lock file). */ for (auto & [id, input2] : flakeInputs) { - auto inputPath(inputPathPrefix); - inputPath.push_back(id); - auto inputPathS = printInputPath(inputPath); - debug("computing input '%s'", inputPathS); + auto inputAttrPath(inputAttrPathPrefix); + inputAttrPath.push_back(id); + auto inputAttrPathS = printInputAttrPath(inputAttrPath); + debug("computing input '%s'", inputAttrPathS); try { /* Do we have an override for this input from one of the ancestors? */ - auto i = overrides.find(inputPath); + auto i = overrides.find(inputAttrPath); bool hasOverride = i != overrides.end(); - bool hasCliOverride = explicitCliOverrides.contains(inputPath); + bool hasCliOverride = explicitCliOverrides.contains(inputAttrPath); if (hasOverride) - overridesUsed.insert(inputPath); + overridesUsed.insert(inputAttrPath); auto input = hasOverride ? i->second.input : input2; /* Resolve relative 'path:' inputs relative to @@ -525,11 +525,11 @@ LockedFlake lockFlake( /* Resolve 'follows' later (since it may refer to an input path we haven't processed yet. */ if (input.follows) { - InputPath target; + InputAttrPath target; target.insert(target.end(), input.follows->begin(), input.follows->end()); - debug("input '%s' follows '%s'", inputPathS, printInputPath(target)); + debug("input '%s' follows '%s'", inputAttrPathS, printInputAttrPath(target)); node->inputs.insert_or_assign(id, target); continue; } @@ -538,7 +538,7 @@ LockedFlake lockFlake( auto overridenParentPath = input.ref->input.isRelative() - ? std::optional(hasOverride ? i->second.parentInputPath : inputPathPrefix) + ? std::optional(hasOverride ? i->second.parentInputAttrPath : inputAttrPathPrefix) : std::nullopt; auto resolveRelativePath = [&]() -> std::optional @@ -557,9 +557,9 @@ LockedFlake lockFlake( auto getInputFlake = [&]() { if (auto resolvedPath = resolveRelativePath()) { - return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputPath); + return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputAttrPath); } else { - return getFlake(state, *input.ref, useRegistries, flakeCache, inputPath); + return getFlake(state, *input.ref, useRegistries, flakeCache, inputAttrPath); } }; @@ -567,19 +567,19 @@ LockedFlake lockFlake( And the input is not in updateInputs? */ std::shared_ptr oldLock; - updatesUsed.insert(inputPath); + updatesUsed.insert(inputAttrPath); - if (oldNode && !lockFlags.inputUpdates.count(inputPath)) + if (oldNode && !lockFlags.inputUpdates.count(inputAttrPath)) if (auto oldLock2 = get(oldNode->inputs, id)) if (auto oldLock3 = std::get_if<0>(&*oldLock2)) oldLock = *oldLock3; if (oldLock && oldLock->originalRef == *input.ref - && oldLock->parentPath == overridenParentPath + && oldLock->parentInputAttrPath == overridenParentPath && !hasCliOverride) { - debug("keeping existing input '%s'", inputPathS); + debug("keeping existing input '%s'", inputAttrPathS); /* Copy the input from the old lock since its flakeref didn't change and there is no override from a @@ -588,18 +588,18 @@ LockedFlake lockFlake( oldLock->lockedRef, oldLock->originalRef, oldLock->isFlake, - oldLock->parentPath); + oldLock->parentInputAttrPath); node->inputs.insert_or_assign(id, childNode); /* If we have this input in updateInputs, then we must fetch the flake to update it. */ - auto lb = lockFlags.inputUpdates.lower_bound(inputPath); + auto lb = lockFlags.inputUpdates.lower_bound(inputAttrPath); auto mustRefetch = lb != lockFlags.inputUpdates.end() - && lb->size() > inputPath.size() - && std::equal(inputPath.begin(), inputPath.end(), lb->begin()); + && lb->size() > inputAttrPath.size() + && std::equal(inputAttrPath.begin(), inputAttrPath.end(), lb->begin()); FlakeInputs fakeInputs; @@ -618,7 +618,7 @@ LockedFlake lockFlake( if (!trustLock) { // It is possible that the flake has changed, // so we must confirm all the follows that are in the lock file are also in the flake. - auto overridePath(inputPath); + auto overridePath(inputAttrPath); overridePath.push_back(i.first); auto o = overrides.find(overridePath); // If the override disappeared, we have to refetch the flake, @@ -642,21 +642,21 @@ LockedFlake lockFlake( if (mustRefetch) { auto inputFlake = getInputFlake(); nodePaths.emplace(childNode, inputFlake.path.parent()); - computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, followsPrefix, + computeLocks(inputFlake.inputs, childNode, inputAttrPath, oldLock, followsPrefix, inputFlake.path, false); } else { - computeLocks(fakeInputs, childNode, inputPath, oldLock, followsPrefix, sourcePath, true); + computeLocks(fakeInputs, childNode, inputAttrPath, oldLock, followsPrefix, sourcePath, true); } } else { /* We need to create a new lock file entry. So fetch this input. */ - debug("creating new input '%s'", inputPathS); + debug("creating new input '%s'", inputAttrPathS); if (!lockFlags.allowUnlocked && !input.ref->input.isLocked() && !input.ref->input.isRelative()) - throw Error("cannot update unlocked flake input '%s' in pure mode", inputPathS); + throw Error("cannot update unlocked flake input '%s' in pure mode", inputAttrPathS); /* Note: in case of an --override-input, we use the *original* ref (input2.ref) for the @@ -665,7 +665,7 @@ LockedFlake lockFlake( nuked the next time we update the lock file. That is, overrides are sticky unless you use --no-write-lock-file. */ - auto ref = (input2.ref && explicitCliOverrides.contains(inputPath)) ? *input2.ref : *input.ref; + auto ref = (input2.ref && explicitCliOverrides.contains(inputAttrPath)) ? *input2.ref : *input.ref; if (input.isFlake) { auto inputFlake = getInputFlake(); @@ -691,11 +691,11 @@ LockedFlake lockFlake( own lock file. */ nodePaths.emplace(childNode, inputFlake.path.parent()); computeLocks( - inputFlake.inputs, childNode, inputPath, + inputFlake.inputs, childNode, inputAttrPath, oldLock ? std::dynamic_pointer_cast(oldLock) : readLockFile(state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(), - oldLock ? followsPrefix : inputPath, + oldLock ? followsPrefix : inputAttrPath, inputFlake.path, false); } @@ -722,7 +722,7 @@ LockedFlake lockFlake( } } catch (Error & e) { - e.addTrace({}, "while updating the flake input '%s'", inputPathS); + e.addTrace({}, "while updating the flake input '%s'", inputAttrPathS); throw; } } @@ -742,11 +742,11 @@ LockedFlake lockFlake( for (auto & i : lockFlags.inputOverrides) if (!overridesUsed.count(i.first)) warn("the flag '--override-input %s %s' does not match any input", - printInputPath(i.first), i.second); + printInputAttrPath(i.first), i.second); for (auto & i : lockFlags.inputUpdates) if (!updatesUsed.count(i)) - warn("'%s' does not match any input of this flake", printInputPath(i)); + warn("'%s' does not match any input of this flake", printInputAttrPath(i)); /* Check 'follows' inputs. */ newLockFile.check(); diff --git a/src/libflake/flake/flake.hh b/src/libflake/flake/flake.hh index 9ab661fcee7..835d0ee0694 100644 --- a/src/libflake/flake/flake.hh +++ b/src/libflake/flake/flake.hh @@ -57,7 +57,7 @@ struct FlakeInput * false = (fetched) static source path */ bool isFlake = true; - std::optional follows; + std::optional follows; FlakeInputs overrides; }; @@ -201,13 +201,13 @@ struct LockFlags /** * Flake inputs to be overridden. */ - std::map inputOverrides; + std::map inputOverrides; /** * Flake inputs to be updated. This means that any existing lock * for those inputs will be ignored. */ - std::set inputUpdates; + std::set inputUpdates; }; LockedFlake lockFlake( diff --git a/src/libflake/flake/lockfile.cc b/src/libflake/flake/lockfile.cc index 67af108b833..25e7299f0a0 100644 --- a/src/libflake/flake/lockfile.cc +++ b/src/libflake/flake/lockfile.cc @@ -43,7 +43,7 @@ LockedNode::LockedNode( : lockedRef(getFlakeRef(fetchSettings, json, "locked", "info")) // FIXME: remove "info" , originalRef(getFlakeRef(fetchSettings, json, "original", nullptr)) , isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true) - , parentPath(json.find("parent") != json.end() ? (std::optional) json["parent"] : std::nullopt) + , parentInputAttrPath(json.find("parent") != json.end() ? (std::optional) json["parent"] : std::nullopt) { if (!lockedRef.input.isConsideredLocked(fetchSettings) && !lockedRef.input.isRelative()) throw Error("Lock file contains unlocked input '%s'. Use '--allow-dirty-locks' to accept this lock file.", @@ -59,7 +59,7 @@ StorePath LockedNode::computeStorePath(Store & store) const return lockedRef.input.computeStorePath(store); } -static std::shared_ptr doFind(const ref & root, const InputPath & path, std::vector & visited) +static std::shared_ptr doFind(const ref & root, const InputAttrPath & path, std::vector & visited) { auto pos = root; @@ -67,8 +67,8 @@ static std::shared_ptr doFind(const ref & root, const InputPath & pa if (found != visited.end()) { std::vector cycle; - std::transform(found, visited.cend(), std::back_inserter(cycle), printInputPath); - cycle.push_back(printInputPath(path)); + std::transform(found, visited.cend(), std::back_inserter(cycle), printInputAttrPath); + cycle.push_back(printInputAttrPath(path)); throw Error("follow cycle detected: [%s]", concatStringsSep(" -> ", cycle)); } visited.push_back(path); @@ -90,9 +90,9 @@ static std::shared_ptr doFind(const ref & root, const InputPath & pa return pos; } -std::shared_ptr LockFile::findInput(const InputPath & path) +std::shared_ptr LockFile::findInput(const InputAttrPath & path) { - std::vector visited; + std::vector visited; return doFind(root, path, visited); } @@ -115,7 +115,7 @@ LockFile::LockFile( if (jsonNode.find("inputs") == jsonNode.end()) return; for (auto & i : jsonNode["inputs"].items()) { if (i.value().is_array()) { // FIXME: remove, obsolete - InputPath path; + InputAttrPath path; for (auto & j : i.value()) path.push_back(j); node.inputs.insert_or_assign(i.key(), path); @@ -203,8 +203,8 @@ std::pair LockFile::toJSON() const n["locked"].erase("__final"); if (!lockedNode->isFlake) n["flake"] = false; - if (lockedNode->parentPath) - n["parent"] = *lockedNode->parentPath; + if (lockedNode->parentInputAttrPath) + n["parent"] = *lockedNode->parentInputAttrPath; } nodes[key] = std::move(n); @@ -267,36 +267,36 @@ bool LockFile::operator ==(const LockFile & other) const return toJSON().first == other.toJSON().first; } -InputPath parseInputPath(std::string_view s) +InputAttrPath parseInputAttrPath(std::string_view s) { - InputPath path; + InputAttrPath path; for (auto & elem : tokenizeString>(s, "/")) { if (!std::regex_match(elem, flakeIdRegex)) - throw UsageError("invalid flake input path element '%s'", elem); + throw UsageError("invalid flake input attribute path element '%s'", elem); path.push_back(elem); } return path; } -std::map LockFile::getAllInputs() const +std::map LockFile::getAllInputs() const { std::set> done; - std::map res; + std::map res; - std::function node)> recurse; + std::function node)> recurse; - recurse = [&](const InputPath & prefix, ref node) + recurse = [&](const InputAttrPath & prefix, ref node) { if (!done.insert(node).second) return; for (auto &[id, input] : node->inputs) { - auto inputPath(prefix); - inputPath.push_back(id); - res.emplace(inputPath, input); + auto inputAttrPath(prefix); + inputAttrPath.push_back(id); + res.emplace(inputAttrPath, input); if (auto child = std::get_if<0>(&input)) - recurse(inputPath, *child); + recurse(inputAttrPath, *child); } }; @@ -320,7 +320,7 @@ std::ostream & operator <<(std::ostream & stream, const Node::Edge & edge) if (auto node = std::get_if<0>(&edge)) stream << describe((*node)->lockedRef); else if (auto follows = std::get_if<1>(&edge)) - stream << fmt("follows '%s'", printInputPath(*follows)); + stream << fmt("follows '%s'", printInputAttrPath(*follows)); return stream; } @@ -347,15 +347,15 @@ std::string LockFile::diff(const LockFile & oldLocks, const LockFile & newLocks) while (i != oldFlat.end() || j != newFlat.end()) { if (j != newFlat.end() && (i == oldFlat.end() || i->first > j->first)) { res += fmt("• " ANSI_GREEN "Added input '%s':" ANSI_NORMAL "\n %s\n", - printInputPath(j->first), j->second); + printInputAttrPath(j->first), j->second); ++j; } else if (i != oldFlat.end() && (j == newFlat.end() || i->first < j->first)) { - res += fmt("• " ANSI_RED "Removed input '%s'" ANSI_NORMAL "\n", printInputPath(i->first)); + res += fmt("• " ANSI_RED "Removed input '%s'" ANSI_NORMAL "\n", printInputAttrPath(i->first)); ++i; } else { if (!equals(i->second, j->second)) { res += fmt("• " ANSI_BOLD "Updated input '%s':" ANSI_NORMAL "\n %s\n → %s\n", - printInputPath(i->first), + printInputAttrPath(i->first), i->second, j->second); } @@ -371,19 +371,19 @@ void LockFile::check() { auto inputs = getAllInputs(); - for (auto & [inputPath, input] : inputs) { + for (auto & [inputAttrPath, input] : inputs) { if (auto follows = std::get_if<1>(&input)) { if (!follows->empty() && !findInput(*follows)) throw Error("input '%s' follows a non-existent input '%s'", - printInputPath(inputPath), - printInputPath(*follows)); + printInputAttrPath(inputAttrPath), + printInputAttrPath(*follows)); } } } void check(); -std::string printInputPath(const InputPath & path) +std::string printInputAttrPath(const InputAttrPath & path) { return concatStringsSep("/", path); } diff --git a/src/libflake/flake/lockfile.hh b/src/libflake/flake/lockfile.hh index cb7c8da5ada..cbc6d01ebce 100644 --- a/src/libflake/flake/lockfile.hh +++ b/src/libflake/flake/lockfile.hh @@ -12,7 +12,7 @@ class StorePath; namespace nix::flake { -typedef std::vector InputPath; +typedef std::vector InputAttrPath; struct LockedNode; @@ -23,7 +23,7 @@ struct LockedNode; */ struct Node : std::enable_shared_from_this { - typedef std::variant, InputPath> Edge; + typedef std::variant, InputAttrPath> Edge; std::map inputs; @@ -40,17 +40,17 @@ struct LockedNode : Node /* The node relative to which relative source paths (e.g. 'path:../foo') are interpreted. */ - std::optional parentPath; + std::optional parentInputAttrPath; LockedNode( const FlakeRef & lockedRef, const FlakeRef & originalRef, bool isFlake = true, - std::optional parentPath = {}) - : lockedRef(lockedRef) - , originalRef(originalRef) + std::optional parentInputAttrPath = {}) + : lockedRef(std::move(lockedRef)) + , originalRef(std::move(originalRef)) , isFlake(isFlake) - , parentPath(parentPath) + , parentInputAttrPath(std::move(parentInputAttrPath)) { } LockedNode( @@ -83,9 +83,9 @@ struct LockFile bool operator ==(const LockFile & other) const; - std::shared_ptr findInput(const InputPath & path); + std::shared_ptr findInput(const InputAttrPath & path); - std::map getAllInputs() const; + std::map getAllInputs() const; static std::string diff(const LockFile & oldLocks, const LockFile & newLocks); @@ -97,8 +97,8 @@ struct LockFile std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile); -InputPath parseInputPath(std::string_view s); +InputAttrPath parseInputAttrPath(std::string_view s); -std::string printInputPath(const InputPath & path); +std::string printInputAttrPath(const InputAttrPath & path); } diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 384c23d8c97..adf391b97be 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -95,20 +95,20 @@ struct CmdFlakeUpdate : FlakeCommand .optional=true, .handler={[&](std::vector inputsToUpdate){ for (const auto & inputToUpdate : inputsToUpdate) { - InputPath inputPath; + InputAttrPath inputAttrPath; try { - inputPath = flake::parseInputPath(inputToUpdate); + inputAttrPath = flake::parseInputAttrPath(inputToUpdate); } catch (Error & e) { warn("Invalid flake input '%s'. To update a specific flake, use 'nix flake update --flake %s' instead.", inputToUpdate, inputToUpdate); throw e; } - if (lockFlags.inputUpdates.contains(inputPath)) - warn("Input '%s' was specified multiple times. You may have done this by accident.", printInputPath(inputPath)); - lockFlags.inputUpdates.insert(inputPath); + if (lockFlags.inputUpdates.contains(inputAttrPath)) + warn("Input '%s' was specified multiple times. You may have done this by accident.", printInputAttrPath(inputAttrPath)); + lockFlags.inputUpdates.insert(inputAttrPath); } }}, .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) { - completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); + completeFlakeInputAttrPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); }} }); @@ -304,7 +304,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON } else if (auto follows = std::get_if<1>(&input.second)) { logger->cout("%s" ANSI_BOLD "%s" ANSI_NORMAL " follows input '%s'", prefix + (last ? treeLast : treeConn), input.first, - printInputPath(*follows)); + printInputAttrPath(*follows)); } } };