Add indirect node variant

This commit is contained in:
Luc Perkins 2023-07-11 11:58:35 -07:00
parent e915cfa5c6
commit 85cb4ebf05
No known key found for this signature in database
GPG Key ID: 4F102D0C16E232F2

View File

@ -135,13 +135,14 @@ fn chase_input_node(
let mut node = &nodes[&next_input]; let mut node = &nodes[&next_input];
for input in inputs { for input in inputs {
let maybe_node_inputs = match node { let maybe_node_inputs = match node {
Node::Root(_) => None,
Node::Repo(node) => node.inputs.to_owned(), Node::Repo(node) => node.inputs.to_owned(),
Node::Indirect(_) => None,
Node::Fallthrough(node) => match node.get("inputs") { Node::Fallthrough(node) => match node.get("inputs") {
Some(node_inputs) => serde_json::from_value(node_inputs.clone()) Some(node_inputs) => serde_json::from_value(node_inputs.clone())
.map_err(FlakeLockParseError::Json)?, .map_err(FlakeLockParseError::Json)?,
None => None, None => None,
}, },
Node::Root(_) => None,
}; };
let node_inputs = match maybe_node_inputs { let node_inputs = match maybe_node_inputs {
@ -181,11 +182,12 @@ impl FlakeLock {
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum Node { pub enum Node {
/// A [RootNode] specifying an [Input] map.
Root(RootNode),
/// A [RepoNode] flake input for a [Git](https://git-scm.com) repository (or another version /// A [RepoNode] flake input for a [Git](https://git-scm.com) repository (or another version
/// control system). /// control system).
Repo(Box<RepoNode>), Repo(Box<RepoNode>),
/// A [RootNode] specifying an [Input] map. Indirect(IndirectNode),
Root(RootNode),
/// A "catch-all" variant for node types that don't (yet) have explicit struct definitions in /// A "catch-all" variant for node types that don't (yet) have explicit struct definitions in
/// this crate. /// this crate.
Fallthrough(serde_json::value::Value), // Covers all other node types Fallthrough(serde_json::value::Value), // Covers all other node types
@ -196,6 +198,7 @@ impl Node {
match self { match self {
Node::Root(_) => "Root", Node::Root(_) => "Root",
Node::Repo(_) => "Repo", Node::Repo(_) => "Repo",
Node::Indirect(_) => "Indirect",
Node::Fallthrough(_) => "Fallthrough", // Covers all other node types Node::Fallthrough(_) => "Fallthrough", // Covers all other node types
} }
} }
@ -222,16 +225,18 @@ pub struct RootNode {
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct RepoNode { pub struct RepoNode {
/// Whether the input is itself a flake.
pub flake: Option<bool>,
/// The node's inputs. /// The node's inputs.
pub inputs: Option<HashMap<String, Input>>, pub inputs: Option<HashMap<String, Input>>,
/// The "locked" attributes of the input (set by Nix). /// The "locked" attributes of the input (set by Nix).
pub locked: RepoLocked, pub locked: Locked,
/// The "original" (user-supplied) attributes of the input. /// The "original" (user-supplied) attributes of the input.
pub original: RepoOriginal, pub original: RepoOriginal,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct RepoLocked { pub struct Locked {
#[serde(alias = "lastModified")] #[serde(alias = "lastModified")]
pub last_modified: i64, pub last_modified: i64,
#[serde(alias = "narHash")] #[serde(alias = "narHash")]
@ -252,3 +257,17 @@ pub struct RepoOriginal {
#[serde(alias = "ref")] #[serde(alias = "ref")]
pub git_ref: Option<String>, pub git_ref: Option<String>,
} }
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct IndirectNode {
pub locked: Locked,
pub original: IndirectOriginal,
}
#[derive(Clone, Debug, Deserialize)]
pub struct IndirectOriginal {
id: String,
#[serde(alias = "type")]
pub node_type: String,
}