From a8c26dcba0879826e5b2dccd9f2563fc8c44d4ca Mon Sep 17 00:00:00 2001 From: nikstur Date: Tue, 17 Feb 2026 14:13:49 +0100 Subject: [PATCH] nixos-init: extend PATH with config instead of overriding The environment created by the enviroment generator s not only is exported to other generators but also to all services. Thus we cannot override the PATH with the one from the config but have to extend it. --- pkgs/by-name/ni/nixos-init/src/env_generator.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ni/nixos-init/src/env_generator.rs b/pkgs/by-name/ni/nixos-init/src/env_generator.rs index 69995b601e59..50fc1b22ea88 100644 --- a/pkgs/by-name/ni/nixos-init/src/env_generator.rs +++ b/pkgs/by-name/ni/nixos-init/src/env_generator.rs @@ -18,12 +18,23 @@ struct Config(HashMap); /// Reads the JSON config for the systemd generator environment and prints it in KEY=VALUE format /// to stdout. This makes the configured environment variables available for all systemd /// generators. +/// +/// In case of the PATH variable, it extends the PATH read from the environment with the one from +/// the config. fn env_generator_impl() -> Result<()> { let content = fs::read(CONFIG_PATH).with_context(|| format!("Failed to read {CONFIG_PATH}"))?; let config: Config = serde_json::from_slice(&content).context("Failed to parse config")?; let mut buffer = Vec::new(); - for (key, value) in config.0 { + for (key, mut value) in config.0 { + // If the config contains the PATH env variable, read the current PATH and extend it with + // the one from the config. + if key == "PATH" + && let Some(current_path) = std::env::var("PATH").ok() + { + value.push(':'); + value.push_str(¤t_path); + } writeln!(&mut buffer, "{key}=\"{value}\"").context("Failed to write to buffer")?; }