diff options
author | Michael Weiss <michael@primeos.dev> | 2020-10-10 11:30:47 +0000 |
---|---|---|
committer | Michael Weiss <dev.primeos@gmail.com> | 2020-10-12 15:27:31 +0200 |
commit | 971f0b45ef7129073a6e996f1c63a1f2b470a7e0 (patch) | |
tree | 8c9448c473e9f957e465e2c881095cec488ca9fe /nixos/tests/hostname.nix | |
parent | b13bb2402be929ad85bb96e5f7ef64f66892e903 (diff) |
nixos/networking: Add a read-only option for the FQDN
This is a convenience option that can be used to quickly obtain the configured FQDN.
Diffstat (limited to 'nixos/tests/hostname.nix')
-rw-r--r-- | nixos/tests/hostname.nix | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/nixos/tests/hostname.nix b/nixos/tests/hostname.nix index 3b87303d73e74..8a77afc21733f 100644 --- a/nixos/tests/hostname.nix +++ b/nixos/tests/hostname.nix @@ -7,9 +7,12 @@ with import ../lib/testing-python.nix { inherit system pkgs; }; with pkgs.lib; let - makeHostNameTest = hostName: domain: + makeHostNameTest = hostName: domain: fqdnOrNull: let fqdn = hostName + (optionalString (domain != null) ".${domain}"); + getStr = str: # maybeString2String + let res = builtins.tryEval str; + in if (res.success && res.value != null) then res.value else "null"; in makeTest { name = "hostname-${fqdn}"; @@ -26,13 +29,16 @@ let ]; }; - testScript = '' + testScript = { nodes, ... }: '' start_all() machine = ${hostName} machine.wait_for_unit("network-online.target") + # Test if NixOS computes the correct FQDN (either a FQDN or an error/null): + assert "${getStr nodes.machine.config.networking.fqdn}" == "${getStr fqdnOrNull}" + # The FQDN, domain name, and hostname detection should work as expected: assert "${fqdn}" == machine.succeed("hostname --fqdn").strip() assert "${optionalString (domain != null) domain}" == machine.succeed("dnsdomainname").strip() @@ -60,7 +66,7 @@ let in { - noExplicitDomain = makeHostNameTest "ahost" null; + noExplicitDomain = makeHostNameTest "ahost" null null; - explicitDomain = makeHostNameTest "ahost" "adomain"; + explicitDomain = makeHostNameTest "ahost" "adomain" "ahost.adomain"; } |