-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add a nix-health config to this project flake
- Loading branch information
Showing
8 changed files
with
92 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::command::{CommandError, NixCmd, NixCmdError}; | ||
|
||
use super::url::FlakeUrl; | ||
|
||
/// Run `nix eval <url> --json` and parse its JSON | ||
/// | ||
/// 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> | ||
where | ||
T: Default + serde::de::DeserializeOwned, | ||
{ | ||
let nix = NixCmd::default(); | ||
let result = nix | ||
.run_with_args_expecting_json(&["eval", url.0.as_str(), "--json"]) | ||
.await; | ||
match result { | ||
Err(err) if error_is_missing_attribute(&err) => { | ||
// The 'nixci' flake output attr is missing. User wants the default config. | ||
Ok(T::default()) | ||
} | ||
r => r, | ||
} | ||
} | ||
|
||
/// Check that [NixCmdError] is a missing attribute error | ||
fn error_is_missing_attribute(err: &NixCmdError) -> bool { | ||
match err { | ||
NixCmdError::CmdError(CommandError::ProcessFailed { stderr, .. }) => { | ||
stderr.contains("does not provide attribute") | ||
} | ||
_ => false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters