From 8924995cb46e4033af31147725ef8820b975e596 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Mon, 22 Dec 2025 11:43:46 +0200 Subject: [PATCH] nixos-init: accept "/" as the prefix, to allow re-use outside of the initrd --- pkgs/by-name/ni/nixos-init/src/activate.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/ni/nixos-init/src/activate.rs b/pkgs/by-name/ni/nixos-init/src/activate.rs index 048b037d9a51..6b5ac049a528 100644 --- a/pkgs/by-name/ni/nixos-init/src/activate.rs +++ b/pkgs/by-name/ni/nixos-init/src/activate.rs @@ -1,4 +1,7 @@ -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use anyhow::{Context, Result}; @@ -9,7 +12,8 @@ use crate::{config::Config, fs::atomic_symlink}; /// This runs both during boot and during re-activation initiated by switch-to-configuration. pub fn activate(prefix: &str, toplevel: impl AsRef, config: &Config) -> Result<()> { log::info!("Setting up /run/current-system..."); - atomic_symlink(&toplevel, format!("{prefix}/run/current-system"))?; + let system_path = PathBuf::from(prefix).join("run/current-system"); + atomic_symlink(&toplevel, system_path)?; log::info!("Setting up modprobe..."); setup_modprobe(&config.modprobe_binary)?; @@ -92,10 +96,9 @@ fn setup_firmware_search_path(firmware: impl AsRef) -> Result<()> { /// /// We do this here accidentally. `/usr/bin/env` is currently load-bearing for `NixOS`. fn setup_usrbinenv(prefix: &str, env_binary: impl AsRef) -> Result<()> { - const USRBINENV_PATH: &str = "/usr/bin/env"; - - fs::create_dir_all(format!("{prefix}/usr/bin")).context("Failed to create /usr/bin")?; - atomic_symlink(&env_binary, format!("{prefix}{USRBINENV_PATH}")) + let usrbin_path = PathBuf::from(prefix).join("usr/bin"); + fs::create_dir_all(&usrbin_path).context("Failed to create /usr/bin")?; + atomic_symlink(&env_binary, usrbin_path.join("env")) } /// Setup /bin/sh. @@ -103,6 +106,6 @@ fn setup_usrbinenv(prefix: &str, env_binary: impl AsRef) -> Result<()> { /// `/bin/sh` is an essential part of a Linux system as this path is hardcoded in the `system()` call /// from libc. See `man systemd(3)`. fn setup_binsh(prefix: &str, sh_binary: impl AsRef) -> Result<()> { - const BINSH_PATH: &str = "/bin/sh"; - atomic_symlink(&sh_binary, format!("{prefix}{BINSH_PATH}")) + let binsh_path = PathBuf::from(prefix).join("bin/sh"); + atomic_symlink(&sh_binary, binsh_path) }