From 7c11feab425ff374a96035ae834bee8796ddc099 Mon Sep 17 00:00:00 2001 From: Alex Hamilton <1622250+Aehmlo@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:05:59 -0400 Subject: [PATCH 1/2] Add configuration/hostname/specialisation env vars This revision introduces a handful of environmental variables to enable fallbacks similar to the NH_FLAKE environmental variable family: * NH_OS_HOSTNAME, * NH_OS_SPECIALISATION, * NH_HOME_CONFIGURATION, * NH_HOME_SPECIALISATION, and * NH_DARWIN_HOSTNAME. --- CHANGELOG.md | 3 +++ src/interface.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f686a7..3e1c5481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ - `nh darwin switch` now shows the output from the `darwin-rebuild` activation. This allows you to see more details about the activation from `nix-darwin`, as well as `Home Manager`. +- The `NH_OS_HOSTNAME`, `NH_OS_SPECIALISATION`, `NH_HOME_CONFIGURATION`, + `NH_HOME_SPECIALISATION`, and `NH_DARWIN_HOSTNAME` environmental variables are + now consulted when determining what attribute/specialisation to use. ### Fixed diff --git a/src/interface.rs b/src/interface.rs index 46fdfb76..8bd02ef3 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -185,11 +185,11 @@ pub struct OsRebuildArgs { pub update_args: UpdateArgs, /// When using a flake installable, select this hostname from nixosConfigurations - #[arg(long, short = 'H', global = true)] + #[arg(long, short = 'H', global = true, env = "NH_OS_HOSTNAME")] pub hostname: Option, /// Explicitly select some specialisation - #[arg(long, short)] + #[arg(long, short, env = "NH_OS_SPECIALISATION")] pub specialisation: Option, /// Ignore specialisations @@ -236,7 +236,7 @@ pub struct OsRollbackArgs { pub ask: bool, /// Explicitly select some specialisation - #[arg(long, short)] + #[arg(long, short, env = "NH_OS_SPECIALISATION")] pub specialisation: Option, /// Ignore specialisations @@ -280,7 +280,7 @@ pub struct OsReplArgs { pub installable: Installable, /// When using a flake installable, select this hostname from nixosConfigurations - #[arg(long, short = 'H', global = true)] + #[arg(long, short = 'H', global = true, env = "NH_OS_HOSTNAME")] pub hostname: Option, } @@ -443,11 +443,11 @@ pub struct HomeRebuildArgs { /// Name of the flake homeConfigurations attribute, like username@hostname /// /// If unspecified, will try @ and - #[arg(long, short)] + #[arg(long, short, env = "NH_HOME_CONFIGURATION")] pub configuration: Option, /// Explicitly select some specialisation - #[arg(long, short)] + #[arg(long, short, env = "NH_HOME_SPECIALISATION")] pub specialisation: Option, /// Ignore specialisations @@ -483,7 +483,7 @@ pub struct HomeReplArgs { /// Name of the flake homeConfigurations attribute, like username@hostname /// /// If unspecified, will try @ and - #[arg(long, short)] + #[arg(long, short, env = "NH_HOME_CONFIGURATION")] pub configuration: Option, /// Extra arguments passed to nix repl @@ -556,7 +556,7 @@ pub struct DarwinRebuildArgs { pub update_args: UpdateArgs, /// When using a flake installable, select this hostname from darwinConfigurations - #[arg(long, short = 'H', global = true)] + #[arg(long, short = 'H', global = true, env = "NH_DARWIN_HOSTNAME")] pub hostname: Option, /// Extra arguments passed to nix build @@ -582,7 +582,7 @@ pub struct DarwinReplArgs { pub installable: Installable, /// When using a flake installable, select this hostname from darwinConfigurations - #[arg(long, short = 'H', global = true)] + #[arg(long, short = 'H', global = true, env = "NH_DARWIN_HOSTNAME")] pub hostname: Option, } From f8bd6f3b37f5555dea95192add42a7405bb07ea1 Mon Sep 17 00:00:00 2001 From: Alex Hamilton <1622250+Aehmlo@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:20:05 -0400 Subject: [PATCH 2/2] Update debug log wording Since there's no way to distinguish between "the user provided a home configuration with --configuration" from "the user provided a home configuration using NH_HOME_CONFIGURATION," this revision updates debug log wording appropriately. --- src/home.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/home.rs b/src/home.rs index 9fdc26a4..e0e4dd0c 100644 --- a/src/home.rs +++ b/src/home.rs @@ -243,7 +243,10 @@ where })?; if check_res.map(|s| s.trim().to_owned()).as_deref() == Some("true") { - debug!("Using explicit configuration from flag: {}", config_name); + debug!( + "Using explicit configuration from flag/environment: {}", + config_name + ); attribute.push(config_name); if push_drv { attribute.extend(toplevel.clone());