refactor(tvix/nix-compat): move build_store_path out of derivation
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
This commit is contained in:
parent
4ab180b1eb
commit
5f2c2e79e1
10 changed files with 176 additions and 155 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::derivation::output::Output;
|
||||
use crate::derivation::Derivation;
|
||||
use crate::nixhash::NixHash;
|
||||
use crate::store_path::StorePath;
|
||||
use crate::store_path::{build_store_path_from_references, StorePath};
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
|
@ -313,40 +313,3 @@ fn output_path_construction() {
|
|||
.expect("must succeed")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_with_zero_references() {
|
||||
// This hash should match `builtins.toFile`, e.g.:
|
||||
//
|
||||
// nix-repl> builtins.toFile "foo" "bar"
|
||||
// "/nix/store/vxjiwkjkn7x4079qvh1jkl5pn05j2aw0-foo"
|
||||
|
||||
let store_path = crate::derivation::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
.expect("path_with_references() should succeed");
|
||||
|
||||
assert_eq!(
|
||||
store_path.to_absolute_path().as_str(),
|
||||
"/nix/store/vxjiwkjkn7x4079qvh1jkl5pn05j2aw0-foo"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_with_non_zero_references() {
|
||||
// This hash should match:
|
||||
//
|
||||
// nix-repl> builtins.toFile "baz" "${builtins.toFile "foo" "bar"}"
|
||||
// "/nix/store/5xd714cbfnkz02h2vbsj4fm03x3f15nf-baz"
|
||||
|
||||
let inner = crate::derivation::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
.expect("path_with_references() should succeed");
|
||||
let inner_path = inner.to_absolute_path();
|
||||
|
||||
let outer =
|
||||
crate::derivation::path_with_references("baz", &inner_path, vec![inner_path.as_str()])
|
||||
.expect("path_with_references() should succeed");
|
||||
|
||||
assert_eq!(
|
||||
outer.to_absolute_path().as_str(),
|
||||
"/nix/store/5xd714cbfnkz02h2vbsj4fm03x3f15nf-baz"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue