From 7c8cf87213dcb8bc1d4aa8aaeda940e0d05c6fce Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:29:37 -0500 Subject: [PATCH] `om ci`: Add devour-flake output path in result JSON (#359) Useful to `nix copy` stuff back transitively (https://github.com/juspay/omnix/issues/358#issuecomment-2529325175). ![image](https://github.com/user-attachments/assets/d920e413-8911-4f55-abe2-bbf0c7d59056) --- crates/omnix-ci/src/command/run.rs | 2 ++ crates/omnix-ci/src/nix/devour_flake.rs | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/omnix-ci/src/command/run.rs b/crates/omnix-ci/src/command/run.rs index 52b3dd76..fd8fd614 100644 --- a/crates/omnix-ci/src/command/run.rs +++ b/crates/omnix-ci/src/command/run.rs @@ -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 /// . + /// + /// You can also pass the individual system name, if they are supported by omnix. #[arg(long)] pub systems: Option, diff --git a/crates/omnix-ci/src/nix/devour_flake.rs b/crates/omnix-ci/src/nix/devour_flake.rs index f1175639..5712a597 100644 --- a/crates/omnix-ci/src/nix/devour_flake.rs +++ b/crates/omnix-ci/src/nix/devour_flake.rs @@ -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 @@ -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, + + /// 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 { + fn from_drv(drv_out: &Path) -> anyhow::Result { // 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(); @@ -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);