nixie-ci/nix-json/src/lib.rs
Marcel Müller 85c6a8f169 Add parsing and finding the failed derivation
Signed-off-by: Marcel Müller <neikos@neikos.email>
2026-01-10 12:13:18 +01:00

123 lines
3.1 KiB
Rust

use std::collections::HashMap;
use serde::Deserialize;
use serde_repr::Deserialize_repr;
pub mod helpers;
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "action", rename_all = "lowercase")]
pub enum NixBuildLogLine {
Start(NixLogStartAction),
Stop(NixLogStopAction),
Result(NixLogResultAction),
Msg(NixLogMsgAction),
}
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: u64,
#[serde(rename = "type")]
pub kind: ResultKind,
#[serde(default)]
pub fields: Vec<serde_json::Value>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogStopAction {
pub id: u64,
}
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogMsgAction {
pub level: Option<i64>,
pub msg: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct NixLogStartAction {
pub id: u64,
pub level: i64,
pub parent: i64,
pub text: Option<String>,
#[serde(rename = "type")]
pub kind: ActivityKind,
#[serde(default)]
pub fields: Vec<serde_json::Value>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct RawNixDerivationInfoOutput(HashMap<String, RawNixDerivationInfo>);
impl RawNixDerivationInfoOutput {
pub fn info(&self) -> &HashMap<String, RawNixDerivationInfo> {
&self.0
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct RawNixDerivationInfo {
pub args: Vec<String>,
pub builder: String,
#[serde(rename = "inputDrvs")]
pub input_derivations: HashMap<String, serde_json::Value>,
#[serde(rename = "inputSrcs")]
pub input_sources: Vec<String>,
pub name: String,
pub outputs: HashMap<String, HashMap<String, String>>,
pub system: String,
}