Move nix json types to extra crate

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2025-12-30 10:05:27 +01:00
parent d662ac59a3
commit a7986584d5
7 changed files with 934 additions and 8 deletions

11
nix-json/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "nix-json"
edition.workspace = true
version = "0.1.0"
license.workspace = true
authors.workspace = true
readme.workspace = true
[dependencies]
serde.workspace = true
serde_json.workspace = true

96
nix-json/src/lib.rs Normal file
View file

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