Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --quiet --quiet by default for om ci and om show #324

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/nix_rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add `NixCmd::extra_args`
- **`eval::nix_eval`**
- Display evaluation progress
- Decrease logging verbosity
Expand Down
15 changes: 15 additions & 0 deletions crates/nix_rs/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct NixCmd {
#[cfg_attr(feature = "clap", arg(long))]
pub extra_access_tokens: Vec<String>,

/// Arguments to pass verbatim to the Nix command
#[cfg_attr(feature = "clap", arg(last = true))]
pub extra_args: Vec<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of extra_args, just add a quiet field looking like this. It is more self-documenting.

https://github.com/clap-rs/clap-verbosity-flag/blob/a7e305e8b0bde21be222ae658cc14813464ea3e6/src/lib.rs#L79-L88


/// Consider all previously downloaded files out-of-date.
#[cfg_attr(feature = "clap", arg(long))]
pub refresh: bool,
Expand All @@ -53,6 +57,7 @@ impl Default for NixCmd {
Self {
extra_experimental_features: vec![],
extra_access_tokens: vec![],
extra_args: vec![],
refresh: false,
}
}
Expand Down Expand Up @@ -114,6 +119,13 @@ impl NixCmd {
cmd
}

/// Suppress logs related to `override-input` usage by reducing `nix` command's verbosity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (Suppress logs related to override-input usage) the only effect of using --quiet --quiet or does it suppress anything else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it does more than that, then function (mute_override_input_logs) wouldn't be accurate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically, it reduces verbosity level of the logs. I could rename the function to depict that.

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<T>(&self, args: &[&str]) -> Result<T, NixCmdError>
where
Expand Down Expand Up @@ -202,6 +214,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());
}
Expand Down
2 changes: 0 additions & 2 deletions crates/nix_rs/src/flake/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>(&stdout)?;
Expand Down
5 changes: 4 additions & 1 deletion crates/omnix-cli/src/command/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ pub struct CICommand {
impl CICommand {
/// Run this sub-command
pub async fn run(&self, verbosity: Verbosity<InfoLevel>) -> 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(())
}
Expand Down
6 changes: 4 additions & 2 deletions crates/omnix-cli/src/command/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;

Expand Down
2 changes: 2 additions & 0 deletions doc/src/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `om {ci,show}`: Suppress logs from `--override-input` usage

### Enhancements

- `om develop`: New command
Expand Down