Skip to content

Commit

Permalink
Merge pull request #12366 from NixOS/mergify/bp/2.25-maintenance/pr-1…
Browse files Browse the repository at this point in the history
…2362

refactor: Extract EvalState::realiseString (backport #12362)
  • Loading branch information
mergify[bot] authored Jan 27, 2025
2 parents 95253b1 + 7d3021f commit 37393f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/libexpr-c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,8 @@ nix_realised_string * nix_string_realise(nix_c_context * context, EvalState * st
context->last_err_code = NIX_OK;
try {
auto & v = check_value_in(value);
nix::NixStringContext stringContext;
auto rawStr = state->state.coerceToString(nix::noPos, v, stringContext, "while realising a string").toOwned();
nix::StorePathSet storePaths;
auto rewrites = state->state.realiseContext(stringContext, &storePaths);

auto s = nix::rewriteStrings(rawStr, rewrites);
auto s = state->state.realiseString(v, &storePaths, isIFD);

// Convert to the C API StorePath type and convert to vector for index-based access
std::vector<StorePath> vec;
Expand Down
9 changes: 9 additions & 0 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@ public:
*/
[[nodiscard]] StringMap realiseContext(const NixStringContext & context, StorePathSet * maybePaths = nullptr, bool isIFD = true);

/**
* Realise the given string with context, and return the string with outputs instead of downstream output placeholders.
* @param[in] str the string to realise
* @param[out] paths all referenced store paths will be added to this set
* @return the realised string
* @throw EvalError if the value is not a string, path or derivation (see `coerceToString`)
*/
std::string realiseString(Value & str, StorePathSet * storePathsOutMaybe, bool isIFD = true, const PosIdx pos = noPos);

/* Call the binary path filter predicate used builtins.path etc. */
bool callPathFilter(
Value * filterFun,
Expand Down
9 changes: 9 additions & 0 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ static inline Value * mkString(EvalState & state, const std::csub_match & match)
return v;
}

std::string EvalState::realiseString(Value & s, StorePathSet * storePathsOutMaybe, bool isIFD, const PosIdx pos)
{
nix::NixStringContext stringContext;
auto rawStr = coerceToString(pos, s, stringContext, "while realising a string").toOwned();
auto rewrites = realiseContext(stringContext, storePathsOutMaybe, isIFD);

return nix::rewriteStrings(rawStr, rewrites);
}

StringMap EvalState::realiseContext(const NixStringContext & context, StorePathSet * maybePathsOut, bool isIFD)
{
std::vector<DerivedPath::Built> drvs;
Expand Down

0 comments on commit 37393f0

Please sign in to comment.