From e29ad16baa0efa93efada14e65c0607f46d85419 Mon Sep 17 00:00:00 2001 From: nikstur Date: Sun, 28 Sep 2025 23:04:35 +0200 Subject: [PATCH] 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. --- pkgs/by-name/ni/nixos-init/src/activate.rs | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/ni/nixos-init/src/activate.rs b/pkgs/by-name/ni/nixos-init/src/activate.rs index c8fe22447899..048b037d9a51 100644 --- a/pkgs/by-name/ni/nixos-init/src/activate.rs +++ b/pkgs/by-name/ni/nixos-init/src/activate.rs @@ -42,16 +42,21 @@ fn setup_modprobe(modprobe_binary: impl AsRef) -> 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) -> Result<()> { firmware.as_ref().display() ) })?; + } else { + log::info!("{FIRMWARE_SERCH_PATH} doesn't exist. Not populating it..."); } Ok(())