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:
Florian Klink 2023-03-30 14:01:38 +02:00 committed by clbot
parent 4ab180b1eb
commit 5f2c2e79e1
10 changed files with 176 additions and 155 deletions

View file

@ -1,4 +1,4 @@
use crate::{nixbase32::Nixbase32DecodeError, store_path::ParseStorePathError};
use crate::{nixbase32::Nixbase32DecodeError, store_path};
use thiserror::Error;
/// Errors that can occur during the validation of Derivation structs.
@ -17,7 +17,7 @@ pub enum DerivationError {
InvalidOutput(String, OutputError),
// input derivation
#[error("unable to parse input derivation path {0}: {1}")]
InvalidInputDerivationPath(String, ParseStorePathError),
InvalidInputDerivationPath(String, store_path::Error),
#[error("input derivation {0} doesn't end with .drv")]
InvalidInputDerivationPrefix(String),
#[error("input derivation {0} output names are empty")]
@ -27,7 +27,7 @@ pub enum DerivationError {
// input sources
#[error("unable to parse input sources path {0}: {1}")]
InvalidInputSourcesPath(String, ParseStorePathError),
InvalidInputSourcesPath(String, store_path::Error),
// platform
#[error("invalid platform field: {0}")]
@ -46,8 +46,8 @@ pub enum DerivationError {
// [crate::derivation::Output] of a [crate::derivation::Derviation].
#[derive(Debug, Error, PartialEq)]
pub enum OutputError {
#[error("Invalid ouput path {0}: {1}")]
InvalidOutputPath(String, ParseStorePathError),
#[error("Invalid output path {0}: {1}")]
InvalidOutputPath(String, store_path::Error),
#[error("Invalid hash encoding: {0}")]
InvalidHashEncoding(String, Nixbase32DecodeError),
#[error("Invalid hash algo: {0}")]