nixos-init: handle kernels without module support

Checks if MODPROBE_PATH exists and only then tries to write to it.
Otherwise it fails and logs that MODPROBE_PATH doesn't exist.

This enables using kernels that do not support loading modules.
This commit is contained in:
nikstur
2025-09-28 23:07:29 +02:00
parent ef2303d56c
commit e29ad16baa
+16 -9
View File
@@ -42,16 +42,21 @@ fn setup_modprobe(modprobe_binary: impl AsRef<Path>) -> Result<()> {
// a procfs in a chroot would.
const MODPROBE_PATH: &str = "/proc/sys/kernel/modprobe";
fs::write(
MODPROBE_PATH,
modprobe_binary.as_ref().as_os_str().as_encoded_bytes(),
)
.with_context(|| {
format!(
"Failed to populate modprobe path with {}",
modprobe_binary.as_ref().display()
if Path::new(MODPROBE_PATH).exists() {
fs::write(
MODPROBE_PATH,
modprobe_binary.as_ref().as_os_str().as_encoded_bytes(),
)
})?;
.with_context(|| {
format!(
"Failed to populate modprobe path with {}",
modprobe_binary.as_ref().display()
)
})?;
} else {
log::info!("{MODPROBE_PATH} doesn't exist. Not populating it...");
}
Ok(())
}
@@ -74,6 +79,8 @@ fn setup_firmware_search_path(firmware: impl AsRef<Path>) -> Result<()> {
firmware.as_ref().display()
)
})?;
} else {
log::info!("{FIRMWARE_SERCH_PATH} doesn't exist. Not populating it...");
}
Ok(())