diff --git a/nix/tests/lanzaboote.nix b/nix/tests/lanzaboote.nix index 87509b5a..d04426c4 100644 --- a/nix/tests/lanzaboote.nix +++ b/nix/tests/lanzaboote.nix @@ -240,6 +240,17 @@ in ''; }; + synthesis = mkSecureBootTest { + name = "lanzaboote-synthesis"; + machine = { lib, ... }: { + boot.bootspec.enable = lib.mkForce false; + }; + testScript = '' + machine.start() + print(machine.succeed("bootctl")) + ''; + }; + systemd-boot-loader-config = mkSecureBootTest { name = "lanzaboote-systemd-boot-loader-config"; machine = { diff --git a/rust/tool/src/generation.rs b/rust/tool/src/generation.rs index 41c05256..480343c5 100644 --- a/rust/tool/src/generation.rs +++ b/rust/tool/src/generation.rs @@ -40,10 +40,19 @@ pub struct Generation { impl Generation { pub fn from_link(link: &GenerationLink) -> Result { let bootspec_path = link.path.join("boot.json"); - let generation: BootspecGeneration = serde_json::from_slice( - &fs::read(bootspec_path).context("Failed to read bootspec file")?, - ) - .context("Failed to parse bootspec json")?; + let generation = fs::read(bootspec_path) + .with_context(|| "Failed to read bootspec") + .and_then(|v| serde_json::from_slice(&v).context("Failed to read bootspec JSON")) + // TODO: this should be much easier, add a From for BootspecGeneration + // this should enable us to do `into()` on the Result + // anyhow compatibility of bootspec would be nice too. + .or_else(|_err| Ok::<_, anyhow::Error>( + BootspecGeneration::V1( + BootJson::synthesize(&link.path) + .map_err(|err| anyhow!(err)) + .context("Failed to read a bootspec (missing bootspec?) and failed to synthesize a valid replacement bootspec.")? + ) + ))?; let bootspec: BootJson = generation .try_into()