Skip to content

Commit

Permalink
fetchTree: Return a path instead of a store path
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra authored and tomberek committed Aug 22, 2024
1 parent fa49d2e commit 2f84513
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

namespace nix {

void emitTreeAttrs(
static void emitTreeAttrs(
EvalState & state,
const StorePath & storePath,
const fetchers::Input & input,
Value & v,
std::function<void(Value &)> setOutPath,
bool emptyRevFallback,
bool forceDirty)
{
auto attrs = state.buildBindings(100);

state.mkStorePathString(storePath, attrs.alloc(state.sOutPath));
setOutPath(attrs.alloc(state.sOutPath));

// FIXME: support arbitrary input attributes.

Expand Down Expand Up @@ -72,10 +72,27 @@ void emitTreeAttrs(
v.mkAttrs(attrs);
}

void emitTreeAttrs(
EvalState & state,
const StorePath & storePath,
const fetchers::Input & input,
Value & v,
bool emptyRevFallback,
bool forceDirty)
{
emitTreeAttrs(state, input, v,
[&](Value & vOutPath) {
state.mkStorePathString(storePath, vOutPath);
},
emptyRevFallback,
forceDirty);
}

struct FetchTreeParams {
bool emptyRevFallback = false;
bool allowNameArgument = false;
bool isFetchGit = false;
bool returnPath = true; // whether to return a SourcePath or a StorePath
};

static void fetchTree(
Expand Down Expand Up @@ -112,7 +129,9 @@ static void fetchTree(

for (auto & attr : *args[0]->attrs()) {
if (attr.name == state.sType) continue;

state.forceValue(*attr.value, attr.pos);

if (attr.value->type() == nPath || attr.value->type() == nString) {
auto s = state.coerceToString(attr.pos, *attr.value, context, "", false, false).toOwned();
attrs.emplace(state.symbols[attr.name],
Expand Down Expand Up @@ -197,7 +216,14 @@ static void fetchTree(

state.allowPath(storePath);

emitTreeAttrs(state, storePath, input2, v, params.emptyRevFallback, false);
emitTreeAttrs(state, input2, v,
[&](Value & vOutPath) {
if (params.returnPath)
vOutPath.mkPath(state.rootPath(state.store->toRealPath(storePath)));
else
state.mkStorePathString(storePath, vOutPath);
},
params.emptyRevFallback, false);
}

static void prim_fetchTree(EvalState & state, const PosIdx pos, Value * * args, Value & v)
Expand Down Expand Up @@ -614,7 +640,8 @@ static void prim_fetchGit(EvalState & state, const PosIdx pos, Value * * args, V
FetchTreeParams {
.emptyRevFallback = true,
.allowNameArgument = true,
.isFetchGit = true
.isFetchGit = true,
.returnPath = false,
});
}

Expand Down

0 comments on commit 2f84513

Please sign in to comment.