Skip to content

Commit 1d2f9fd

Browse files
committed
bwrap: Add set_default_path() helper for standard PATH
Extract the repeated PATH environment variable string into a set_default_path() method on BwrapCmd. The bwrap environment may not have a complete PATH, causing tools like bootupctl or sfdisk to not be found. This consolidates the workaround into one place. Assisted-by: OpenCode (Claude Opus 4)
1 parent 500678c commit 1d2f9fd

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

crates/lib/src/bootloader.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs::create_dir_all;
22
use std::process::Command;
33

4-
use anyhow::{Context, Result, anyhow, bail};
4+
use anyhow::{anyhow, bail, Context, Result};
55
use bootc_utils::{BwrapCmd, CommandRunExt};
66
use camino::Utf8Path;
77
use cap_std_ext::cap_std::fs::Dir;
@@ -10,7 +10,7 @@ use fn_error_context::context;
1010

1111
use bootc_mount as mount;
1212

13-
use crate::bootc_composefs::boot::{SecurebootKeys, mount_esp};
13+
use crate::bootc_composefs::boot::{mount_esp, SecurebootKeys};
1414
use crate::{discoverable_partition_specification, utils};
1515

1616
/// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel)
@@ -86,10 +86,7 @@ fn bootupd_supports_filesystem(rootfs: &Utf8Path, deployment_path: Option<&str>)
8686
let output = if let Some(deploy) = deployment_path {
8787
let target_root = rootfs.join(deploy);
8888
BwrapCmd::new(&target_root)
89-
.setenv(
90-
"PATH",
91-
"/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
92-
)
89+
.set_default_path()
9390
.run_get_string(help_args)?
9491
} else {
9592
Command::new("bootupctl")
@@ -206,14 +203,8 @@ pub(crate) fn install_via_bootupd(
206203
}
207204

208205
// The $PATH in the bwrap env is not complete enough for some images
209-
// so we inject a reasonnable default.
210-
// This is causing bootupctl and/or sfdisk binaries
211-
// to be not found with fedora 43.
212-
cmd.setenv(
213-
"PATH",
214-
"/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
215-
)
216-
.run(bwrap_args)
206+
// so we inject a reasonable default.
207+
cmd.set_default_path().run(bwrap_args)
217208
} else {
218209
// Running directly without chroot
219210
Command::new("bootupctl")

crates/utils/src/bwrap.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ impl<'a> BwrapCmd<'a> {
5959
self
6060
}
6161

62+
/// Set $PATH to a reasonable default for finding system binaries.
63+
///
64+
/// The bwrap environment may not have a complete $PATH, causing
65+
/// tools like bootupctl or sfdisk to not be found. This sets a
66+
/// default that covers the standard binary directories.
67+
pub fn set_default_path(self) -> Self {
68+
self.setenv(
69+
"PATH",
70+
"/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
71+
)
72+
}
73+
6274
/// Build the bwrap `Command` with all bind mounts, env vars, and args.
6375
fn build_command<S: AsRef<OsStr>>(&self, args: impl IntoIterator<Item = S>) -> Command {
6476
let mut cmd = Command::new("bwrap");

0 commit comments

Comments
 (0)