From a72a1044c29ce41973e0cf81bcee04923f21995f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 3 Nov 2023 14:03:19 +0200 Subject: refactor(tvix/glue): move nix_path handling to helper in tvix-glue Change-Id: I2327560c4cf0d3f90e253e3c2f47cb29c762461e Reviewed-on: https://cl.tvl.fyi/c/depot/+/9910 Reviewed-by: raitobezarius Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/cli/src/main.rs | 11 ++--------- tvix/glue/src/lib.rs | 10 ++++++++++ tvix/glue/src/tvix_io.rs | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'tvix') diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index 1ffa2be256ac..66705e130730 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -2,8 +2,8 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::Arc; use std::{fs, path::PathBuf}; -use tvix_glue::add_derivation_builtins; use tvix_glue::known_paths::KnownPaths; +use tvix_glue::{add_derivation_builtins, configure_nix_path}; use clap::Parser; use rustyline::{error::ReadlineError, Editor}; @@ -75,6 +75,7 @@ fn interpret(code: &str, path: Option, args: &Args, explain: bool) -> b let known_paths: Rc> = Default::default(); add_derivation_builtins(&mut eval, known_paths.clone()); + configure_nix_path(&mut eval, &args.nix_search_path); let tokio_runtime = tokio::runtime::Runtime::new().unwrap(); eval.io_handle = Box::new(tvix_glue::tvix_io::TvixIO::new( @@ -87,14 +88,6 @@ fn interpret(code: &str, path: Option, args: &Args, explain: bool) -> b ), )); - // bundle fetchurl.nix (used in nixpkgs) by resolving to - // `/__corepkgs__`, which has special handling in [`nix_compat`]. - eval.nix_path = args - .nix_search_path - .as_ref() - .map(|p| format!("nix=/__corepkgs__:{}", p)) - .or_else(|| Some("nix=/__corepkgs__".to_string())); - let source_map = eval.source_map(); let result = { let mut compiler_observer = diff --git a/tvix/glue/src/lib.rs b/tvix/glue/src/lib.rs index acb81d31445f..760e730217ee 100644 --- a/tvix/glue/src/lib.rs +++ b/tvix/glue/src/lib.rs @@ -26,3 +26,13 @@ pub fn add_derivation_builtins( eval.src_builtins .push(("derivation", include_str!("derivation.nix"))); } + +/// Tell the Evaluator to resolve to the path `/__corepkgs__`, +/// which has special handling in [tvix_io::TvixIO]. +/// This is used in nixpkgs to import `fetchurl.nix` from ``. +pub fn configure_nix_path(eval: &mut tvix_eval::Evaluation, nix_search_path: &Option) { + eval.nix_path = nix_search_path + .as_ref() + .map(|p| format!("nix=/__corepkgs__:{}", p)) + .or_else(|| Some("nix=/__corepkgs__".to_string())); +} diff --git a/tvix/glue/src/tvix_io.rs b/tvix/glue/src/tvix_io.rs index caadbeb5e663..09e1417a2157 100644 --- a/tvix/glue/src/tvix_io.rs +++ b/tvix/glue/src/tvix_io.rs @@ -59,8 +59,8 @@ impl EvalIO for TvixIO { fn read_to_string(&self, path: &Path) -> Result { // Bundled version of corepkgs/fetchurl.nix. The counterpart - // of this happens in `main`, where the `nix_path` of the - // evaluation has `nix=/__corepkgs__` added to it. + // of this happens in [crate::configure_nix_path], where the `nix_path` + // of the evaluation has `nix=/__corepkgs__` added to it. // // This workaround is similar to what cppnix does for passing // the path through. -- cgit 1.4.1