diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index d20fbc1cc66..498c0a37783 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -68,8 +68,8 @@ rec { # the first interface (i.e. the first network in its # virtualisation.vlans option). networking.extraHosts = flip concatMapStrings machines - (m: let config = (getAttr m nodes).config; in - optionalString (config.networking.primaryIPAddress != "") + (m': let config = (getAttr m' nodes).config; in + optionalString (m.first != m' && config.networking.primaryIPAddress != "") ("${config.networking.primaryIPAddress} " + "${config.networking.hostName}\n")); diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index 12ac6f6f9a6..d355d705a24 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -59,6 +59,12 @@ subtest "override-env-var", sub { $machine->succeed('[ "$EDITOR" = emacs ]'); }; + + # Test whether hostname (and by extension nss_myhostname) works. + subtest "hostname", sub { + $machine->succeed('[ "`hostname`" = machine ]'); + $machine->succeed('[ "`hostname -s`" = machine ]'); + }; ''; }