Skip to content

Commit

Permalink
ci: Add devour-flake output path in result JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Dec 9, 2024
1 parent ca6e8f8 commit 96ca32f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions crates/omnix-ci/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct RunCommand {
/// Must be a flake reference which, when imported, must return a Nix list
/// of systems. You may use one of the lists from
/// <https://github.com/nix-systems>.
///
/// You can also pass the individual system name, if they are supported by omnix.
#[arg(long)]
pub systems: Option<SystemsListFlakeRef>,

Expand Down
20 changes: 16 additions & 4 deletions crates/omnix-ci/src/nix/devour_flake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
use anyhow::{bail, Context, Result};
use nix_rs::{command::NixCmd, flake::url::FlakeUrl, store::path::StorePath};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, process::Stdio};
use std::{
collections::HashMap,
ffi::OsString,
os::unix::ffi::OsStringExt,
path::{Path, PathBuf},
process::Stdio,
};
use tokio::io::{AsyncBufReadExt, BufReader};

/// Absolute path to the devour-flake flake source
Expand All @@ -29,13 +35,19 @@ pub struct DevourFlakeOutput {
/// Output paths indexed by name (or pname) of the path if any
#[serde(rename = "byName")]
pub by_name: HashMap<String, StorePath>,

/// The devour-flake output store path from which Self is derived.
#[serde(skip_deserializing, rename = "devourOutput")]
pub devour_output: PathBuf,
}

impl DevourFlakeOutput {
fn from_drv(drv_out: &str) -> anyhow::Result<Self> {
fn from_drv(drv_out: &Path) -> anyhow::Result<Self> {
// Read drv_out file as JSON, decoding it into DevourFlakeOutput
let mut out: DevourFlakeOutput = serde_json::from_reader(std::fs::File::open(drv_out)?)
.context("Failed to parse devour-flake output")?;
// Provide the original devour-output store path itself.
out.devour_output = drv_out.to_owned();
// Remove duplicates, which is possible in user's flake
// e.g., when doing `packages.foo = self'.packages.default`
out.out_paths.sort();
Expand Down Expand Up @@ -96,8 +108,8 @@ pub async fn devour_flake(
.await
.context("Unable to spawn devour-flake process")?;
if output.status.success() {
let drv_out = String::from_utf8(output.stdout)?;
let v = DevourFlakeOutput::from_drv(drv_out.trim())?;
let drv_out = PathBuf::from(OsString::from_vec(output.stdout.trim_ascii_end().into()));
let v = DevourFlakeOutput::from_drv(&drv_out)?;
Ok(v)
} else {
let exit_code = output.status.code().unwrap_or(1);
Expand Down

0 comments on commit 96ca32f

Please sign in to comment.