From 34fc4637ebbb906d38647ca8a12fdb80cd2baf18 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 18 Oct 2023 11:39:36 +0100 Subject: refactor(tvix/nix-compat): rename NixHashWithMode -> CAHash 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 --- tvix/cli/src/derivation.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tvix/cli/src/derivation.rs') diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs index 76cc3f60f77e..15df6ed76102 100644 --- a/tvix/cli/src/derivation.rs +++ b/tvix/cli/src/derivation.rs @@ -115,7 +115,7 @@ fn populate_output_configuration( ) -> Result<(), ErrorKind> { // We only do something when `digest` and `algo` are `Some(_)``, and // there's an `out` output. - if let (Some(hash), Some(algo), hash_mode) = (hash, hash_algo, hash_mode) { + if let (Some(nixhash_str), Some(algo), hash_mode) = (hash, hash_algo, hash_mode) { match drv.outputs.get_mut("out") { None => return Err(Error::ConflictingOutputTypes.into()), Some(out) => { @@ -126,12 +126,12 @@ fn populate_output_configuration( Some(algo.as_ref()) }; - let output_hash = nixhash::from_str(&hash, a).map_err(Error::InvalidOutputHash)?; + let hash = nixhash::from_str(&nixhash_str, a).map_err(Error::InvalidOutputHash)?; // construct the NixHashWithMode. - out.hash_with_mode = match hash_mode.as_deref() { - None | Some("flat") => Some(nixhash::NixHashWithMode::Flat(output_hash)), - Some("recursive") => Some(nixhash::NixHashWithMode::Recursive(output_hash)), + out.ca_hash = match hash_mode.as_deref() { + None | Some("flat") => Some(nixhash::CAHash::Flat(hash)), + Some("recursive") => Some(nixhash::CAHash::Nar(hash)), Some(other) => { return Err(Error::InvalidOutputHashMode(other.to_string()).into()) } -- cgit 1.4.1