Skip to content

Commit a7abe98

Browse files
committed
feat: read the full specialisation schema from bootspec
This fixes #147 by changing the type of specialisations from `Generation` to `BootJson`. This means that we capture the full recursive JSON schema for specialisations, including extensions, while the previous type threw this information away. This allows for instance to set specific sort keys for specialisations. Such sort keys are allowed by the bootspec specification, but are currently not retained when parsing a bootspec document.
1 parent b20e28c commit a7abe98

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

bootspec/rfc0125_spec.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
},
2121
"org.nixos.specialisation.v1": {
2222
"<name>": {
23+
"org.nix-community.test": {
24+
"foo": "bar"
25+
},
2326
"org.nixos.bootspec.v1": {
2427
"system": "x86_64-linux",
2528
"init": "/nix/store/xxx-nixos-system-xxx/init",

bootspec/src/generation.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ mod tests {
8888
.map(ToOwned::to_owned)
8989
.collect::<Vec<_>>();
9090
assert!(keys.contains(&SpecialisationName(String::from("<name>"))));
91+
92+
assert_eq!(
93+
from_json
94+
.specialisations
95+
.get(&SpecialisationName("<name>".into()))
96+
.unwrap()
97+
.extensions
98+
.get("org.nix-community.test")
99+
.unwrap()
100+
.as_object()
101+
.unwrap()
102+
.get("foo")
103+
.unwrap()
104+
.as_str(),
105+
Some("bar")
106+
)
91107
}
92108

93109
#[test]

bootspec/src/v1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
66
use serde::{Deserialize, Serialize};
77

88
use crate::error::{BootspecError, SynthesizeError};
9-
use crate::{Result, SpecialisationName, SystemConfigurationRoot};
9+
use crate::{BootJson, Result, SpecialisationName, SystemConfigurationRoot};
1010

1111
/// The V1 bootspec schema version.
1212
pub const SCHEMA_VERSION: u64 = 1;
@@ -48,7 +48,7 @@ impl GenerationV1 {
4848

4949
specialisations.insert(
5050
SpecialisationName(name.to_string()),
51-
Self::synthesize(&toplevel)?,
51+
BootJson::synthesize_version(&toplevel, SCHEMA_VERSION)?,
5252
);
5353
}
5454
}
@@ -63,7 +63,7 @@ impl GenerationV1 {
6363
/// A mapping of V1 bootspec specialisations.
6464
///
6565
/// This structure represents the contents of the `org.nixos.specialisations.v1` key.
66-
pub type SpecialisationsV1 = HashMap<SpecialisationName, GenerationV1>;
66+
pub type SpecialisationsV1 = HashMap<SpecialisationName, BootJson>;
6767

6868
/// A V1 bootspec toplevel.
6969
///

0 commit comments

Comments
 (0)