about summary refs log tree commit diff
path: root/tvix/nix-compat/src/lib.rs
blob: ec9ddd1ffa7be8caec76800873fdd0efefac4ae3 (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
use sha2::{Digest, Sha256};

pub mod derivation;
pub mod nar;
pub mod nixbase32;
pub mod nixhash;
mod nixhash_algos;
mod nixhash_with_mode;
pub mod store_path;
mod texthash;

/// Nix placeholders (i.e. values returned by `builtins.placeholder`)
/// are used to populate outputs with paths that must be
/// string-replaced with the actual placeholders later, at runtime.
///
/// The actual placeholder is basically just a SHA256 hash encoded in
/// cppnix format.
pub fn hash_placeholder(name: &str) -> String {
    let digest = {
        let mut hasher = Sha256::new();
        hasher.update(format!("nix-output:{}", name));
        hasher.finalize()
    };

    format!("/{}", nixbase32::encode(&digest))
}