about summary refs log tree commit diff
path: root/tvix/nix-compat/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-31T16·43+0300
committerclbot <clbot@tvl.fyi>2023-02-01T10·01+0000
commit759f9dbf39635cd3ec630bfccdb88bb8af8b7805 (patch)
tree4a1fb0f676c43b5985a5f366d55d3b676d402ab2 /tvix/nix-compat/src/lib.rs
parent3caa4c4aa492dd1ee51a111836365790c63bdee1 (diff)
feat(tvix/cli): implement builtins.placeholder r/5799
This doesn't require any other corresponding handling *yet*, as the
actual replacements happen in the builder logic (which we delegate to
cppnix at the moment).

Change-Id: I034147c933f05ae427c7a8794647132d108d0ede
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7972
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/nix-compat/src/lib.rs')
-rw-r--r--tvix/nix-compat/src/lib.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/lib.rs b/tvix/nix-compat/src/lib.rs
index 60775ad90e05..94fd88549af4 100644
--- a/tvix/nix-compat/src/lib.rs
+++ b/tvix/nix-compat/src/lib.rs
@@ -1,4 +1,22 @@
+use sha2::{Digest, Sha256};
+
 pub mod derivation;
 pub mod nar;
 pub mod nixbase32;
 pub mod store_path;
+
+/// 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))
+}