diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-18T10·39+0100 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-10-23T14·57+0000 |
commit | 34fc4637ebbb906d38647ca8a12fdb80cd2baf18 (patch) | |
tree | f735c40fbab6bdbd8027f9e1f75106c070a58807 /tvix/nix-compat/src/derivation/write.rs | |
parent | 833957b3749d4d31ccb7aeb96a8fb25ebb931e67 (diff) |
refactor(tvix/nix-compat): rename NixHashWithMode -> CAHash r/6871
This specific struct is only used to represent content-addressed paths (in case a Derivation has a fixed-output hash, for example). Rename `Output`'s `hash_with_mode` to `ca_hash`. We now also include `CAHash::Text`, and update the `validate` function of the `Output` struct to reject text hashes there. This allows cleaning up the various output path calculation functions inside nix-compat/src/store_path/utils.rs, as they can now match on the type. `make_type` is renamed to `make_references_string`, `build_regular_ca_path` is renamed to `build_ca_path`, and `build_text_path` has a disclaimer added, because you might not actually want to use it. Change-Id: I674d065f2ed5c804012ddfed56e161ac49d23931 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9814 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/nix-compat/src/derivation/write.rs')
-rw-r--r-- | tvix/nix-compat/src/derivation/write.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index 7ebbbffa4b55..087227c99998 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -4,7 +4,7 @@ //! [ATerm]: http://program-transformation.org/Tools/ATermFormat.html use crate::aterm::escape_bytes; -use crate::derivation::output::Output; +use crate::derivation::{ca_kind_prefix, output::Output}; use bstr::BString; use std::{ collections::{BTreeMap, BTreeSet}, @@ -79,14 +79,10 @@ pub fn write_outputs( let mut elements: Vec<&str> = vec![output_name, &output.path]; - let (mode_and_algo, digest) = match &output.hash_with_mode { - Some(crate::nixhash::NixHashWithMode::Flat(h)) => ( - h.algo().to_string(), - data_encoding::HEXLOWER.encode(h.digest_as_bytes()), - ), - Some(crate::nixhash::NixHashWithMode::Recursive(h)) => ( - format!("r:{}", h.algo()), - data_encoding::HEXLOWER.encode(h.digest_as_bytes()), + let (mode_and_algo, digest) = match &output.ca_hash { + Some(ca_hash) => ( + format!("{}{}", ca_kind_prefix(ca_hash), ca_hash.digest().algo()), + data_encoding::HEXLOWER.encode(ca_hash.digest().digest_as_bytes()), ), None => ("".to_string(), "".to_string()), }; |