@@ -5,8 +5,9 @@ use std::path::{Path, PathBuf};
55
66use serde:: { Deserialize , Serialize } ;
77
8+ use crate :: deser;
89use crate :: error:: { BootspecError , SynthesizeError } ;
9- use crate :: { Result , SpecialisationName , SystemConfigurationRoot } ;
10+ use crate :: { Extensions , Result , SpecialisationName , SystemConfigurationRoot } ;
1011
1112/// The V1 bootspec schema version.
1213pub const SCHEMA_VERSION : u64 = 1 ;
@@ -48,7 +49,7 @@ impl GenerationV1 {
4849
4950 specialisations. insert (
5051 SpecialisationName ( name. to_string ( ) ) ,
51- Self :: synthesize ( & toplevel) ?,
52+ SpecialisationV1 :: synthesize ( & toplevel) ?,
5253 ) ;
5354 }
5455 }
@@ -62,8 +63,37 @@ impl GenerationV1 {
6263
6364/// A mapping of V1 bootspec specialisations.
6465///
65- /// This structure represents the contents of the `org.nixos.specialisations.v1` key.
66- pub type SpecialisationsV1 = HashMap < SpecialisationName , GenerationV1 > ;
66+ /// This structure represents the contents of the `org.nixos.specialisation.v1` key.
67+ pub type SpecialisationsV1 = HashMap < SpecialisationName , SpecialisationV1 > ;
68+
69+ /// A V1 bootspec specialisation.
70+ ///
71+ /// This structure represents a single specialisation contained in the `org.nixos.specialisation.v1` key.
72+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
73+ pub struct SpecialisationV1 {
74+ #[ serde( flatten) ]
75+ pub generation : GenerationV1 ,
76+ #[ serde(
77+ default = "HashMap::new" ,
78+ skip_serializing_if = "HashMap::is_empty" ,
79+ deserialize_with = "deser::skip_generation_fields" ,
80+ flatten
81+ ) ]
82+ pub extensions : Extensions ,
83+ }
84+
85+ impl SpecialisationV1 {
86+ /// Synthesize a [`SpecialisationV1`] struct from the path to a NixOS generation.
87+ ///
88+ /// This is useful when used on generations that do not have a bootspec attached to it.
89+ pub fn synthesize ( generation_path : & Path ) -> Result < Self > {
90+ let generation = GenerationV1 :: synthesize ( generation_path) ?;
91+ Ok ( Self {
92+ generation,
93+ extensions : HashMap :: new ( ) ,
94+ } )
95+ }
96+ }
6797
6898/// A V1 bootspec toplevel.
6999///
0 commit comments