1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
10 makeHostNameTest = hostName: domain: fqdnOrNull:
12 fqdn = hostName + (optionalString (domain != null) ".${domain}");
13 getStr = str: # maybeString2String
14 let res = builtins.tryEval str;
15 in if (res.success && res.value != null) then res.value else "null";
18 name = "hostname-${fqdn}";
19 meta = with pkgs.lib.maintainers; {
20 maintainers = [ primeos blitz ];
23 nodes.machine = { lib, ... }: {
24 networking.hostName = hostName;
25 networking.domain = domain;
27 environment.systemPackages = with pkgs; [
32 testScript = { nodes, ... }: ''
37 machine.wait_for_unit("network-online.target")
39 # Test if NixOS computes the correct FQDN (either a FQDN or an error/null):
40 assert "${getStr nodes.machine.config.networking.fqdn}" == "${getStr fqdnOrNull}"
42 # The FQDN, domain name, and hostname detection should work as expected:
43 assert "${fqdn}" == machine.succeed("hostname --fqdn").strip()
44 assert "${optionalString (domain != null) domain}" == machine.succeed("dnsdomainname").strip()
48 'hostnamectl status | grep "Static hostname" | cut -d: -f2'
52 # 127.0.0.1 and ::1 should resolve back to "localhost":
54 "localhost" == machine.succeed("getent hosts 127.0.0.1 | awk '{print $2}'").strip()
56 assert "localhost" == machine.succeed("getent hosts ::1 | awk '{print $2}'").strip()
58 # 127.0.0.2 should resolve back to the FQDN and hostname:
59 fqdn_and_host_name = "${optionalString (domain != null) "${hostName}.${domain} "}${hostName}"
62 == machine.succeed("getent hosts 127.0.0.2 | awk '{print $2,$3}'").strip()
69 noExplicitDomain = makeHostNameTest "ahost" null null;
71 explicitDomain = makeHostNameTest "ahost" "adomain" "ahost.adomain";