Yet another Nix CLI helper. [Maintainers=@NotAShelf]
Find a file
raf 894bb7ebf3
Merge pull request #263 from nix-community/fix-homes
home: ensure `--configuration` is correctly passed to switch
2025-04-30 16:53:53 +00:00
.github chore: Change update user to GitHub 2025-04-30 14:34:14 +02:00
.vscode nh search local 2023-07-05 12:18:59 +02:00
src home: ensure --configuration is correctly passed to switch 2025-04-30 19:35:02 +03:00
test fix ci script 2024-11-27 11:10:12 +01:00
.envrc add lint to CI 2024-11-18 11:30:39 +01:00
.gitignore better formatting 2022-11-26 20:49:09 +00:00
Cargo.lock chore: 4.0.3 2025-04-30 19:35:03 +03:00
Cargo.toml chore: 4.0.3 2025-04-30 19:35:03 +03:00
CHANGELOG.md docs: 4.0.3 changelog 2025-04-30 19:44:13 +03:00
fix.sh dont use nix fmt 2024-11-27 11:35:27 +01:00
flake.lock nix: switch to current nixos-stable 2025-04-23 18:34:02 +00:00
flake.nix nix: switch to current nixos-stable 2025-04-23 18:34:02 +00:00
LICENSE license 2022-11-04 16:56:35 +01:00
package.nix build with rev 2024-11-27 11:06:49 +01:00
README.md docs: format README; fix typos and wording 2025-04-24 00:11:15 +03:00
rustfmt.toml use nightly rustfmt with rules 2024-11-18 10:52:17 +01:00
shell.nix Dev: add darwin build deps 2024-12-06 08:32:16 +01:00

nh

Because the name "yet-another-nix-helper" was too long to type...

What does it do?

Nh is a modern helper utility that is a take at reimplementing some commands from the NixOS ecosystem. We aim to provide more features and better ergonomics than the existing commands.

We provide several subcommands, such as:

  • os, which reimplements nixos-rebuild, with a tree of builds, diff and confirmation.
  • home, which reimplements home-manager.
  • darwin, which reimplements darwin-rebuild
  • search, a super-fast package searching tool (powered by a ElasticSearch client).
  • clean, my own take at cleaning GC roots from a NixOS system.

This wouldn't be possible without the programs that nh runs under the hood:

nh feature showcase

Installation

The latest, tagged version will is available in Nixpkgs as Nh stable. This repository provides the latest development version of Nh, which you can get from the flake outputs.

nix shell nixpkgs#nh # stable
nix shell github:viperML/nh # dev

NixOS

We provide a NixOS module that integrates nh clean as a service. To enable it, set the following configuration:

{ config, pkgs, ... }:
{
  programs.nh = {
    enable = true;
    clean.enable = true;
    clean.extraArgs = "--keep-since 4d --keep 3";
    flake = "/home/user/my-nixos-config";
  };
}

Nh supports both Flakes and classical NixOS configurations:

  • For flakes, the command is nh os switch /path/to/flake
  • For a classical configuration:
    • nh os switch -f '<nixpkgs/nixos>', or
    • nh os switch -f '<nixpkgs/nixos>' -- -I nixos-config=/path/to/configuration.nix if using a different location than the default.

You might want to check nh os --help for other values and the defaults from environment variables.

Specialisations support

Nh is capable of detecting which specialisation you are running, so it runs the proper activation script. To do so, you need to give Nh some information of the spec that is currently running by writing its name to /etc/specialisation. The config would look like this:

{config, pkgs, ...}: {
  specialisation."foo".configuration = {
    environment.etc."specialisation".text = "foo";
    # ..rest of config
  };

  specialisation."bar".configuration = {
    environment.etc."specialisation".text = "bar";
    # ..rest of config
  };
}

Home-Manager

Home specialisations are read from ~/.local/share/home-manager/specialisation. The config would look like this:

{config, pkgs, ...}: {
  specialisation."foo".configuration = {
    xdg.dataFile."home-manager/specialisation".text = "foo";
    # ..rest of config
  };

  specialisation."bar".configuration = {
    xdg.dataFile."home-manager/specialisation".text = "bar";
    # ..rest of config
  };
}

Status

Dependency status

Packaging status

Hacking

Just clone and nix develop. We also provide a .envrc for Direnv.