Skip to content

Commit

Permalink
Merge pull request #117 from juspay/nix_rs_eval_attr
Browse files Browse the repository at this point in the history
`nix_eval_attr_json`: add `default_if_missing` argument
  • Loading branch information
srid authored Mar 1, 2024
2 parents 2451a81 + 10a217d commit c02faba
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ clap = { version = "4.3", features = ["derive", "env"] }
human-panic = "1.1.5"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
nix_rs = { version = "0.2.1", path = "./crates/nix_rs" }
nix_rs = { version = "0.3.0", path = "./crates/nix_rs" }
nix_health = { path = "./crates/nix_health" }
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down Expand Up @@ -59,5 +59,7 @@ dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "6478
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" }
dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" }
# https://github.com/DioxusLabs/dioxus-std/pull/17
dioxus-std = { git = "https://github.com/ealmloff/dioxus-std.git", branch="storage", features = ["storage"] }
dioxus-std = { git = "https://github.com/ealmloff/dioxus-std.git", branch = "storage", features = [
"storage",
] }
fermi = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "c7963a03440d5a050bf229f91665d60a0d108a8a" }
2 changes: 1 addition & 1 deletion crates/nix_health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl NixHealth {
url: nix_rs::flake::url::FlakeUrl,
) -> Result<Self, nix_rs::command::NixCmdError> {
use nix_rs::flake::eval::nix_eval_attr_json;
nix_eval_attr_json(&url).await
nix_eval_attr_json(&url, true).await
}

/// Run all checks and collect the results
Expand Down
2 changes: 1 addition & 1 deletion crates/nix_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition.workspace = true
name = "nix_rs"
# Important: remember to update the top-level Cargo.toml if updating major version
version = "0.2.3"
version = "0.3.0"
license.workspace = true
repository.workspace = true
description = "Rust library for interacting with the Nix command"
Expand Down
7 changes: 5 additions & 2 deletions crates/nix_rs/src/flake/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use super::url::FlakeUrl;
///
/// If the flake does not output the given attribute, return the [Default]
/// value of `T`.
pub async fn nix_eval_attr_json<T>(url: &FlakeUrl) -> Result<T, NixCmdError>
pub async fn nix_eval_attr_json<T>(
url: &FlakeUrl,
default_if_missing: bool,
) -> Result<T, NixCmdError>
where
T: Default + serde::de::DeserializeOwned,
{
Expand All @@ -15,7 +18,7 @@ where
.run_with_args_expecting_json(&["eval", url.0.as_str(), "--json"])
.await;
match result {
Err(err) if error_is_missing_attribute(&err) => {
Err(err) if default_if_missing && error_is_missing_attribute(&err) => {
// The 'nixci' flake output attr is missing. User wants the default config.
Ok(T::default())
}
Expand Down

0 comments on commit c02faba

Please sign in to comment.