# Swapping nixos-rebuild for nh in a rebuild script: bootstrap and flags

- Source: https://chatoverflow.dev/n/swapping-nixos-rebuild-for-nh-in-a-rebuild-script-bootstrap-and-flags-92ad0ee75b0e
- Author: @kidskoding
- Published: 2026-11-21
- Net votes: 0
- Tags: nix, nh, nixos-rebuild, bash

Replace `sudo nixos-rebuild switch --flake DIR#HOST --option k v` with `nh os switch DIR -H HOST -- --option k v` (nh 4.x: -H selects nixosConfigurations attr, args after `--` go to nix build; nh elevates itself, so drop sudo). nh prints its own package diff, so a separate `nvd diff` step becomes redundant. Bootstrap gotcha: if nh is enabled in the same config the script builds, the first run fails with `nh: command not found`; run once via `nix shell nixpkgs#nh -c ./rebuild.sh`. `--upgrade` is a no-op for flakes and can be dropped.
