From 47e8c802295ae7f1e1e509284b477fd133496dd3 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Sun, 5 Jul 2026 17:43:13 +1000 Subject: [PATCH] fix various clippy errors related to schema versions --- crates/cli/src/cli.rs | 4 +-- crates/core/src/cache/mod.rs | 8 +++--- crates/core/src/hive/mod.rs | 53 ++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 83586bc..e647b18 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -14,7 +14,7 @@ use wire_core::commands::common::get_hive_node_names; use wire_core::hive::node::{ ApplyGoal as HiveGoal, HandleUnreachable, Name, SwitchToConfigurationGoal, }; -use wire_core::hive::{Hive, get_hive_location}; +use wire_core::hive::{SCHEMA_VERSION_SEMVER, get_hive_location}; use std::io::IsTerminal; #[cfg(debug_assertions)] @@ -30,7 +30,7 @@ use std::{ name = "wire", bin_name = "wire", about = "a tool to deploy nixos systems", - version = format!("{}, supports hives within {}", crate_version!(), *Hive::SCHEMA_VERSION_SEMVER) + version = format!("{}, supports hives within {}", crate_version!(), *SCHEMA_VERSION_SEMVER) )] pub struct Cli { #[command(subcommand)] diff --git a/crates/core/src/cache/mod.rs b/crates/core/src/cache/mod.rs index b5eb596..5b65d33 100644 --- a/crates/core/src/cache/mod.rs +++ b/crates/core/src/cache/mod.rs @@ -21,7 +21,7 @@ use wire_nix_client::NixClient; use crate::{ SafeStorePath, commands::trace_nix_log_message, - hive::{FlakePrefetch, Hive, node::Name}, + hive::{FlakePrefetch, Hive, SCHEMA_VERSION_STRING, node::Name}, }; #[derive(Clone)] @@ -174,7 +174,7 @@ impl InspectionCache { ", store_path_digest, hash, - &**Hive::SCHEMA_VERSION_STRING, + &**SCHEMA_VERSION_STRING, store_path_name ) .fetch_optional(&self.pool) @@ -228,7 +228,7 @@ impl InspectionCache { returning inspection_blobs.id ", json_value, - &**Hive::SCHEMA_VERSION_STRING + &**SCHEMA_VERSION_STRING ) .fetch_one(&self.pool) .await @@ -438,7 +438,7 @@ where offset 30 )", - &**Hive::SCHEMA_VERSION_STRING + &**SCHEMA_VERSION_STRING ) .execute(&self.pool) .await?; diff --git a/crates/core/src/hive/mod.rs b/crates/core/src/hive/mod.rs index 25be345..a666ea4 100644 --- a/crates/core/src/hive/mod.rs +++ b/crates/core/src/hive/mod.rs @@ -29,6 +29,18 @@ pub mod node; pub mod plan; pub mod steps; +/// The schema version that was previously used before the semver schema +/// versions where implemented +pub const DEPRECATED_SCHEMA_VERSION: u64 = 1; + +/// Semver version requirement for schemas that this wire binary can read. +pub static SCHEMA_VERSION_SEMVER: LazyLock = LazyLock::new(|| { + VersionReq::parse("^1.0.0").expect("hive version requirement failed to parse") +}); + +pub static SCHEMA_VERSION_STRING: LazyLock = + LazyLock::new(|| SCHEMA_VERSION_SEMVER.to_string()); + #[derive(Debug, Eq, PartialEq)] pub enum SchemaVersion { Semver(semver::Version), @@ -59,23 +71,24 @@ fn check_schema_version<'de, D: Deserializer<'de>>(d: D) -> Result>(d: D) -> Result>(d: D) -> Result = LazyLock::new(|| { - VersionReq::parse("^1.0.0").expect("hive version requirement failed to parse") - }); - - pub const SCHEMA_VERSION_STRING: LazyLock = - LazyLock::new(|| Hive::SCHEMA_VERSION_SEMVER.to_string()); - #[instrument(skip_all, name = "eval_hive")] pub async fn new_from_path( location: &HiveLocation, @@ -392,7 +393,7 @@ mod tests { hive, Hive { nodes, - schema: SchemaVersion::DeprecatedInteger(Hive::DEPRECATED_SCHEMA_VERSION) + schema: SchemaVersion::DeprecatedInteger(DEPRECATED_SCHEMA_VERSION) } ); } @@ -434,7 +435,7 @@ mod tests { hive, Hive { nodes, - schema: SchemaVersion::DeprecatedInteger(Hive::DEPRECATED_SCHEMA_VERSION) + schema: SchemaVersion::DeprecatedInteger(DEPRECATED_SCHEMA_VERSION) } ); } @@ -466,7 +467,7 @@ mod tests { hive, Hive { nodes, - schema: SchemaVersion::DeprecatedInteger(Hive::DEPRECATED_SCHEMA_VERSION) + schema: SchemaVersion::DeprecatedInteger(DEPRECATED_SCHEMA_VERSION) } ); -- 2.51.2