forked from lix-project/lix
Make non-flake inputs lazy
Also add a proper test for non-flake inputs.
This commit is contained in:
parent
1c5067b9a7
commit
1e53a07712
|
@ -276,7 +276,7 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the `NonFlake` corresponding to a `FlakeRef`.
|
// Get the `NonFlake` corresponding to a `FlakeRef`.
|
||||||
NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias alias, bool impureIsAllowed = false)
|
NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowed = false)
|
||||||
{
|
{
|
||||||
auto sourceInfo = fetchFlake(state, flakeRef, impureIsAllowed);
|
auto sourceInfo = fetchFlake(state, flakeRef, impureIsAllowed);
|
||||||
debug("got non-flake source '%s' with flakeref %s", sourceInfo.storePath, sourceInfo.resolvedRef.to_string());
|
debug("got non-flake source '%s' with flakeref %s", sourceInfo.storePath, sourceInfo.resolvedRef.to_string());
|
||||||
|
@ -290,8 +290,6 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al
|
||||||
if (state.allowedPaths)
|
if (state.allowedPaths)
|
||||||
state.allowedPaths->insert(nonFlake.sourceInfo.storePath);
|
state.allowedPaths->insert(nonFlake.sourceInfo.storePath);
|
||||||
|
|
||||||
nonFlake.alias = alias;
|
|
||||||
|
|
||||||
return nonFlake;
|
return nonFlake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +337,7 @@ static std::pair<Flake, FlakeInput> updateLocks(
|
||||||
} else {
|
} else {
|
||||||
if (handleLockFile == AllPure || handleLockFile == TopRefUsesRegistries)
|
if (handleLockFile == AllPure || handleLockFile == TopRefUsesRegistries)
|
||||||
throw Error("cannot update non-flake dependency '%s' in pure mode", id);
|
throw Error("cannot update non-flake dependency '%s' in pure mode", id);
|
||||||
auto nonFlake = getNonFlake(state, ref, id, allowedToUseRegistries(handleLockFile, false));
|
auto nonFlake = getNonFlake(state, ref, allowedToUseRegistries(handleLockFile, false));
|
||||||
newEntry.nonFlakeInputs.insert_or_assign(id,
|
newEntry.nonFlakeInputs.insert_or_assign(id,
|
||||||
NonFlakeInput(
|
NonFlakeInput(
|
||||||
nonFlake.sourceInfo.resolvedRef,
|
nonFlake.sourceInfo.resolvedRef,
|
||||||
|
@ -441,6 +439,25 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V
|
||||||
callFlake(state, flake, *lazyFlake, v);
|
callFlake(state, flake, *lazyFlake, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prim_callNonFlake(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
|
{
|
||||||
|
auto lazyNonFlake = (NonFlakeInput *) args[0]->attrs;
|
||||||
|
|
||||||
|
auto nonFlake = getNonFlake(state, lazyNonFlake->ref);
|
||||||
|
|
||||||
|
if (nonFlake.sourceInfo.narHash != lazyNonFlake->narHash)
|
||||||
|
throw Error("the content hash of repository '%s' doesn't match the hash recorded in the referring lockfile", nonFlake.sourceInfo.resolvedRef);
|
||||||
|
|
||||||
|
state.mkAttrs(v, 8);
|
||||||
|
|
||||||
|
assert(state.store->isValidPath(nonFlake.sourceInfo.storePath));
|
||||||
|
|
||||||
|
mkString(*state.allocAttr(v, state.sOutPath),
|
||||||
|
nonFlake.sourceInfo.storePath, {nonFlake.sourceInfo.storePath});
|
||||||
|
|
||||||
|
emitSourceInfoAttrs(state, nonFlake.sourceInfo, v);
|
||||||
|
}
|
||||||
|
|
||||||
void callFlake(EvalState & state,
|
void callFlake(EvalState & state,
|
||||||
const Flake & flake,
|
const Flake & flake,
|
||||||
const FlakeInputs & inputs,
|
const FlakeInputs & inputs,
|
||||||
|
@ -468,16 +485,15 @@ void callFlake(EvalState & state,
|
||||||
|
|
||||||
for (auto & dep : inputs.nonFlakeInputs) {
|
for (auto & dep : inputs.nonFlakeInputs) {
|
||||||
auto vNonFlake = state.allocAttr(v, dep.first);
|
auto vNonFlake = state.allocAttr(v, dep.first);
|
||||||
state.mkAttrs(*vNonFlake, 8);
|
auto vPrimOp = state.allocValue();
|
||||||
|
static auto primOp = new PrimOp(prim_callNonFlake, 1, state.symbols.create("callNonFlake"));
|
||||||
auto nonFlake = getNonFlake(state, dep.second.ref, dep.first);
|
vPrimOp->type = tPrimOp;
|
||||||
|
vPrimOp->primOp = primOp;
|
||||||
assert(state.store->isValidPath(nonFlake.sourceInfo.storePath));
|
auto vArg = state.allocValue();
|
||||||
|
vArg->type = tNull;
|
||||||
mkString(*state.allocAttr(*vNonFlake, state.sOutPath),
|
// FIXME: leak
|
||||||
nonFlake.sourceInfo.storePath, {nonFlake.sourceInfo.storePath});
|
vArg->attrs = (Bindings *) new NonFlakeInput(dep.second); // evil! also inefficient
|
||||||
|
mkApp(*vNonFlake, *vPrimOp, *vArg);
|
||||||
emitSourceInfoAttrs(state, nonFlake.sourceInfo, *vNonFlake);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mkString(*state.allocAttr(v, state.sDescription), flake.description);
|
mkString(*state.allocAttr(v, state.sDescription), flake.description);
|
||||||
|
|
|
@ -75,7 +75,6 @@ struct Flake
|
||||||
|
|
||||||
struct NonFlake
|
struct NonFlake
|
||||||
{
|
{
|
||||||
FlakeAlias alias;
|
|
||||||
FlakeRef originalRef;
|
FlakeRef originalRef;
|
||||||
SourceInfo sourceInfo;
|
SourceInfo sourceInfo;
|
||||||
NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo)
|
NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo)
|
||||||
|
|
|
@ -122,6 +122,7 @@ static nlohmann::json flakeToJson(const Flake & flake)
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void printNonFlakeInfo(const NonFlake & nonFlake)
|
static void printNonFlakeInfo(const NonFlake & nonFlake)
|
||||||
{
|
{
|
||||||
std::cout << fmt("ID: %s\n", nonFlake.alias);
|
std::cout << fmt("ID: %s\n", nonFlake.alias);
|
||||||
|
@ -136,7 +137,6 @@ static nlohmann::json nonFlakeToJson(const NonFlake & nonFlake)
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// FIXME: merge info CmdFlakeInfo?
|
// FIXME: merge info CmdFlakeInfo?
|
||||||
struct CmdFlakeDeps : FlakeCommand
|
struct CmdFlakeDeps : FlakeCommand
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,7 +83,7 @@ git -C $flake3Dir add flake.nix
|
||||||
git -C $flake3Dir commit -m 'Initial'
|
git -C $flake3Dir commit -m 'Initial'
|
||||||
|
|
||||||
cat > $nonFlakeDir/README.md <<EOF
|
cat > $nonFlakeDir/README.md <<EOF
|
||||||
Not much
|
FNORD
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
git -C $nonFlakeDir add README.md
|
git -C $nonFlakeDir add README.md
|
||||||
|
@ -235,23 +235,42 @@ cat > $flake3Dir/flake.nix <<EOF
|
||||||
outputs = inputs: rec {
|
outputs = inputs: rec {
|
||||||
packages.xyzzy = inputs.flake2.outputs.packages.bar;
|
packages.xyzzy = inputs.flake2.outputs.packages.bar;
|
||||||
packages.sth = inputs.flake1.outputs.packages.foo;
|
packages.sth = inputs.flake1.outputs.packages.foo;
|
||||||
|
packages.fnord =
|
||||||
|
with import ./config.nix;
|
||||||
|
mkDerivation {
|
||||||
|
inherit system;
|
||||||
|
name = "fnord";
|
||||||
|
buildCommand = ''
|
||||||
|
cat \${inputs.nonFlake}/README.md > \$out
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
git -C $flake3Dir add flake.nix
|
cp ./config.nix $flake3Dir
|
||||||
|
|
||||||
|
git -C $flake3Dir add flake.nix config.nix
|
||||||
git -C $flake3Dir commit -m 'Add nonFlakeInputs'
|
git -C $flake3Dir commit -m 'Add nonFlakeInputs'
|
||||||
|
|
||||||
# Check whether `nix build` works with a lockfile which is missing a nonFlakeInputs
|
# Check whether `nix build` works with a lockfile which is missing a
|
||||||
|
# nonFlakeInputs.
|
||||||
nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:sth
|
nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:sth
|
||||||
|
|
||||||
git -C $flake3Dir commit -m 'Update nonFlakeInputs'
|
git -C $flake3Dir commit -m 'Update nonFlakeInputs'
|
||||||
|
|
||||||
|
nix build -o $TEST_ROOT/result --flake-registry $registry flake3:fnord
|
||||||
|
[[ $(cat $TEST_ROOT/result) = FNORD ]]
|
||||||
|
|
||||||
# Check whether flake input fetching is lazy: flake3:sth does not
|
# Check whether flake input fetching is lazy: flake3:sth does not
|
||||||
# depend on flake2, so this shouldn't fail.
|
# depend on flake2, so this shouldn't fail.
|
||||||
rm -rf $TEST_HOME/.cache
|
rm -rf $TEST_HOME/.cache
|
||||||
clearStore
|
clearStore
|
||||||
mv $flake2Dir $flake2Dir.tmp
|
mv $flake2Dir $flake2Dir.tmp
|
||||||
|
mv $nonFlakeDir $nonFlakeDir.tmp
|
||||||
nix build -o $TEST_ROOT/result --flake-registry $registry flake3:sth
|
nix build -o $TEST_ROOT/result --flake-registry $registry flake3:sth
|
||||||
(! nix build -o $TEST_ROOT/result --flake-registry $registry flake3:xyzzy)
|
(! nix build -o $TEST_ROOT/result --flake-registry $registry flake3:xyzzy)
|
||||||
|
(! nix build -o $TEST_ROOT/result --flake-registry $registry flake3:fnord)
|
||||||
mv $flake2Dir.tmp $flake2Dir
|
mv $flake2Dir.tmp $flake2Dir
|
||||||
|
mv $nonFlakeDir.tmp $nonFlakeDir
|
||||||
|
nix build -o $TEST_ROOT/result --flake-registry $registry flake3:xyzzy flake3:fnord
|
||||||
|
|
Loading…
Reference in a new issue