tool(architecture): make it generic
Architecture is now a generic structure that can be specialized via an "external" trait for generating the paths you care about depending on your target bootloader.
This commit is contained in:
parent
609c11f26d
commit
0107754d62
|
@ -0,0 +1,35 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
/// Supported system
|
||||
#[non_exhaustive]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum Architecture {
|
||||
X86,
|
||||
AArch64,
|
||||
}
|
||||
|
||||
impl Architecture {
|
||||
pub fn efi_representation(&self) -> &str {
|
||||
match self {
|
||||
Self::X86 => "x64",
|
||||
Self::AArch64 => "aa64",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn efi_fallback_filename(&self) -> PathBuf {
|
||||
format!("BOOT{}.EFI", self.efi_representation().to_ascii_uppercase()).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Architecture {
|
||||
/// Converts from a NixOS system double to a supported system
|
||||
pub fn from_nixos_system(system_double: &str) -> Result<Self> {
|
||||
Ok(match system_double {
|
||||
"x86_64-linux" => Self::X86,
|
||||
"aarch64-linux" => Self::AArch64,
|
||||
_ => bail!("Unsupported NixOS system double: {}, please open an issue or a PR if you think this should be supported.", system_double)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -3,53 +3,11 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::architecture::Architecture;
|
||||
use crate::generation::Generation;
|
||||
|
||||
/// Supported system
|
||||
#[allow(dead_code)]
|
||||
#[non_exhaustive]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum Architecture {
|
||||
X86,
|
||||
AArch64,
|
||||
}
|
||||
|
||||
impl Architecture {
|
||||
pub fn systemd_stub_filename(&self) -> &Path {
|
||||
Path::new(match self {
|
||||
Self::X86 => "linuxx64.efi.stub",
|
||||
Self::AArch64 => "linuxaa64.efi.stub"
|
||||
})
|
||||
}
|
||||
|
||||
pub fn systemd_filename(&self) -> &Path {
|
||||
Path::new(match self {
|
||||
Self::X86 => "systemd-bootx64.efi",
|
||||
Self::AArch64 => "systemd-bootaa64.efi"
|
||||
})
|
||||
}
|
||||
|
||||
pub fn efi_fallback_filename(&self) -> &Path {
|
||||
Path::new(match self {
|
||||
Self::X86 => "BOOTX64.EFI",
|
||||
Self::AArch64 => "BOOTAA64.EFI",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Architecture {
|
||||
/// Converts from a NixOS system double to a supported system
|
||||
pub fn from_nixos_system(system_double: &str) -> Result<Self> {
|
||||
Ok(match system_double {
|
||||
"x86_64-linux" => Self::X86,
|
||||
"aarch64-linux" => Self::AArch64,
|
||||
_ => bail!("Unsupported NixOS system double: {}, please open an issue or a PR if you think this should be supported.", system_double)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic ESP paths which can be specific to a bootloader
|
||||
pub trait EspPaths<const N: usize> {
|
||||
/// Build an ESP path structure out of the ESP root directory
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod architecture;
|
||||
pub mod esp;
|
||||
pub mod gc;
|
||||
pub mod generation;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use lanzaboote_tool::architecture::Architecture;
|
||||
|
||||
/// Systemd-specific architecture helpers
|
||||
pub trait SystemdArchitectureExt {
|
||||
fn systemd_stub_filename(&self) -> PathBuf;
|
||||
fn systemd_filename(&self) -> PathBuf;
|
||||
}
|
||||
|
||||
impl SystemdArchitectureExt for Architecture {
|
||||
fn systemd_stub_filename(&self) -> PathBuf {
|
||||
format!("linux{}.efi.stub", self.efi_representation()).into()
|
||||
}
|
||||
|
||||
fn systemd_filename(&self) -> PathBuf {
|
||||
format!("systemd-boot{}.efi", self.efi_representation()).into()
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@ use std::path::PathBuf;
|
|||
use anyhow::{Context, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::esp::Architecture;
|
||||
use crate::install;
|
||||
use lanzaboote_tool::architecture::Architecture;
|
||||
use lanzaboote_tool::signature::KeyPair;
|
||||
|
||||
/// The default log level.
|
||||
|
@ -31,9 +31,9 @@ enum Commands {
|
|||
|
||||
#[derive(Parser)]
|
||||
struct InstallCommand {
|
||||
/// Target system
|
||||
/// System for lanzaboote binaries, e.g. defines the EFI fallback path
|
||||
#[arg(long)]
|
||||
target_system: String,
|
||||
system: String,
|
||||
|
||||
/// Systemd path
|
||||
#[arg(long)]
|
||||
|
@ -95,7 +95,7 @@ fn install(args: InstallCommand) -> Result<()> {
|
|||
|
||||
install::Installer::new(
|
||||
PathBuf::from(lanzaboote_stub),
|
||||
Architecture::from_nixos_system(&args.target_system)?,
|
||||
Architecture::from_nixos_system(&args.system)?,
|
||||
args.systemd,
|
||||
args.systemd_boot_loader_config,
|
||||
key_pair,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::architecture::SystemdArchitectureExt;
|
||||
use lanzaboote_tool::architecture::Architecture;
|
||||
use lanzaboote_tool::esp::EspPaths;
|
||||
|
||||
/// Paths to the boot files that are not specific to a generation.
|
||||
|
@ -18,7 +20,7 @@ pub struct SystemdEspPaths {
|
|||
}
|
||||
|
||||
impl EspPaths<10> for SystemdEspPaths {
|
||||
fn new(esp: impl AsRef<Path>) -> Self {
|
||||
fn new(esp: impl AsRef<Path>, architecture: Architecture) -> Self {
|
||||
let esp = esp.as_ref();
|
||||
let efi = esp.join("EFI");
|
||||
let efi_nixos = efi.join("nixos");
|
||||
|
@ -34,9 +36,9 @@ impl EspPaths<10> for SystemdEspPaths {
|
|||
nixos: efi_nixos,
|
||||
linux: efi_linux,
|
||||
efi_fallback_dir: efi_efi_fallback_dir.clone(),
|
||||
efi_fallback: efi_efi_fallback_dir.join("BOOTX64.EFI"),
|
||||
efi_fallback: efi_efi_fallback_dir.join(architecture.efi_fallback_filename()),
|
||||
systemd: efi_systemd.clone(),
|
||||
systemd_boot: efi_systemd.join("systemd-bootx64.efi"),
|
||||
systemd_boot: efi_systemd.join(architecture.systemd_filename()),
|
||||
loader,
|
||||
systemd_boot_loader_config,
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ use anyhow::{anyhow, Context, Result};
|
|||
use nix::unistd::syncfs;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::architecture::SystemdArchitectureExt;
|
||||
use crate::esp::SystemdEspPaths;
|
||||
use crate::version::SystemdVersion;
|
||||
use lanzaboote_tool::esp::{EspGenerationPaths, EspPaths, Architecture};
|
||||
use lanzaboote_tool::architecture::Architecture;
|
||||
use lanzaboote_tool::esp::{EspGenerationPaths, EspPaths};
|
||||
use lanzaboote_tool::gc::Roots;
|
||||
use lanzaboote_tool::generation::{Generation, GenerationLink};
|
||||
use lanzaboote_tool::os_release::OsRelease;
|
||||
|
@ -45,8 +47,8 @@ impl Installer {
|
|||
generation_links: Vec<PathBuf>,
|
||||
) -> Self {
|
||||
let mut gc_roots = Roots::new();
|
||||
let esp_paths = EspPaths::new(esp, target_arch);
|
||||
gc_roots.extend(esp_paths.to_iter());
|
||||
let esp_paths = SystemdEspPaths::new(esp, arch);
|
||||
gc_roots.extend(esp_paths.iter());
|
||||
|
||||
Self {
|
||||
broken_gens: BTreeSet::new(),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
pub mod architecture;
|
|
@ -1,3 +1,4 @@
|
|||
mod architecture;
|
||||
mod cli;
|
||||
mod esp;
|
||||
mod install;
|
||||
|
|
Loading…
Reference in New Issue