about summary refs log tree commit diff
path: root/tvix/cli/src/nix_compat.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-03-04T00·43+0300
committertazjin <tazjin@tvl.su>2023-03-13T20·30+0000
commita59e264457f030fedf63c6d2925c896d6790d390 (patch)
treec5036a4f33ff1afde2b0c1fdf412823a66c93b80 /tvix/cli/src/nix_compat.rs
parentc7007767336b5c7cc29b1fd10cd62132c99941e6 (diff)
feat(tvix/cli): bundle corepkgs/fetchurl.nix with tvix-cli r/5981
This file which ships with C++ Nix is required for evaluating nixpkgs.
Like C++ Nix, we now inject a pseudo path in EvalIO from which this
will resolve as <nix/fetchurl.nix>

Change-Id: Ic948c476a2cfc6381d5655d308bc2d5fa25b7123
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8213
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/cli/src/nix_compat.rs')
-rw-r--r--tvix/cli/src/nix_compat.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/cli/src/nix_compat.rs b/tvix/cli/src/nix_compat.rs
index 2bee43882f09..cc9e0db5fd80 100644
--- a/tvix/cli/src/nix_compat.rs
+++ b/tvix/cli/src/nix_compat.rs
@@ -59,10 +59,24 @@ impl EvalIO for NixCompatIO {
 
     // Pass the rest of the functions through to `Self::underlying`
     fn path_exists(&self, path: PathBuf) -> Result<bool, ErrorKind> {
+        if path.starts_with("/__corepkgs__") {
+            return Ok(true);
+        }
+
         self.underlying.path_exists(path)
     }
 
     fn read_to_string(&self, path: PathBuf) -> Result<String, ErrorKind> {
+        // Bundled version of corepkgs/fetchurl.nix. This workaround
+        // is similar to what cppnix does for passing the path
+        // through.
+        //
+        // TODO: this comparison is bad and allocates, we should use
+        // the sane path library.
+        if path.starts_with("/__corepkgs__/fetchurl.nix") {
+            return Ok(include_str!("fetchurl.nix").to_string());
+        }
+
         self.underlying.read_to_string(path)
     }