diff options
-rw-r--r-- | tvix/cli/src/.skip-subtree | 1 | ||||
-rw-r--r-- | tvix/cli/src/derivation.nix | 36 | ||||
-rw-r--r-- | tvix/cli/src/main.rs | 4 |
3 files changed, 41 insertions, 0 deletions
diff --git a/tvix/cli/src/.skip-subtree b/tvix/cli/src/.skip-subtree new file mode 100644 index 000000000000..a16a2afe1f1e --- /dev/null +++ b/tvix/cli/src/.skip-subtree @@ -0,0 +1 @@ +Because of the derivation.nix file ... diff --git a/tvix/cli/src/derivation.nix b/tvix/cli/src/derivation.nix new file mode 100644 index 000000000000..9355cc3a96f0 --- /dev/null +++ b/tvix/cli/src/derivation.nix @@ -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 diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index 552b8e941c55..447bb13c714e 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -60,6 +60,10 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b eval.builtins .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 result = { let mut compiler_observer = |