Announcing NH 4.3.0

NH 4.3.0

Hey all,

It is my pleasure to announce the release of NH 4.3.0 with the extensive
support of @faukah, featuring various bugfixes, new features, and code cleanup.
As we cannot cover everything new in this document, here are some of the
highlights compiled from our changelog to give you an idea of what’s new:

Highlights

  • Remote deployments:
    Platform commands (nh os, nh home, nh darwin) now support SSH-based
    remote builds via --build-host. The flag now uses proper remote build
    semantics: derivations are copied to the remote host via nix-copy-closure,
    built remotely, and results are transferred back. This matches nixos-rebuild
    behavior, and is significantly more robust than the previous implementation
    where --build-host would use Nix’s --builders flag inefficiently.
    (#428,
    #497)

  • Image building:
    A new nh os build-image subcommand for building a disk-image variant is now
    available. A variant can be selected using the --image-variant flag. All
    variants in the config.system.build.images attribute set are supported.

  • Improved VMs:
    A --run flag was added to nh os build-vm, which allows immediately
    starting a built VM after the build is complete. This can be chained with
    other build-vm flags such as --with-bootloader.

  • Even nicer diffing:
    dix, the crate powering the package diff
    shown after every rebuild, has seen significant work to make nh’s diffs more
    informative and reliable.

  • Better activation log UX:
    Platform commands (nh os, nh home, nh darwin) now accept a
    --show-activation-logs flag that displays activation output at the end.
    While activation output is now hidden to reduce noise by default, this flag
    can be used to replicate the activation behaviour from nixos-rebuild where
    failing units are displayed at the end.

    • Breaking change: Activation output is now hidden by default on Home
      Manager and Darwin. The logs were previously always visible.
    • The flag can be set globally via the NH_SHOW_ACTIVATION_LOGS environment
      variable.
  • Better search:
    nh search displays a link to the package.nix file on the nixpkgs GitHub,
    and also fixes the existing links so that they no longer brokenly point to a
    non-existent file path on Nix flake systems.

Fixes

  • Graceful out-of-sync profiles:
    nh os info now gracefully handles out-of-sync profiles. When a previous
    switch failed during activation (e.g., a Systemd service failed), the profile
    may be out of sync with /run/current-system while in “test mode” via
    switch-to-configuration test. NH now warns about this condition and displays
    version info from the running system instead of failing with an error.

  • Proper installable resolution:
    nh now properly resolves installables, fixing issues when e.g. multiple
    NH_{FLAKE,FILE,{OS,HOME_DARWIN}_FLAKE} environment variables are set.

  • Better cleaning when using direnv:
    Direnv caches in alternative locations (e.g.,
    $XDG_CACHE_DIR/direnv/layouts) will now be detected during nh clean.


As always, a very big thank you to everyone NH, and especially to those who took
the time to contribute NH via issues, pull requests, discussions or other means
of feedback. Special thanks to @faukah for making this release possible and his
stubborn efforts to make the codebase more maintainable. Here is to more
exciting releases.

Cheers,

- NotAShelf

29 Likes

Is it possible to pass a custom attribute for the system to switch to when not using flakes. I’m not using flakes but have all systems in different attribute sets in my config. I currently use nixos-rebuild switch -A nixosConfigurations.systemA.

Yeah, you can use the NH_ATTRP variable or the optional ATTRPATH arg:

Usage: nh os build [OPTIONS] [INSTALLABLE] [-- <EXTRA_ARGS>...]

Arguments:
  [INSTALLABLE]
          Which installable to use.
          Nix accepts various kinds of installables:

          [FLAKEREF[#ATTRPATH]]
              Flake reference with an optional attribute path.
              [env: NH_FLAKE=/home/tlater/.local/src/dotfiles]
              [env: NH_OS_FLAKE=]
              [env: NH_HOME_FLAKE=]
              [env: NH_DARWIN_FLAKE=]

          -f, --file <FILE> [ATTRPATH]
              Path to file with an optional attribute path.
              [env: NH_FILE=]
              [env: NH_ATTRP=]

          -e, --expr <EXPR> [ATTRPATH]
              Nix expression with an optional attribute path.

          [PATH]
              Path or symlink to a /nix/store path


  [EXTRA_ARGS]...
          Extra arguments passed to nix build
2 Likes