1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-12 05:26:02 +01:00

Add path flakeref variant

Unlike file://<path>, this allows the path to be a dirty Git tree, so

  nix build /path/to/flake:attr

is a convenient way to test building a local flake.
This commit is contained in:
Eelco Dolstra 2019-04-08 22:46:25 +02:00
parent a9ceeeb4b0
commit 6a4c7fb975
6 changed files with 49 additions and 5 deletions

View file

@ -129,6 +129,7 @@ struct FlakeSourceInfo
{
Path storePath;
std::optional<Hash> rev;
std::optional<uint64_t> revCount;
};
static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef)
@ -178,6 +179,18 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef)
FlakeSourceInfo info;
info.storePath = gitInfo.storePath;
info.rev = Hash(gitInfo.rev, htSHA1);
info.revCount = gitInfo.revCount;
return info;
}
else if (auto refData = std::get_if<FlakeRef::IsPath>(&directFlakeRef.data)) {
if (!pathExists(refData->path + "/.git"))
throw Error("flake '%s' does not reference a Git repository", refData->path);
auto gitInfo = exportGit(state.store, refData->path, {}, "", "source");
FlakeSourceInfo info;
info.storePath = gitInfo.storePath;
info.rev = Hash(gitInfo.rev, htSHA1);
info.revCount = gitInfo.revCount;
return info;
}
@ -206,6 +219,8 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef)
}
Flake flake(newFlakeRef);
flake.path = flakePath;
flake.revCount = sourceInfo.revCount;
Value vInfo;
state.evalFile(flakePath + "/flake.nix", vInfo); // FIXME: symlink attack
@ -349,10 +364,20 @@ Value * makeFlakeValue(EvalState & state, const FlakeRef & flakeRef, bool impure
for (auto & flake : flakes) {
auto vFlake = state.allocAttr(*vResult, flake.second.id);
if (topFlakeId == flake.second.id) vTop = vFlake;
state.mkAttrs(*vFlake, 2);
state.mkAttrs(*vFlake, 4);
mkString(*state.allocAttr(*vFlake, state.sDescription), flake.second.description);
state.store->assertStorePath(flake.second.path);
mkString(*state.allocAttr(*vFlake, state.sOutPath), flake.second.path, {flake.second.path});
if (flake.second.revCount)
mkInt(*state.allocAttr(*vFlake, state.symbols.create("revCount")), *flake.second.revCount);
auto vProvides = state.allocAttr(*vFlake, state.symbols.create("provides"));
mkApp(*vProvides, *flake.second.vProvides, *vResult);
vFlake->attrs->sort();
}