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.systemctl("start network-online.target")
38 machine.wait_for_unit("network-online.target")
40 # Test if NixOS computes the correct FQDN (either a FQDN or an error/null):
41 assert "${getStr nodes.machine.networking.fqdn}" == "${getStr fqdnOrNull}"
43 # The FQDN, domain name, and hostname detection should work as expected:
44 assert "${fqdn}" == machine.succeed("hostname --fqdn").strip()
45 assert "${optionalString (domain != null) domain}" == machine.succeed("dnsdomainname").strip()
49 'hostnamectl status | grep "Static hostname" | cut -d: -f2'
53 # 127.0.0.1 and ::1 should resolve back to "localhost":
55 "localhost" == machine.succeed("getent hosts 127.0.0.1 | awk '{print $2}'").strip()
57 assert "localhost" == machine.succeed("getent hosts ::1 | awk '{print $2}'").strip()
59 # 127.0.0.2 should resolve back to the FQDN and hostname:
60 fqdn_and_host_name = "${optionalString (domain != null) "${hostName}.${domain} "}${hostName}"
63 == machine.succeed("getent hosts 127.0.0.2 | awk '{print $2,$3}'").strip()
70 noExplicitDomain = makeHostNameTest "ahost" null null;
72 explicitDomain = makeHostNameTest "ahost" "adomain" "ahost.adomain";