diff --git a/src/command/introspect.rs b/src/command/introspect.rs index b46587a..3c6e3f1 100644 --- a/src/command/introspect.rs +++ b/src/command/introspect.rs @@ -25,6 +25,10 @@ For example, to retrieve the configuration of one node, you may write something .value_name("EXPRESSION") .help("The Nix expression") .takes_value(true)) + .arg(Arg::with_name("instantiate") + .long("instantiate") + .help("Actually instantiate the expression") + .takes_value(false)) } pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { @@ -42,6 +46,12 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { format!("import {}", path.canonicalize().expect("Could not generate absolute path to expression file.").to_str().unwrap()) }; - let result = hive.introspect(expression).await.unwrap(); - println!("{}", result); + let instantiate = local_args.is_present("instantiate"); + let result = hive.introspect(expression, instantiate).await.unwrap(); + + if instantiate { + print!("{}", result); + } else { + println!("{}", result); + } } diff --git a/src/nix/hive.rs b/src/nix/hive.rs index d4d3aed..2473d98 100644 --- a/src/nix/hive.rs +++ b/src/nix/hive.rs @@ -185,10 +185,16 @@ impl Hive { } /// Evaluates an expression using values from the configuration - pub async fn introspect(&self, expression: String) -> NixResult { - let expression = format!("toJSON (hive.introspect ({}))", expression); - self.nix_instantiate(&expression).eval_with_builders().await? - .capture_json().await + pub async fn introspect(&self, expression: String, instantiate: bool) -> NixResult { + if instantiate { + let expression = format!("hive.introspect ({})", expression); + self.nix_instantiate(&expression).instantiate_with_builders().await? + .capture_output().await + } else { + let expression = format!("toJSON (hive.introspect ({}))", expression); + self.nix_instantiate(&expression).eval_with_builders().await? + .capture_json().await + } } /// Retrieve machinesFile setting for the hive.