Skip to content

--build-host option in nh is misleading compared to nixos-rebuild #428

@c2fc2f

Description

@c2fc2f

The --build-host option in nh does not behave the same way as in nixos-rebuild, which makes it confusing and arguably useless in its current state.

Behavior in nh

When using --build-host, nh simply forwards the host to nix build --builders:

This means that the SSH connection is initiated by the nix-daemon (running as root), in a non-interactive environment.
As a consequence, if the SSH key used to connect to the builder requires a passphrase, it must already be unlocked and available in root’s SSH agent. Since nix-daemon does not have access to the user’s SSH agent, this often fails unless you use a passphrase-less key or preload it into an agent that root can access.

See also: nix.dev distributed builds

Behavior in nixos-rebuild

In contrast, nixos-rebuild’s --build-host works differently:

  • It opens an SSH connection as the user running the command, in an interactive environment (so it has access to the user’s SSH agent, or the user can even type the passphrase if necessary).
  • It then transfers the system closure to the build host via that connection and launches the build remotely.

Relevant code:

Why this is problematic

  • In nh, --build-host is effectively just an alias for --builders.
  • This is misleading, because it gives the impression that it behaves like nixos-rebuild --build-host, when in reality it does not.
  • For many users, this makes nh --build-host unusable unless they set up special conditions (e.g. SSH keys without passphrases available to root).

Conclusion

There are two possible ways forward:

  1. Remove the --build-host option from nh to avoid confusion.
  2. Reimplement it so that it matches the expected semantics from nixos-rebuild, i.e. opening the SSH connection as the user in an interactive environment, transferring the system closure, and building remotely.

Related discussions

Maintainers

@NotAShelf
@cramt


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions