Add parsing and finding the failed derivation

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-01-10 12:13:18 +01:00
parent a7986584d5
commit 85c6a8f169
9 changed files with 985 additions and 76 deletions

View file

@ -1,49 +1,106 @@
use std::collections::HashMap;
use serde::Deserialize;
use serde_repr::Deserialize_repr;
#[derive(Debug, Deserialize)]
pub mod helpers;
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "action", rename_all = "lowercase")]
pub enum NixBuildLogLine {
Start(NixLogStartAction),
Stop(NixLogStartAction),
Stop(NixLogStopAction),
Result(NixLogResultAction),
Msg(NixLogMsgAction),
}
#[derive(Debug, Deserialize)]
impl NixBuildLogLine {
pub fn id(&self) -> Option<u64> {
match self {
NixBuildLogLine::Start(NixLogStartAction { id, .. })
| NixBuildLogLine::Stop(NixLogStopAction { id })
| NixBuildLogLine::Result(NixLogResultAction { id, .. }) => Some(*id),
NixBuildLogLine::Msg(..) => None,
}
}
}
/// What kind of activity was logged
///
/// This definition mirrors the one in nixcpp. As it can evolve, the enum is marked as
/// `non_exhaustive` and may get extended later on.
#[derive(Debug, Clone, Copy, Deserialize_repr, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum ActivityKind {
Unknown = 0,
CopyPath = 100,
FileTransfer = 101,
Realise = 102,
CopyPaths = 103,
Builds = 104,
Build = 105,
OptimiseStore = 106,
VerifyPaths = 107,
Substitute = 108,
QueryPathInfo = 109,
PostBuildHook = 110,
BuildWaiting = 111,
FetchTree = 112,
}
/// What kind of result information was logged
///
/// This definition mirrors the one in nixcpp. As it can evolve, the enum is marked as
/// `non_exhaustive` and may get extended later on.
#[derive(Debug, Clone, Copy, Deserialize_repr, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum ResultKind {
FileLinked = 100,
BuildLogLine = 101,
UntrustedPath = 102,
CorruptedPath = 103,
SetPhase = 104,
Progress = 105,
SetExpected = 106,
PostBuildLogLine = 107,
FetchStatus = 108,
}
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogResultAction {
pub id: i64,
pub id: u64,
#[serde(rename = "type")]
pub kind: i64,
pub kind: ResultKind,
#[serde(default)]
pub fields: Vec<serde_json::Value>,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogStopAction {
pub id: i64,
pub id: u64,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogMsgAction {
pub level: Option<i64>,
pub msg: String,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogStartAction {
pub id: i64,
pub level: Option<i64>,
pub parent: Option<i64>,
pub id: u64,
pub level: i64,
pub parent: i64,
pub text: Option<String>,
#[serde(rename = "type")]
pub kind: Option<i64>,
pub kind: ActivityKind,
#[serde(default)]
pub fields: Vec<serde_json::Value>,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct RawNixDerivationInfoOutput(HashMap<String, RawNixDerivationInfo>);
impl RawNixDerivationInfoOutput {
@ -52,45 +109,15 @@ impl RawNixDerivationInfoOutput {
}
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct RawNixDerivationInfo {
args: Vec<String>,
builder: String,
pub args: Vec<String>,
pub builder: String,
#[serde(rename = "inputDrvs")]
input_derivations: HashMap<String, serde_json::Value>,
pub input_derivations: HashMap<String, serde_json::Value>,
#[serde(rename = "inputSrcs")]
input_sources: Vec<String>,
name: String,
outputs: HashMap<String, HashMap<String, String>>,
system: String,
}
impl RawNixDerivationInfo {
pub fn args(&self) -> &[String] {
&self.args
}
pub fn builder(&self) -> &str {
&self.builder
}
pub fn input_derivations(&self) -> &HashMap<String, serde_json::Value> {
&self.input_derivations
}
pub fn input_sources(&self) -> &[String] {
&self.input_sources
}
pub fn name(&self) -> &str {
&self.name
}
pub fn outputs(&self) -> &HashMap<String, HashMap<String, String>> {
&self.outputs
}
pub fn system(&self) -> &str {
&self.system
}
pub input_sources: Vec<String>,
pub name: String,
pub outputs: HashMap<String, HashMap<String, String>>,
pub system: String,
}