Skip to content

bootspec: add a specialisation test #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions bootspec/src/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,81 @@ mod tests {
assert_eq!(from_json, expected);
}

#[test]
fn valid_v1_json_with_specialisations() {
let json =r#"{
"org.nixos.bootspec.v1": {
"init": "/nix/store/dqfz68g6q2i4xs3knjqivxdj0wyglfvl-nixos-system-machine-23.05pre-git/init",
"initrd": "/nix/store/kqv7bsb9ji7yhknim3laviz37b6smn2b-initrd-linux-6.1.25/initrd",
"initrdSecrets": "/nix/store/f3kvscyhly5p8qybcmcgs0rj9lr3zplj-append-initrd-secrets/bin/append-initrd-secrets",
"kernel": "/nix/store/v5j1pn8nd7h3i0w6kg1fpsa0mlxcgda4-linux-6.1.25/bzImage",
"kernelParams": [
"console=ttyS0",
"panic=1",
"boot.panic_on_fail",
"clock=acpi_pm",
"loglevel=7",
"net.ifnames=0"
],
"label": "NixOS Stoat 23.05pre-git (Linux 6.1.25)",
"system": "x86_64-linux",
"toplevel": "/nix/store/dqfz68g6q2i4xs3knjqivxdj0wyglfvl-nixos-system-machine-23.05pre-git"
},
"org.nixos.specialisation.v1": {
"variant": {
"init": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git/init",
"initrd": "/nix/store/kqv7bsb9ji7yhknim3laviz37b6smn2b-initrd-linux-6.1.25/initrd",
"initrdSecrets": "/nix/store/f3kvscyhly5p8qybcmcgs0rj9lr3zplj-append-initrd-secrets/bin/append-initrd-secrets",
"kernel": "/nix/store/v5j1pn8nd7h3i0w6kg1fpsa0mlxcgda4-linux-6.1.25/bzImage",
"kernelParams": [
"console=ttyS0",
"panic=1",
"boot.panic_on_fail",
"clock=acpi_pm",
"loglevel=7",
"net.ifnames=0"
],
"label": "NixOS Stoat 23.05pre-git (Linux 6.1.25)",
"system": "x86_64-linux",
"toplevel": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git"
}
}
Comment on lines +160 to +178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec says that there must be an org.nixos.bootspec.v1 key under the specialisation name, and you're missing that; that's why it fails:

  "org.nixos.specialisation.v1": {
    // Each key in this object corresponds to a specialisation as defined by the `specialisation.<name>` NixOS option.
    "<name>": {
      "org.nixos.bootspec.v1": {
        // See above
      }
    }
  },
Suggested change
"org.nixos.specialisation.v1": {
"variant": {
"init": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git/init",
"initrd": "/nix/store/kqv7bsb9ji7yhknim3laviz37b6smn2b-initrd-linux-6.1.25/initrd",
"initrdSecrets": "/nix/store/f3kvscyhly5p8qybcmcgs0rj9lr3zplj-append-initrd-secrets/bin/append-initrd-secrets",
"kernel": "/nix/store/v5j1pn8nd7h3i0w6kg1fpsa0mlxcgda4-linux-6.1.25/bzImage",
"kernelParams": [
"console=ttyS0",
"panic=1",
"boot.panic_on_fail",
"clock=acpi_pm",
"loglevel=7",
"net.ifnames=0"
],
"label": "NixOS Stoat 23.05pre-git (Linux 6.1.25)",
"system": "x86_64-linux",
"toplevel": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git"
}
}
"org.nixos.specialisation.v1": {
"variant": {
"org.nixos.bootspec.v1": {
"init": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git/init",
"initrd": "/nix/store/kqv7bsb9ji7yhknim3laviz37b6smn2b-initrd-linux-6.1.25/initrd",
"initrdSecrets": "/nix/store/f3kvscyhly5p8qybcmcgs0rj9lr3zplj-append-initrd-secrets/bin/append-initrd-secrets",
"kernel": "/nix/store/v5j1pn8nd7h3i0w6kg1fpsa0mlxcgda4-linux-6.1.25/bzImage",
"kernelParams": [
"console=ttyS0",
"panic=1",
"boot.panic_on_fail",
"clock=acpi_pm",
"loglevel=7",
"net.ifnames=0"
],
"label": "NixOS Stoat 23.05pre-git (Linux 6.1.25)",
"system": "x86_64-linux",
"toplevel": "/nix/store/4z5jmmhdvhyrpw08ic05bsb3hnbf365w-nixos-system-machine-23.05pre-git"
}
}
}

}"#;

let from_json: Generation = serde_json::from_str(&json).unwrap();
let Generation::V1(from_json) = from_json;

let bootspec = BootSpecV1 {
system: String::from("x86_64-linux"),
label: String::from("NixOS Stoat 23.05pre-git (Linux 6.1.25)"),
kernel: PathBuf::from("/nix/store/v5j1pn8nd7h3i0w6kg1fpsa0mlxcgda4-linux-6.1.25/bzImage"),
kernel_params: vec![
"console=ttyS0",
"panic=1",
"boot.panic_on_fail",
"clock=acpi_pm",
"loglevel=7",
"net.ifnames=0"
]
.iter()
.map(ToString::to_string)
.collect(),
init: PathBuf::from("/nix/store/dqfz68g6q2i4xs3knjqivxdj0wyglfvl-nixos-system-machine-23.05pre-git/init"),
initrd: Some(PathBuf::from("/nix/store/kqv7bsb9ji7yhknim3laviz37b6smn2b-initrd-linux-6.1.25/initrd")),
initrd_secrets: Some(PathBuf::from(
"/nix/store/f3kvscyhly5p8qybcmcgs0rj9lr3zplj-append-initrd-secrets/bin/append-initrd-secrets"
)),
toplevel: SystemConfigurationRoot(PathBuf::from("/nix/store/dqfz68g6q2i4xs3knjqivxdj0wyglfvl-nixos-system-machine-23.05pre-git/")),
};
let expected = GenerationV1 {
bootspec,
specialisations: HashMap::new(),
};

assert_eq!(from_json, expected);

}

#[test]
fn valid_v1_json_with_typed_extension() {
let json = r#"{
Expand Down