Merge pull request #100155 from primeos/nixos-add-fqdn-option

nixos/networking: Add a read-only option for the FQDN

authored by Florian Klink and committed by GitHub b2f3bd4d 68b6d6ca

+44 -17
+15 -13
nixos/modules/services/networking/smokeping.nix
··· 124 }; 125 hostName = mkOption { 126 type = types.str; 127 - default = config.networking.hostName; 128 example = "somewhere.example.com"; 129 description = "DNS name for the urls generated in the cgi."; 130 }; ··· 156 ownerEmail = mkOption { 157 type = types.str; 158 default = "no-reply@${cfg.hostName}"; 159 example = "no-reply@yourdomain.com"; 160 description = "Email contact for owner"; 161 }; ··· 239 targetConfig = mkOption { 240 type = types.lines; 241 default = '' 242 - probe = FPing 243 - menu = Top 244 - title = Network Latency Grapher 245 - remark = Welcome to the SmokePing website of xxx Company. \ 246 - Here you will learn all about the latency of our network. 247 - + Local 248 - menu = Local 249 - title = Local Network 250 - ++ LocalMachine 251 - menu = Local Machine 252 - title = This host 253 - host = localhost 254 ''; 255 description = "Target configuration"; 256 };
··· 124 }; 125 hostName = mkOption { 126 type = types.str; 127 + default = config.networking.fqdn; 128 + defaultText = "\${config.networking.fqdn}"; 129 example = "somewhere.example.com"; 130 description = "DNS name for the urls generated in the cgi."; 131 }; ··· 157 ownerEmail = mkOption { 158 type = types.str; 159 default = "no-reply@${cfg.hostName}"; 160 + defaultText = "no-reply@\${hostName}"; 161 example = "no-reply@yourdomain.com"; 162 description = "Email contact for owner"; 163 }; ··· 241 targetConfig = mkOption { 242 type = types.lines; 243 default = '' 244 + probe = FPing 245 + menu = Top 246 + title = Network Latency Grapher 247 + remark = Welcome to the SmokePing website of xxx Company. \ 248 + Here you will learn all about the latency of our network. 249 + + Local 250 + menu = Local 251 + title = Local Network 252 + ++ LocalMachine 253 + menu = Local Machine 254 + title = This host 255 + host = localhost 256 ''; 257 description = "Target configuration"; 258 };
+18
nixos/modules/tasks/network-interfaces.nix
··· 398 ''; 399 }; 400 401 networking.hostId = mkOption { 402 default = null; 403 example = "4e98920d";
··· 398 ''; 399 }; 400 401 + networking.fqdn = mkOption { 402 + readOnly = true; 403 + type = types.str; 404 + default = if (cfg.hostName != "" && cfg.domain != null) 405 + then "${cfg.hostName}.${cfg.domain}" 406 + else throw '' 407 + The FQDN is required but cannot be determined. Please make sure that 408 + both networking.hostName and networking.domain are set properly. 409 + ''; 410 + defaultText = literalExample ''''${networking.hostName}.''${networking.domain}''; 411 + description = '' 412 + The fully qualified domain name (FQDN) of this host. It is the result 413 + of combining networking.hostName and networking.domain. Using this 414 + option will result in an evaluation error if the hostname is empty or 415 + no domain is specified. 416 + ''; 417 + }; 418 + 419 networking.hostId = mkOption { 420 default = null; 421 example = "4e98920d";
+10 -4
nixos/tests/hostname.nix
··· 7 with pkgs.lib; 8 9 let 10 - makeHostNameTest = hostName: domain: 11 let 12 fqdn = hostName + (optionalString (domain != null) ".${domain}"); 13 in 14 makeTest { 15 name = "hostname-${fqdn}"; ··· 26 ]; 27 }; 28 29 - testScript = '' 30 start_all() 31 32 machine = ${hostName} 33 34 machine.wait_for_unit("network-online.target") 35 36 # The FQDN, domain name, and hostname detection should work as expected: 37 assert "${fqdn}" == machine.succeed("hostname --fqdn").strip() 38 assert "${optionalString (domain != null) domain}" == machine.succeed("dnsdomainname").strip() ··· 60 61 in 62 { 63 - noExplicitDomain = makeHostNameTest "ahost" null; 64 65 - explicitDomain = makeHostNameTest "ahost" "adomain"; 66 }
··· 7 with pkgs.lib; 8 9 let 10 + makeHostNameTest = hostName: domain: fqdnOrNull: 11 let 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"; 16 in 17 makeTest { 18 name = "hostname-${fqdn}"; ··· 29 ]; 30 }; 31 32 + testScript = { nodes, ... }: '' 33 start_all() 34 35 machine = ${hostName} 36 37 machine.wait_for_unit("network-online.target") 38 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}" 41 + 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() ··· 66 67 in 68 { 69 + noExplicitDomain = makeHostNameTest "ahost" null null; 70 71 + explicitDomain = makeHostNameTest "ahost" "adomain" "ahost.adomain"; 72 }
+1
nixos/tests/smokeping.nix
··· 8 sm = 9 { ... }: 10 { 11 services.smokeping = { 12 enable = true; 13 port = 8081;
··· 8 sm = 9 { ... }: 10 { 11 + networking.domain = "example.com"; # FQDN: sm.example.com 12 services.smokeping = { 13 enable = true; 14 port = 8081;