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.
This commit is contained in:
Raito Bezarius 2023-06-16 16:23:39 +02:00 committed by nikstur
parent acc4c2e0a1
commit e5c1d74e3f
4 changed files with 13 additions and 2 deletions

View File

@ -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} \

View File

@ -76,6 +76,7 @@ impl EspGenerationPaths {
pub fn new<const N: usize, P: EspPaths<N>>(
esp_paths: &P,
generation: &Generation,
system: Architecture,
) -> Result<Self> {
let bootspec = &generation.spec.bootspec.bootspec;
let bootspec_system: Architecture = Architecture::from_nixos_system(&bootspec.system)?;

View File

@ -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,

View File

@ -30,11 +30,13 @@ pub struct Installer {
configuration_limit: usize,
esp_paths: SystemdEspPaths,
generation_links: Vec<PathBuf>,
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());