about summary refs log tree commit diff
path: root/tvix/derivation/src/output.rs
blob: cd77c00f2f41a81a842a6bb5b58f3b1491034b1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use serde::{Deserialize, Serialize};
use tvix_store::store_path::{ParseStorePathError, StorePath};

use crate::ValidateDerivationError;

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct Output {
    pub path: String,

    #[serde(flatten)]
    pub hash: Option<Hash>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Hash {
    #[serde(rename = "hash")]
    pub digest: String,
    #[serde(rename = "hashAlgo")]
    pub algo: String,
}

impl Output {
    pub fn is_fixed(&self) -> bool {
        self.hash.is_some()
    }

    pub fn validate(&self) -> Result<(), ParseStorePathError> {
        if let Err(e) = StorePath::from_absolute_path(&self.path) {
            return Err(e);
        }
        Ok(())
    }
}