NH reimplements some basic nix commands. Adding functionality on top of the existing solutions, like nixos-rebuild, home-manager cli or nix itself.
As the main features:
- Tree of builds with nix-output-manager
- Visualization of the upgrade diff with nvd
- Asking for confirmation before performing activation
nh is available in nixpkgs:
- NixOS search: https://search.nixos.org/packages?channel=unstable&query=nh
- Hydra status:
If you want to get the latest nh version not published to nixpkgs, you can use the flake
{
inputs.nh = {
url = "github:viperML/nh";
inputs.nixpkgs.follows = "nixpkgs"; # override this repo's nixpkgs snapshot
};
}
Then, include it in your environment.systemPackages
or home.packages
by referencing the input:
inputs.nh.packages.<system>.default
nh uses the FLAKE
env variable as a default for os
and home
. This is a shorthand for --flake
in other commands. This saves typing it every time.
For NixOS, configuring it could be as simple as:
environment.sessionVariables.FLAKE = "/home/ayats/Documents/dotfiles";
The nh NixOS modules provides an garbage collection alternative to the default one. Currently you can only get it through the flake.
nixosConfigurations.foo = nixpkgs.lib.nixosSystem {
modules = [
inputs.nh.nixosModules.default
{
nh = {
enable = true;
clean.enable = true;
clean.extraArgs = "--keep-since 4d --keep 3";
};
}
];
}
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
};
}
By default nh uses nix-output-monitor (nom) to show the build log. This can be disabled either by:
- Exporting the environment variable
NH_NOM=0
- Overriding the package:
nh.override { use-nom = false; }
Just nix develop