From f43716f28e1c7c787e003bd83dd1e897b360240a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:21:09 +0200 Subject: nixos: Add networking.fqdnOrHostName option, readOnly --- nixos/modules/tasks/network-interfaces.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index 6f01917bcc59f..c21675285f64c 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -479,6 +479,22 @@ in ''; }; + networking.fqdnOrHostName = mkOption { + readOnly = true; + type = types.str; + default = if cfg.domain == null then cfg.hostName else cfg.fqdn; + defaultText = literalExpression '' + if cfg.domain == null then cfg.hostName else cfg.fqdn + ''; + description = lib.mdDoc '' + Either the fully qualified domain name (FQDN), or just the host name if + it does not exists. + + This is a convenience option for modules to read instead of `fqdn` when + a mere `hostName` is also an acceptable value. + ''; + }; + networking.hostId = mkOption { default = null; example = "4e98920d"; -- cgit 1.4.1 From fec3f62d38585455fe8bac4634e307d8728c387b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:21:43 +0200 Subject: nixos/kubelet: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/cluster/kubernetes/kubelet.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/cluster/kubernetes/kubelet.nix b/nixos/modules/services/cluster/kubernetes/kubelet.nix index ae9548bdba22d..769143a6a3ff3 100644 --- a/nixos/modules/services/cluster/kubernetes/kubelet.nix +++ b/nixos/modules/services/cluster/kubernetes/kubelet.nix @@ -176,8 +176,7 @@ in hostname = mkOption { description = lib.mdDoc "Kubernetes kubelet hostname override."; - default = config.networking.hostName; - defaultText = literalExpression "config.networking.hostName"; + defaultText = literalExpression "config.networking.fqdnOrHostName"; type = str; }; @@ -357,8 +356,8 @@ in boot.kernelModules = ["br_netfilter" "overlay"]; - services.kubernetes.kubelet.hostname = with config.networking; - mkDefault (hostName + optionalString (domain != null) ".${domain}"); + services.kubernetes.kubelet.hostname = + mkDefault config.networking.fqdnOrHostName; services.kubernetes.pki.certs = with top.lib; { kubelet = mkCert { -- cgit 1.4.1 From 185f12d96f46460e77589a079b079fd1d037b736 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:22:05 +0200 Subject: nixos/smartd: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/monitoring/smartd.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nixos/modules/services/monitoring/smartd.nix b/nixos/modules/services/monitoring/smartd.nix index cfebb4b9798bd..1e654cad5dd2a 100644 --- a/nixos/modules/services/monitoring/smartd.nix +++ b/nixos/modules/services/monitoring/smartd.nix @@ -4,8 +4,7 @@ with lib; let - host = config.networking.hostName or "unknown" - + optionalString (config.networking.domain != null) ".${config.networking.domain}"; + host = config.networking.fqdnOrHostName; cfg = config.services.smartd; opt = options.services.smartd; -- cgit 1.4.1 From 06a1a2946776aa5b50ac355c7641d23b17c9546e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:22:27 +0200 Subject: nixos/flannel: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/networking/flannel.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/networking/flannel.nix b/nixos/modules/services/networking/flannel.nix index c19e51e5aa6c8..6ed4f78ddc92b 100644 --- a/nixos/modules/services/networking/flannel.nix +++ b/nixos/modules/services/networking/flannel.nix @@ -92,10 +92,8 @@ in { Needed when running with Kubernetes as backend as this cannot be auto-detected"; ''; type = types.nullOr types.str; - default = with config.networking; (hostName + optionalString (domain != null) ".${domain}"); - defaultText = literalExpression '' - with config.networking; (hostName + optionalString (domain != null) ".''${domain}") - ''; + default = config.networking.fqdnOrHostName; + defaultText = literalExpression "config.networking.fqdnOrHostName"; example = "node1.example.com"; }; -- cgit 1.4.1 From 12da62fef52151d67fe497c9b6af43b813fdd43b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:22:51 +0200 Subject: nixos/jitsi-videobridge: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/networking/jitsi-videobridge.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/jitsi-videobridge.nix b/nixos/modules/services/networking/jitsi-videobridge.nix index 4455b7bcee4a4..f3b888f5e15c1 100644 --- a/nixos/modules/services/networking/jitsi-videobridge.nix +++ b/nixos/modules/services/networking/jitsi-videobridge.nix @@ -150,7 +150,7 @@ in config = { hostName = mkDefault name; mucNickname = mkDefault (builtins.replaceStrings [ "." ] [ "-" ] ( - config.networking.hostName + optionalString (config.networking.domain != null) ".${config.networking.domain}" + config.networking.fqdnOrHostName )); }; })); -- cgit 1.4.1 From c069475f82927b401313b722437f52d0e577d45e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:23:13 +0200 Subject: nixos/bookstack: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/web-apps/bookstack.nix | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/web-apps/bookstack.nix b/nixos/modules/services/web-apps/bookstack.nix index 3fbccf5400879..32a85de9415bb 100644 --- a/nixos/modules/services/web-apps/bookstack.nix +++ b/nixos/modules/services/web-apps/bookstack.nix @@ -60,11 +60,8 @@ in { hostname = lib.mkOption { type = lib.types.str; - default = if config.networking.domain != null then - config.networking.fqdn - else - config.networking.hostName; - defaultText = lib.literalExpression "config.networking.fqdn"; + default = config.networking.fqdnOrHostName; + defaultText = lib.literalExpression "config.networking.fqdnOrHostName"; example = "bookstack.example.com"; description = lib.mdDoc '' The hostname to serve BookStack on. -- cgit 1.4.1 From 5699ff529ad9d5959a4584531e242b5ab86a3889 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:23:32 +0200 Subject: nixos/discourse: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/web-apps/discourse.nix | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/web-apps/discourse.nix b/nixos/modules/services/web-apps/discourse.nix index 66b22ec87db12..dae40864a7919 100644 --- a/nixos/modules/services/web-apps/discourse.nix +++ b/nixos/modules/services/web-apps/discourse.nix @@ -42,11 +42,8 @@ in hostname = lib.mkOption { type = lib.types.str; - default = if config.networking.domain != null then - config.networking.fqdn - else - config.networking.hostName; - defaultText = lib.literalExpression "config.networking.fqdn"; + default = config.networking.fqdnOrHostName; + defaultText = lib.literalExpression "config.networking.fqdnOrHostName"; example = "discourse.example.com"; description = lib.mdDoc '' The hostname to serve Discourse on. -- cgit 1.4.1 From ed5aa53f451ee1bea1922f8ffa9e2f3b73280723 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:23:48 +0200 Subject: nixos/matamo: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/web-apps/matomo.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/web-apps/matomo.nix b/nixos/modules/services/web-apps/matomo.nix index 9e8d85161da76..117d540ba36b1 100644 --- a/nixos/modules/services/web-apps/matomo.nix +++ b/nixos/modules/services/web-apps/matomo.nix @@ -12,8 +12,6 @@ let phpExecutionUnit = "phpfpm-${pool}"; databaseService = "mysql.service"; - fqdn = if config.networking.domain != null then config.networking.fqdn else config.networking.hostName; - in { imports = [ (mkRenamedOptionModule [ "services" "piwik" "enable" ] [ "services" "matomo" "enable" ]) @@ -77,11 +75,9 @@ in { hostname = mkOption { type = types.str; - default = "${user}.${fqdn}"; + default = "${user}.${config.networking.fqdnOrHostName}"; defaultText = literalExpression '' - if config.${options.networking.domain} != null - then "${user}.''${config.${options.networking.fqdn}}" - else "${user}.''${config.${options.networking.hostName}}" + "${user}.''${config.${options.networking.fqdnOrHostName}}" ''; example = "matomo.yourdomain.org"; description = lib.mdDoc '' -- cgit 1.4.1 From 1ab9d1beb1668e4cd3da2bfdd52851de0972a781 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 6 Oct 2022 16:24:03 +0200 Subject: nixos/snipe-it: Refactor to use config.networking.fqdnOrHostName --- nixos/modules/services/web-apps/snipe-it.nix | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/web-apps/snipe-it.nix b/nixos/modules/services/web-apps/snipe-it.nix index 264b72fe837b1..10de321cc5d10 100644 --- a/nixos/modules/services/web-apps/snipe-it.nix +++ b/nixos/modules/services/web-apps/snipe-it.nix @@ -54,11 +54,8 @@ in { hostName = lib.mkOption { type = lib.types.str; - default = if config.networking.domain != null then - config.networking.fqdn - else - config.networking.hostName; - defaultText = lib.literalExpression "config.networking.fqdn"; + default = config.networking.fqdnOrHostName; + defaultText = lib.literalExpression "config.networking.fqdnOrHostName"; example = "snipe-it.example.com"; description = lib.mdDoc '' The hostname to serve Snipe-IT on. -- cgit 1.4.1 From 18e3f431e1b36d4f569ddddd415f95921e1b7748 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 15 Oct 2022 11:56:42 +0200 Subject: networking.fqdnOrHostName: Elaborate and format the descriptions --- nixos/modules/tasks/network-interfaces.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index c21675285f64c..9d55dc8bab831 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -473,9 +473,12 @@ in defaultText = literalExpression ''"''${networking.hostName}.''${networking.domain}"''; description = lib.mdDoc '' The fully qualified domain name (FQDN) of this host. It is the result - of combining networking.hostName and networking.domain. Using this + of combining `networking.hostName` and `networking.domain.` Using this option will result in an evaluation error if the hostname is empty or no domain is specified. + + Modules that accept a mere `networing.hostName` but prefer a fully qualified + domain name may use `networking.fqdnOrHostName` instead. ''; }; @@ -491,7 +494,8 @@ in it does not exists. This is a convenience option for modules to read instead of `fqdn` when - a mere `hostName` is also an acceptable value. + a mere `hostName` is also an acceptable value; this option does not + throw an error when `domain` is unset. ''; }; -- cgit 1.4.1