From 80426aa814853ddc14726523b1601e4e348a77ce Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Tue, 16 Aug 2022 20:15:43 -0600 Subject: [PATCH] cli: Support passing --impure --- src/cli.rs | 6 ++++++ src/nix/hive/mod.rs | 9 +++++++++ src/nix/mod.rs | 4 ++++ src/util.rs | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 92c1c4a..b97c96e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -124,6 +124,12 @@ pub fn build_cli(include_internal: bool) -> ClapCommand<'static> { .long_help("Passes --show-trace to Nix commands") .global(true) .takes_value(false)) + .arg(Arg::new("impure") + .long("impure") + .help("Allow impure expressions") + .long_help("Passes --impure to Nix commands") + .global(true) + .takes_value(false)) .arg(Arg::new("color") .long("color") .help("When to colorize the output") diff --git a/src/nix/hive/mod.rs b/src/nix/hive/mod.rs index b8141b2..49123cb 100644 --- a/src/nix/hive/mod.rs +++ b/src/nix/hive/mod.rs @@ -49,6 +49,9 @@ pub struct Hive { /// Whether to pass --show-trace in Nix commands. show_trace: bool, + /// Whether to pass --impure in Nix commands. + impure: bool, + meta_config: OnceCell, } @@ -100,6 +103,7 @@ impl Hive { context_dir, assets, show_trace: false, + impure: false, meta_config: OnceCell::new(), }) } @@ -123,11 +127,16 @@ impl Hive { self.show_trace = value; } + pub fn set_impure(&mut self, impure: bool) { + self.impure = impure; + } + /// Returns Nix options to set for this Hive. pub fn nix_options(&self) -> NixOptions { let mut options = NixOptions::default(); options.set_show_trace(self.show_trace); options.set_pure_eval(self.path.is_flake()); + options.set_impure(self.impure); options } diff --git a/src/nix/mod.rs b/src/nix/mod.rs index 284ab87..4bf2d40 100644 --- a/src/nix/mod.rs +++ b/src/nix/mod.rs @@ -197,6 +197,10 @@ impl NixOptions { self.pure_eval = pure_eval; } + pub fn set_impure(&mut self, impure: bool) { + self.impure = impure; + } + pub fn set_builders(&mut self, builders: Option) { self.builders = builders; } diff --git a/src/util.rs b/src/util.rs index ff40436..f2badc5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -250,6 +250,10 @@ pub async fn hive_from_args(args: &ArgMatches) -> ColmenaResult { hive.set_show_trace(true); } + if args.is_present("impure") { + hive.set_impure(true); + } + return Ok(hive); } @@ -273,6 +277,10 @@ pub async fn hive_from_args(args: &ArgMatches) -> ColmenaResult { hive.set_show_trace(true); } + if args.is_present("impure") { + hive.set_impure(true); + } + Ok(hive) }