From e5c1d74e3fe5a6d3ec7544ebff59c2eebe029b1c Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Fri, 16 Jun 2023 16:23:39 +0200 Subject: [PATCH] tool: introduce --target-system to choose target architecture We will hard fail in case of encountering different architectures in bootspec. This should still be compatible with cross-compiling systems in the future. --- nix/modules/lanzaboote.nix | 1 + rust/tool/shared/src/esp.rs | 1 + rust/tool/systemd/src/cli.rs | 6 ++++++ rust/tool/systemd/src/install.rs | 7 +++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nix/modules/lanzaboote.nix b/nix/modules/lanzaboote.nix index 92939db..d55e825 100644 --- a/nix/modules/lanzaboote.nix +++ b/nix/modules/lanzaboote.nix @@ -104,6 +104,7 @@ in ''} ${cfg.package}/bin/lzbt install \ + --system ${config.nixpkgs.hostPlatform.system} \ --systemd ${config.systemd.package} \ --systemd-boot-loader-config ${loaderConfigFile} \ --public-key ${cfg.publicKeyFile} \ diff --git a/rust/tool/shared/src/esp.rs b/rust/tool/shared/src/esp.rs index e81ef7b..9437cb0 100644 --- a/rust/tool/shared/src/esp.rs +++ b/rust/tool/shared/src/esp.rs @@ -76,6 +76,7 @@ impl EspGenerationPaths { pub fn new>( esp_paths: &P, generation: &Generation, + system: Architecture, ) -> Result { let bootspec = &generation.spec.bootspec.bootspec; let bootspec_system: Architecture = Architecture::from_nixos_system(&bootspec.system)?; diff --git a/rust/tool/systemd/src/cli.rs b/rust/tool/systemd/src/cli.rs index df86121..c8d4b47 100644 --- a/rust/tool/systemd/src/cli.rs +++ b/rust/tool/systemd/src/cli.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use anyhow::{Context, Result}; use clap::{Parser, Subcommand}; +use crate::esp::Architecture; use crate::install; use lanzaboote_tool::signature::KeyPair; @@ -30,6 +31,10 @@ enum Commands { #[derive(Parser)] struct InstallCommand { + /// Target system + #[arg(long)] + target_system: String, + /// Systemd path #[arg(long)] systemd: PathBuf, @@ -90,6 +95,7 @@ fn install(args: InstallCommand) -> Result<()> { install::Installer::new( PathBuf::from(lanzaboote_stub), + Architecture::from_nixos_system(&args.target_system)?, args.systemd, args.systemd_boot_loader_config, key_pair, diff --git a/rust/tool/systemd/src/install.rs b/rust/tool/systemd/src/install.rs index 36c528a..c5fc764 100644 --- a/rust/tool/systemd/src/install.rs +++ b/rust/tool/systemd/src/install.rs @@ -30,11 +30,13 @@ pub struct Installer { configuration_limit: usize, esp_paths: SystemdEspPaths, generation_links: Vec, + arch: Architecture, } impl Installer { pub fn new( lanzaboote_stub: PathBuf, + arch: Architecture, systemd: PathBuf, systemd_boot_loader_config: PathBuf, key_pair: KeyPair, @@ -56,6 +58,7 @@ impl Installer { configuration_limit, esp_paths, generation_links, + arch, } } @@ -238,7 +241,7 @@ impl Installer { let bootspec = &generation.spec.bootspec.bootspec; - let esp_gen_paths = EspGenerationPaths::new(&self.esp_paths, generation)?; + let esp_gen_paths = EspGenerationPaths::new(&self.esp_paths, generation, self.arch)?; self.gc_roots.extend(esp_gen_paths.to_iter()); let initrd_content = fs::read( @@ -284,7 +287,7 @@ impl Installer { let bootspec = &generation.spec.bootspec.bootspec; - let esp_gen_paths = EspGenerationPaths::new(&self.esp_paths, generation)?; + let esp_gen_paths = EspGenerationPaths::new(&self.esp_paths, generation, self.arch)?; let kernel_cmdline = assemble_kernel_cmdline(&bootspec.init, bootspec.kernel_params.clone());