Skip to content

Commit b69263a

Browse files
install: Make the bootloader to also be a config file option
There is already a --bootloader command line argument. Make it this to also be available as an install file configuration option. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
1 parent 2fcac23 commit b69263a

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

crates/lib/src/install.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,10 @@ async fn prepare_install(
16481648
.and_then(|b| b.skip_boot_uuid)
16491649
.unwrap_or(false);
16501650
}
1651+
1652+
if config_opts.bootloader.is_none() {
1653+
config_opts.bootloader = config.bootloader.clone();
1654+
}
16511655
} else {
16521656
tracing::debug!("No install configuration found");
16531657
}

crates/lib/src/install/config.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! This module handles the TOML configuration file for `bootc install`.
44
5+
use crate::spec::Bootloader;
56
use anyhow::{Context, Result};
67
use clap::ValueEnum;
78
use fn_error_context::context;
@@ -97,6 +98,8 @@ pub(crate) struct InstallConfiguration {
9798
pub(crate) boot_mount_spec: Option<String>,
9899
/// Bootupd configuration
99100
pub(crate) bootupd: Option<Bootupd>,
101+
/// Bootloader to use (grub, systemd, none)
102+
pub(crate) bootloader: Option<Bootloader>,
100103
}
101104

102105
fn merge_basic<T>(s: &mut Option<T>, o: Option<T>, _env: &EnvProperties) {
@@ -180,6 +183,7 @@ impl Mergeable for InstallConfiguration {
180183
merge_basic(&mut self.root_mount_spec, other.root_mount_spec, env);
181184
merge_basic(&mut self.boot_mount_spec, other.boot_mount_spec, env);
182185
self.bootupd.merge(other.bootupd, env);
186+
merge_basic(&mut self.bootloader, other.bootloader, env);
183187
if let Some(other_kargs) = other.kargs {
184188
self.kargs
185189
.get_or_insert_with(Default::default)
@@ -810,3 +814,46 @@ skip-boot-uuid = false
810814
assert_eq!(install.bootupd.unwrap().skip_boot_uuid.unwrap(), true);
811815
}
812816
}
817+
818+
#[test]
819+
fn test_parse_bootloader() {
820+
let env = EnvProperties {
821+
sys_arch: "x86_64".to_string(),
822+
};
823+
824+
// 1. Test parsing "none"
825+
let c: InstallConfigurationToplevel = toml::from_str(
826+
r##"[install]
827+
bootloader = "none"
828+
"##,
829+
)
830+
.unwrap();
831+
assert_eq!(c.install.unwrap().bootloader, Some(Bootloader::None));
832+
833+
// 2. Test parsing "grub"
834+
let c: InstallConfigurationToplevel = toml::from_str(
835+
r##"[install]
836+
bootloader = "grub"
837+
"##,
838+
)
839+
.unwrap();
840+
assert_eq!(c.install.unwrap().bootloader, Some(Bootloader::Grub));
841+
842+
// 3. Test merging
843+
// Initial config has "systemd"
844+
let mut install: InstallConfiguration = toml::from_str(
845+
r#"bootloader = "systemd"
846+
"#,
847+
)
848+
.unwrap();
849+
850+
// Incoming config has "none"
851+
let other = InstallConfiguration {
852+
bootloader: Some(Bootloader::None),
853+
..Default::default()
854+
};
855+
856+
// Merge should overwrite systemd with none
857+
install.merge(other, &env);
858+
assert_eq!(install.bootloader, Some(Bootloader::None));
859+
}

crates/lib/src/spec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub struct BootEntryOstree {
185185
#[derive(
186186
clap::ValueEnum, Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema,
187187
)]
188+
#[serde(rename_all = "kebab-case")]
188189
pub enum Bootloader {
189190
/// Use Grub as the bootloader
190191
#[default]

0 commit comments

Comments
 (0)