feat(tvix/cli): implement builtins.derivation
This uses the actual upstream Nix code for `builtins.derivation` (which is not a primop in C++ Nix) to implement `builtins.derivation` as a wrapper around `builtins.derivationStrict`. We're doing it this way to ensure that our thunking logic is correct. An initial Rust-native rewrite (see e.g. cl/7363) is pretty difficult to debug while there are still other issues to root out, but eventually we might want to turn this into native code. Change-Id: I5845e18073e103b8670e40648bd7fd9b511058e0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7902 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
8a9aa018dc
commit
de10a924f2
3 changed files with 41 additions and 0 deletions
1
tvix/cli/src/.skip-subtree
Normal file
1
tvix/cli/src/.skip-subtree
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Because of the derivation.nix file ...
|
36
tvix/cli/src/derivation.nix
Normal file
36
tvix/cli/src/derivation.nix
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# LGPL-2.1-or-later
|
||||||
|
#
|
||||||
|
# taken from: https://github.com/NixOS/nix/blob/master/src/libexpr/primops/derivation.nix
|
||||||
|
#
|
||||||
|
# TODO: rewrite in native Rust code
|
||||||
|
|
||||||
|
/* This is the implementation of the ‘derivation’ builtin function.
|
||||||
|
It's actually a wrapper around the ‘derivationStrict’ primop. */
|
||||||
|
|
||||||
|
drvAttrs @ { outputs ? [ "out" ], ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
strict = derivationStrict drvAttrs;
|
||||||
|
|
||||||
|
commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) //
|
||||||
|
{
|
||||||
|
all = map (x: x.value) outputsList;
|
||||||
|
inherit drvAttrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
outputToAttrListElement = outputName:
|
||||||
|
{
|
||||||
|
name = outputName;
|
||||||
|
value = commonAttrs // {
|
||||||
|
outPath = builtins.getAttr outputName strict;
|
||||||
|
drvPath = strict.drvPath;
|
||||||
|
type = "derivation";
|
||||||
|
inherit outputName;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputsList = map outputToAttrListElement outputs;
|
||||||
|
|
||||||
|
in
|
||||||
|
(builtins.head outputsList).value
|
|
@ -60,6 +60,10 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
|
||||||
eval.builtins
|
eval.builtins
|
||||||
.extend(derivation::derivation_builtins(known_paths));
|
.extend(derivation::derivation_builtins(known_paths));
|
||||||
|
|
||||||
|
// Add the actual `builtins.derivation` from compiled Nix code
|
||||||
|
eval.src_builtins
|
||||||
|
.push(("derivation", include_str!("derivation.nix")));
|
||||||
|
|
||||||
let source_map = eval.source_map();
|
let source_map = eval.source_map();
|
||||||
let result = {
|
let result = {
|
||||||
let mut compiler_observer =
|
let mut compiler_observer =
|
||||||
|
|
Loading…
Reference in a new issue