Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,18 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
.run_capture_stderr()?;
}

// Apply ostree configuration from install config
if let Some(install_config) = state.install_config.as_ref() {
if let Some(ostree_config) = install_config.ostree.as_ref() {
if let Some(bls_append_except_default) = ostree_config.bls_append_except_default.as_ref() {
Command::new("ostree")
.args(["config", "--repo", "ostree/repo", "set", "sysroot.bls-append-except-default", bls_append_except_default])
.cwd_dir(rootfs_dir.try_clone()?)
.run_capture_stderr()?;
}
}
}
Comment on lines +806 to +815
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The nested if let chain can be flattened using and_then for better readability and to be more idiomatic.

    if let Some(bls_append_except_default) = state
        .install_config
        .as_ref()
        .and_then(|c| c.ostree.as_ref())
        .and_then(|o| o.bls_append_except_default.as_ref())
    {
        Command::new("ostree")
            .args([
                "config",
                "--repo",
                "ostree/repo",
                "set",
                "sysroot.bls-append-except-default",
                bls_append_except_default,
            ])
            .cwd_dir(rootfs_dir.try_clone()?)
            .run_capture_stderr()?;
    }


let sysroot = {
let path = format!(
"/proc/{}/fd/{}",
Expand Down
59 changes: 59 additions & 0 deletions crates/lib/src/install/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ pub(crate) struct BasicFilesystems {
// pub(crate) esp: Option<FilesystemCustomization>,
}

/// Configuration for ostree repository
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub(crate) struct Ostree {
/// Boot Loader Spec entries that should append arguments only for non-default entries
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) bls_append_except_default: Option<String>,
}

/// The serialized [install] section
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename = "install", rename_all = "kebab-case", deny_unknown_fields)]
Expand All @@ -73,6 +82,8 @@ pub(crate) struct InstallConfiguration {
pub(crate) kargs: Option<Vec<String>>,
/// Supported architectures for this configuration
pub(crate) match_architectures: Option<Vec<String>>,
/// Ostree repository configuration
pub(crate) ostree: Option<Ostree>,
}

fn merge_basic<T>(s: &mut Option<T>, o: Option<T>, _env: &EnvProperties) {
Expand Down Expand Up @@ -119,6 +130,13 @@ impl Mergeable for BasicFilesystems {
}
}

impl Mergeable for Ostree {
/// Apply any values in other, overriding any existing values in `self`.
fn merge(&mut self, other: Self, env: &EnvProperties) {
merge_basic(&mut self.bls_append_except_default, other.bls_append_except_default, env)
}
}

impl Mergeable for InstallConfiguration {
/// Apply any values in other, overriding any existing values in `self`.
fn merge(&mut self, other: Self, env: &EnvProperties) {
Expand All @@ -133,6 +151,7 @@ impl Mergeable for InstallConfiguration {
#[cfg(feature = "install-to-disk")]
merge_basic(&mut self.block, other.block, env);
self.filesystem.merge(other.filesystem, env);
self.ostree.merge(other.ostree, env);
if let Some(other_kargs) = other.kargs {
self.kargs
.get_or_insert_with(Default::default)
Expand Down Expand Up @@ -572,4 +591,44 @@ root-fs-type = "xfs"
)
);
}

#[test]
fn test_parse_ostree() {
let env = EnvProperties {
sys_arch: "x86_64".to_string(),
};
let c: InstallConfigurationToplevel = toml::from_str(
r##"[install.ostree]
bls-append-except-default = "console=ttyS0"
"##,
)
.unwrap();
let install = c.install.unwrap();
assert_eq!(
install.ostree.as_ref().unwrap().bls_append_except_default.as_ref().unwrap(),
"console=ttyS0"
);

// Test merging ostree config
let c: InstallConfigurationToplevel = toml::from_str(
r##"[install.ostree]
bls-append-except-default = "console=ttyS0"
"##,
)
.unwrap();
let mut install = c.install.unwrap();
let other = InstallConfigurationToplevel {
install: Some(InstallConfiguration {
ostree: Some(Ostree {
bls_append_except_default: Some("console=tty0".to_string()),
}),
..Default::default()
}),
};
install.merge(other.install.unwrap(), &env);
assert_eq!(
install.ostree.as_ref().unwrap().bls_append_except_default.as_ref().unwrap(),
"console=tty0"
);
}
Comment on lines +596 to +633
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test can be simplified by removing the duplicated TOML parsing. The install variable from the first part of the test can be made mutable and reused for the merge test.

    fn test_parse_ostree() {
        let env = EnvProperties {
            sys_arch: "x86_64".to_string(),
        };
        let c: InstallConfigurationToplevel = toml::from_str(
            r##"[install.ostree]
bls-append-except-default = "console=ttyS0"
"##,
        )
        .unwrap();
        let mut install = c.install.unwrap();
        assert_eq!(
            install.ostree.as_ref().unwrap().bls_append_except_default.as_ref().unwrap(),
            "console=ttyS0"
        );

        // Test merging ostree config
        let other = InstallConfigurationToplevel {
            install: Some(InstallConfiguration {
                ostree: Some(Ostree {
                    bls_append_except_default: Some("console=tty0".to_string()),
                }),
                ..Default::default()
            }),
        };
        install.merge(other.install.unwrap(), &env);
        assert_eq!(
            install.ostree.as_ref().unwrap().bls_append_except_default.as_ref().unwrap(),
            "console=tty0"
        );
    }

}
Loading