Shorter syntax for referencing flake outputs

Fixes #2819.
This commit is contained in:
Eelco Dolstra 2019-06-04 22:35:43 +02:00
parent ce225615c3
commit 1b05792988
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 19 additions and 9 deletions

View file

@ -468,10 +468,12 @@ static void prim_callNonFlake(EvalState & state, const Pos & pos, Value * * args
void callFlake(EvalState & state,
const Flake & flake,
const FlakeInputs & inputs,
Value & v)
Value & vRes)
{
// Construct the resulting attrset '{description, outputs,
// ...}'. This attrset is passed lazily as an argument to 'outputs'.
// Construct the resulting attrset '{outputs, ...}'. This attrset
// is passed lazily as an argument to the 'outputs' function.
auto & v = *state.allocValue();
state.mkAttrs(v,
inputs.flakeInputs.size() +
@ -513,6 +515,14 @@ void callFlake(EvalState & state,
v.attrs->push_back(Attr(state.symbols.create("self"), &v));
v.attrs->sort();
/* For convenience, put the outputs directly in the result, so you
can refer to an output of an input as 'inputs.foo.bar' rather
than 'inputs.foo.outputs.bar'. */
auto v2 = *state.allocValue();
state.eval(state.parseExprFromString("res: res.outputs // res", "/"), v2);
state.callFunction(v2, v, vRes, noPos);
}
void callFlake(EvalState & state,

View file

@ -55,7 +55,7 @@ cat > $flake2Dir/flake.nix <<EOF
description = "Fnord";
outputs = inputs: rec {
packages.bar = inputs.flake1.outputs.packages.foo;
packages.bar = inputs.flake1.packages.foo;
};
}
EOF
@ -74,7 +74,7 @@ cat > $flake3Dir/flake.nix <<EOF
description = "Fnord";
outputs = inputs: rec {
packages.xyzzy = inputs.flake2.outputs.packages.bar;
packages.xyzzy = inputs.flake2.packages.bar;
};
}
EOF
@ -176,8 +176,8 @@ cat > $flake3Dir/flake.nix <<EOF
description = "Fnord";
outputs = inputs: rec {
packages.xyzzy = inputs.flake2.outputs.packages.bar;
packages.sth = inputs.flake1.outputs.packages.foo;
packages.xyzzy = inputs.flake2.packages.bar;
packages.sth = inputs.flake1.packages.foo;
};
}
EOF
@ -233,8 +233,8 @@ cat > $flake3Dir/flake.nix <<EOF
description = "Fnord";
outputs = inputs: rec {
packages.xyzzy = inputs.flake2.outputs.packages.bar;
packages.sth = inputs.flake1.outputs.packages.foo;
packages.xyzzy = inputs.flake2.packages.bar;
packages.sth = inputs.flake1.packages.foo;
packages.fnord =
with import ./config.nix;
mkDerivation {