From 6cc690c8b64b010fb435873be296e83ae456a044 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sat, 19 Oct 2024 03:30:25 +0530 Subject: [PATCH 1/5] Use `--quiet --quiet` by default for `om ci` and `om show` --- crates/nix_rs/CHANGELOG.md | 1 + crates/nix_rs/src/command.rs | 12 ++++++++++++ crates/omnix-cli/src/command/ci.rs | 5 ++++- crates/omnix-cli/src/command/show.rs | 6 ++++-- doc/src/history.md | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/nix_rs/CHANGELOG.md b/crates/nix_rs/CHANGELOG.md index 741f8e3f..fa8ee4fe 100644 --- a/crates/nix_rs/CHANGELOG.md +++ b/crates/nix_rs/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Add `NixCmd::extra_args` - **`eval::nix_eval`** - Display evaluation progress - Decrease logging verbosity diff --git a/crates/nix_rs/src/command.rs b/crates/nix_rs/src/command.rs index 51b79f59..0b50e7b8 100644 --- a/crates/nix_rs/src/command.rs +++ b/crates/nix_rs/src/command.rs @@ -40,6 +40,10 @@ pub struct NixCmd { #[cfg_attr(feature = "clap", arg(long))] pub extra_access_tokens: Vec, + /// Arguments to pass verbatim to the Nix command + #[cfg_attr(feature = "clap", arg(long))] + pub extra_args: Vec, + /// Consider all previously downloaded files out-of-date. #[cfg_attr(feature = "clap", arg(long))] pub refresh: bool, @@ -57,6 +61,7 @@ impl Default for NixCmd { Self { extra_experimental_features: vec![], extra_access_tokens: vec![], + extra_args: vec![], refresh: false, command: None, } @@ -119,6 +124,13 @@ impl NixCmd { cmd } + /// Suppress logs related to `override-input` usage. + pub fn mute_override_input_logs(&mut self) { + // Yes, this requires *double* use of `--quiet`. Also, `-qq` won't work until https://github.com/NixOS/nix/pull/11652 + self.extra_args + .extend(vec!["--quiet".to_string(), "--quiet".to_string()]); + } + /// Run nix with given args, interpreting stdout as JSON, parsing into `T` pub async fn run_with_args_expecting_json(&self, args: &[&str]) -> Result where diff --git a/crates/omnix-cli/src/command/ci.rs b/crates/omnix-cli/src/command/ci.rs index 9299e4ca..6aedaab2 100644 --- a/crates/omnix-cli/src/command/ci.rs +++ b/crates/omnix-cli/src/command/ci.rs @@ -17,8 +17,11 @@ pub struct CICommand { impl CICommand { /// Run this sub-command pub async fn run(&self, verbosity: Verbosity) -> anyhow::Result<()> { + let mut nixcmd = self.nixcmd.clone(); + nixcmd.mute_override_input_logs(); + self.command() - .run(&self.nixcmd, verbosity.log_level() > Some(Level::Info)) + .run(&nixcmd, verbosity.log_level() > Some(Level::Info)) .await?; Ok(()) } diff --git a/crates/omnix-cli/src/command/show.rs b/crates/omnix-cli/src/command/show.rs index 8fa30ef0..563f5855 100644 --- a/crates/omnix-cli/src/command/show.rs +++ b/crates/omnix-cli/src/command/show.rs @@ -90,10 +90,12 @@ impl Row { impl ShowCommand { pub async fn run(&self) -> anyhow::Result<()> { - let nix_cmd = NixCmd::get().await; + let mut nix_cmd = NixCmd::get().await.clone(); + nix_cmd.mute_override_input_logs(); + let nix_config = NixConfig::get().await.as_ref()?; let system = &nix_config.system.value; - let flake = Flake::from_nix(nix_cmd, nix_config, self.flake_url.clone()) + let flake = Flake::from_nix(&nix_cmd, nix_config, self.flake_url.clone()) .await .with_context(|| "Unable to fetch flake")?; diff --git a/doc/src/history.md b/doc/src/history.md index 36e47fdf..7bbecc6c 100644 --- a/doc/src/history.md +++ b/doc/src/history.md @@ -2,6 +2,8 @@ ## Unreleased +- `om ci`: Suppress logs from `--override-input` usage + ### Enhancements - `om hack`: New command From 16cdd535bb7612780178adea0e4762b2171d3789 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sat, 19 Oct 2024 03:37:45 +0530 Subject: [PATCH 2/5] more specific doc --- crates/nix_rs/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nix_rs/src/command.rs b/crates/nix_rs/src/command.rs index 0b50e7b8..fca656ad 100644 --- a/crates/nix_rs/src/command.rs +++ b/crates/nix_rs/src/command.rs @@ -124,7 +124,7 @@ impl NixCmd { cmd } - /// Suppress logs related to `override-input` usage. + /// Suppress logs related to `override-input` usage by reducing `nix` command's verbosity pub fn mute_override_input_logs(&mut self) { // Yes, this requires *double* use of `--quiet`. Also, `-qq` won't work until https://github.com/NixOS/nix/pull/11652 self.extra_args From 6468df0bfcd6f60c32a376a4c5f19a9e3db46edb Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sat, 19 Oct 2024 03:38:03 +0530 Subject: [PATCH 3/5] missing `show` in `history.md` --- doc/src/history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/history.md b/doc/src/history.md index 7bbecc6c..b380eb37 100644 --- a/doc/src/history.md +++ b/doc/src/history.md @@ -2,7 +2,7 @@ ## Unreleased -- `om ci`: Suppress logs from `--override-input` usage +- `om {ci,show}`: Suppress logs from `--override-input` usage ### Enhancements From 02eca60ea137f4ebd8e96714561c67ade9794b8f Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sat, 19 Oct 2024 04:00:23 +0530 Subject: [PATCH 4/5] remove `--quiet --quiet` from eval.rs --- crates/nix_rs/src/flake/eval.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/nix_rs/src/flake/eval.rs b/crates/nix_rs/src/flake/eval.rs index 49e61044..76b6a940 100644 --- a/crates/nix_rs/src/flake/eval.rs +++ b/crates/nix_rs/src/flake/eval.rs @@ -20,8 +20,6 @@ where cmd.args(["eval", "--json"]); opts.use_in_command(cmd); cmd.arg(url.to_string()); - // Avoid Nix from dumping logs related to `--override-input` use. Yes, this requires *double* use of `--quiet`. Also, `-qq` won't work until https://github.com/NixOS/nix/pull/11652 - cmd.args(["--quiet", "--quiet"]); }) .await?; let v = serde_json::from_slice::(&stdout)?; From 6d34e29502f10ccdf719c3eedb25f255277ca41f Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sat, 19 Oct 2024 04:00:39 +0530 Subject: [PATCH 5/5] fix extra_args no allow_hyphens --- crates/nix_rs/src/command.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/nix_rs/src/command.rs b/crates/nix_rs/src/command.rs index fca656ad..3b26978b 100644 --- a/crates/nix_rs/src/command.rs +++ b/crates/nix_rs/src/command.rs @@ -41,7 +41,7 @@ pub struct NixCmd { pub extra_access_tokens: Vec, /// Arguments to pass verbatim to the Nix command - #[cfg_attr(feature = "clap", arg(long))] + #[cfg_attr(feature = "clap", arg(last = true))] pub extra_args: Vec, /// Consider all previously downloaded files out-of-date. @@ -219,6 +219,9 @@ impl NixCmd { args.push("--extra-access-tokens".to_string()); args.push(self.extra_access_tokens.join(" ")); } + + args.extend(self.extra_args.clone()); + if self.refresh { args.push("--refresh".to_string()); }