about summary refs log tree commit diff
path: root/tvix/cli
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-30T12·01+0200
committerclbot <clbot@tvl.fyi>2023-03-30T14·03+0000
commit5f2c2e79e1778cda877d6122dd24be08740c8720 (patch)
treeb87dba0063a193a39c1bf57a2b1e3513039e144c /tvix/cli
parent4ab180b1ebf411d7d7ebd98ae17c25945b17e2c2 (diff)
refactor(tvix/nix-compat): move build_store_path out of derivation r/6060
This doesn't have anything to do with ATerms, we just happen to be using
the aterm representation of a Derivation as contents.

Moving this into store_path/utils.rs makes these things much cleaner -
Have a build_store_path_from_references function, and a
build_store_path_from_fingerprint helper function that makes use of it.

build_store_path_from_references is invoked from the derivation module
which can be used to calculate the derivation path.

In the derivation module, we also invoke
build_store_path_from_fingerprint during the output path calculation.

Change-Id: Ia8d61a5e8e5d3f396f93593676ed3f5d1a3f1d66
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8367
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/cli')
-rw-r--r--tvix/cli/src/derivation.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs
index 5a04c2a11bb2..23c49d3d0974 100644
--- a/tvix/cli/src/derivation.rs
+++ b/tvix/cli/src/derivation.rs
@@ -1,6 +1,6 @@
 //! Implements `builtins.derivation`, the core of what makes Nix build packages.
 use nix_compat::derivation::Derivation;
-use nix_compat::{hash_placeholder, nixhash};
+use nix_compat::nixhash;
 use std::cell::RefCell;
 use std::collections::{btree_map, BTreeSet};
 use std::rc::Rc;
@@ -202,6 +202,7 @@ async fn strong_coerce_to_string(co: &GenCo, val: Value) -> Result<String, Error
 #[builtins(state = "Rc<RefCell<KnownPaths>>")]
 mod derivation_builtins {
     use super::*;
+    use nix_compat::store_path::hash_placeholder;
     use tvix_eval::generators::Gen;
 
     #[builtin("placeholder")]
@@ -411,10 +412,16 @@ mod derivation_builtins {
 
         // TODO: fail on derivation references (only "plain" is allowed here)
 
-        let path =
-            nix_compat::derivation::path_with_references(name.as_str(), content.as_str(), refs)
-                .map_err(Error::InvalidDerivation)?
-                .to_absolute_path();
+        let path = nix_compat::store_path::build_store_path_from_references(
+            name.as_str(),
+            content.as_str(),
+            refs,
+        )
+        .map_err(|_e| {
+            nix_compat::derivation::DerivationError::InvalidOutputName(name.as_str().to_string())
+        })
+        .map_err(Error::InvalidDerivation)?
+        .to_absolute_path();
 
         state.borrow_mut().plain(&path);
 
@@ -428,7 +435,7 @@ pub use derivation_builtins::builtins as derivation_builtins;
 
 #[cfg(test)]
 mod tests {
-    use super::*;
+    use nix_compat::store_path::hash_placeholder;
     use tvix_eval::observer::NoOpObserver;
 
     // TODO: These tests are commented out because we do not have