Skip to content

Commit

Permalink
chore: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Apr 17, 2024
1 parent 81f7338 commit 13e8200
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl BuildConfig {
}

async fn get_current_system() -> Result<System, NixCmdError> {
let cmd = crate::NIXCMD.get().unwrap();
let cmd = crate::nixcmd().await;
let config = NixConfig::from_nix(cmd).await?;
Ok(config.system.value)
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Config {
/// ```
/// along with the config.
pub async fn from_flake_url(url: &FlakeUrl) -> Result<Config> {
let cmd = crate::NIXCMD.get().unwrap();
let cmd = crate::nixcmd().await;
let (flake_url, attr) = url.split_attr();
let nested_attr = attr.as_list();
let (name, selected_subflake) = match nested_attr.as_slice() {
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ use tracing::instrument;

static NIXCMD: OnceCell<NixCmd> = OnceCell::const_new();

pub async fn nixcmd() -> &'static NixCmd {
NIXCMD
.get_or_init(|| async { NixCmd::with_flakes().await.unwrap() })
.await
}

/// Run nixci on the given [CliArgs], returning the built outputs in sorted order.
#[instrument(name = "nixci", skip(args))]
pub async fn nixci(args: CliArgs) -> anyhow::Result<Vec<DrvOut>> {
tracing::debug!("Args: {args:?}");
NIXCMD.set(NixCmd::with_flakes().await?)?;
let cfg = args.command.get_config().await?;
match args.command {
cli::Command::Build(build_cfg) => nixci_build(args.verbose, &build_cfg, &cfg).await,
Expand Down
2 changes: 1 addition & 1 deletion src/nix/devour_flake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct DrvOut(pub String);
pub async fn devour_flake(verbose: bool, args: Vec<String>) -> Result<DevourFlakeOutput> {
// TODO: Use nix_rs here as well
// In the context of doing https://github.com/srid/nixci/issues/15
let nix = crate::NIXCMD.get().unwrap();
let nix = crate::nixcmd().await;
let mut cmd = nix.command();
let devour_flake_url = format!("{}#default", env!("DEVOUR_FLAKE"));
cmd.args(&[
Expand Down
2 changes: 1 addition & 1 deletion src/nix/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use nix_rs::flake::url::FlakeUrl;

/// Make sure that the `flake.lock` file is in sync.
pub async fn nix_flake_lock_check(url: &FlakeUrl) -> Result<()> {
let nix = crate::NIXCMD.get().unwrap();
let nix = crate::nixcmd().await;
let mut cmd = nix.command();
cmd.args(&["flake", "lock", "--no-update-lock-file", &url.0]);
nix_rs::command::trace_cmd(&cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/system_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn nix_eval_impure_expr<T>(expr: String) -> Result<T, NixCmdError>
where
T: Default + serde::de::DeserializeOwned,
{
let nix = crate::NIXCMD.get().unwrap();
let nix = crate::nixcmd().await;
let v = nix
.run_with_args_expecting_json::<T>(&["eval", "--impure", "--json", "--expr", &expr])
.await?;
Expand Down

0 comments on commit 13e8200

Please sign in to comment.