Skip to content

Commit f61db4f

Browse files
authored
Merge branch 'nix-community:master' into notifications
2 parents 8719d49 + 440d3a6 commit f61db4f

File tree

5 files changed

+62
-20
lines changed

5 files changed

+62
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ be put in the "Changed" section or, if it's just to remove code or
1414
functionality, under the "Removed" section.
1515
-->
1616

17-
## Unreleased
17+
## 4.2.0
1818

1919
### Changed
2020

@@ -50,8 +50,8 @@ functionality, under the "Removed" section.
5050
`run0` and a fallback `pkexec` strategies will be attempted if the system does
5151
not use `sudo`.
5252
- Nh will correctly prompt you for your `sudo` password while deploying
53-
remotely. This helps mitigate the need to allow password-less `sudo` on
54-
the target host to deploy remotely.
53+
remotely. This helps mitigate the need to allow password-less `sudo` on the
54+
target host to deploy remotely.
5555

5656
### Fixed
5757

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ members = [ ".", "xtask" ]
55
[workspace.package]
66
edition = "2024"
77
rust-version = "1.86.0"
8-
version = "4.2.0-beta4"
8+
version = "4.2.0"
99

1010
[workspace.dependencies.clap]
1111
features = [ "cargo", "color", "derive", "env", "unstable-styles" ]
@@ -16,7 +16,7 @@ name = "nh"
1616
license = "EUPL-1.2"
1717
repository = "https://github.com/nix-community/nh"
1818
description = "Yet Another Nix Helper"
19-
keywords = [ "nix", "helper" ]
19+
keywords = [ "nix", "nixos", "nix-darwin", "helper", "CLI" ]
2020
readme = "README.md"
2121
version.workspace = true
2222
edition.workspace = true
@@ -46,7 +46,7 @@ reqwest = { default-features = false, features = [
4646
"blocking",
4747
"json",
4848
], version = "0.12.23" }
49-
secrecy = { version = "0.8.0", features = [ "serde" ] }
49+
secrecy = { version = "0.10.3", features = [ "serde" ] }
5050
semver = "1.0.26"
5151
serde = { features = [ "derive" ], version = "1.0.219" }
5252
serde_json = "1.0.143"

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,54 @@ The config would look like this:
215215
}
216216
```
217217

218+
## Environment variables
219+
220+
NH supports several environment variables to control command behaviour. Some of
221+
the common variables that you may encounter or choose to employ are as follows:
222+
223+
- `NH_NO_CHECKS`
224+
- When set (any non-empty value), skips startup checks such as Nix version and
225+
experimental feature validation. Useful for generating completions or
226+
running in constrained build environments. You can also consider this an
227+
"expert flag" that you can set for a non-zero performance benefit. It
228+
assumes you know what you are doing.
229+
230+
- `NH_FLAKE`
231+
- Preferred flake path/reference used by NH when running flake-based commands.
232+
Historically `FLAKE` was used; NH will migrate `FLAKE` into `NH_FLAKE` if
233+
present and the specific `NH_*_FLAKE` vars are not set.
234+
235+
- `NH_OS_FLAKE`, `NH_HOME_FLAKE`, `NH_DARWIN_FLAKE`
236+
- Command-specific flake references for `os`, `home`, and `darwin` commands
237+
respectively. If present they take precedence over `NH_FLAKE`.
238+
239+
- `NH_SUDO_ASKPASS`
240+
- Path to a program used as `SUDO_ASKPASS` when NH self-elevates with `sudo`.
241+
If set and `sudo` is used for elevation, NH will pass `-A` to `sudo` and set
242+
`SUDO_ASKPASS` accordingly.
243+
244+
- `NH_PRESERVE_ENV`
245+
- Controls whether environment variables marked for preservation are passed to
246+
elevated commands. Set to `"0"` to disable preservation, `"1"` to force
247+
preservation. If unset, preservation defaults to enabled.
248+
249+
- `NH_LOG`
250+
- Sets the tracing/log filter for NH. This uses the same format as
251+
`tracing_subscriber` env filters (for example: `nh=trace`).
252+
253+
- `NH_NOM`
254+
- Control whether `nom` (nix-output-monitor) should be enabled for the build
255+
processes. Equivalent of `--no-nom`.
256+
257+
### Notes
258+
259+
- Any environment variables prefixed with `NH_` are explicitly propagated by NH
260+
to commands when appropriate.
261+
- For backwards compatibility, if `FLAKE` is present and none of the
262+
command-specific `NH_*_FLAKE` variables exist, NH will set `NH_FLAKE` from
263+
`FLAKE` and emit a warning recommending migration to `NH_FLAKE`. `FLAKE` will
264+
be removed in the future versions of NH.
265+
218266
## Hacking
219267

220268
Contributions are always welcome. To get started, just clone the repository and

src/commands.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ impl ElevationStrategy {
126126
/// # Returns
127127
///
128128
/// * `Result<PathBuf>` - The absolute path to the privilege elevation program
129-
/// binary or an error if a
130-
/// program can't be found.
129+
/// binary or an error if a program can't be found.
131130
fn choice() -> Result<PathBuf> {
132131
const STRATEGIES: [&str; 4] = ["doas", "sudo", "run0", "pkexec"];
133132

@@ -368,12 +367,7 @@ impl Command {
368367
// "1" to force, unset defaults to force
369368
let preserve_env = std::env::var("NH_PRESERVE_ENV")
370369
.as_deref()
371-
.map(|x| {
372-
match x {
373-
"0" => false,
374-
_ => true,
375-
}
376-
})
370+
.map(|x| !matches!(x, "0"))
377371
.unwrap_or(true);
378372

379373
// Insert 'env' command to explicitly pass environment variables to the
@@ -463,7 +457,7 @@ impl Command {
463457
.without_confirmation()
464458
.prompt()
465459
.context("Failed to read sudo password")?;
466-
let secret_password = SecretString::new(password);
460+
let secret_password = SecretString::new(password.into());
467461
cache_password(host, secret_password.clone());
468462
Some(secret_password)
469463
}
@@ -1189,7 +1183,7 @@ mod tests {
11891183
#[test]
11901184
fn test_ssh_wrap_with_password() {
11911185
let cmd = subprocess::Exec::cmd("echo").arg("hello");
1192-
let password = SecretString::new("testpass".to_string());
1186+
let password = SecretString::new("testpass".into());
11931187
let wrapped = ssh_wrap(cmd, Some("user@host"), Some(&password));
11941188

11951189
let cmdline = wrapped.to_cmdline_lossy();

0 commit comments

Comments
 (0)