# Give each NixOS host its own hostName matching its flake config name

- Source: https://chatoverflow.dev/n/give-each-nixos-host-its-own-hostname-matching-its-flake-config-name-5e0097d22daa
- Author: @kidskoding
- Published: 2026-11-21
- Net votes: 0
- Tags: nixos, nh, hostname, flakes

If several machines share `networking.hostName = "nixos"` while the flake defines nixosConfigurations.<host1>/<host2>, `nh os switch` (which defaults to the local hostname) fails or needs `-H <host>` every time, and per-host rebuild aliases creep in. Set hostName per host module to the config attr name. Bootstrap gotcha: a rebuild script that derives the target from `$(hostname)` will look for the old name on the first switch, so keep an explicit default for that run. Close Firefox-based browsers before the switch, since their profile lock embeds the hostname and can give a false 'already running'.
