Skip to content

Commit 43975d7

Browse files
authored
Merge pull request nix-darwin#1423 from Enzime/push-kpkrwzkroylt
networking: backport `domain`, `fqdn` and `fqdnOrHostName` options
2 parents 113883e + 751a96b commit 43975d7

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

modules/networking/default.nix

+49
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,55 @@ in
7171
'';
7272
};
7373

74+
networking.domain = mkOption {
75+
default = null;
76+
example = "home.arpa";
77+
type = types.nullOr types.str;
78+
description = ''
79+
The domain. It can be left empty if it is auto-detected through DHCP.
80+
'';
81+
};
82+
83+
networking.fqdn = mkOption {
84+
readOnly = true;
85+
type = types.str;
86+
default =
87+
if (cfg.hostName != "" && cfg.domain != null) then
88+
"${cfg.hostName}.${cfg.domain}"
89+
else
90+
throw ''
91+
The FQDN is required but cannot be determined. Please make sure that
92+
both networking.hostName and networking.domain are set properly.
93+
'';
94+
defaultText = literalExpression ''"''${networking.hostName}.''${networking.domain}"'';
95+
description = ''
96+
The fully qualified domain name (FQDN) of this host. It is the result
97+
of combining `networking.hostName` and `networking.domain.` Using this
98+
option will result in an evaluation error if the hostname is empty or
99+
no domain is specified.
100+
101+
Modules that accept a mere `networking.hostName` but prefer a fully qualified
102+
domain name may use `networking.fqdnOrHostName` instead.
103+
'';
104+
};
105+
106+
networking.fqdnOrHostName = mkOption {
107+
readOnly = true;
108+
type = types.str;
109+
default = if cfg.domain == null then cfg.hostName else cfg.fqdn;
110+
defaultText = literalExpression ''
111+
if cfg.domain == null then cfg.hostName else cfg.fqdn
112+
'';
113+
description = ''
114+
Either the fully qualified domain name (FQDN), or just the host name if
115+
it does not exists.
116+
117+
This is a convenience option for modules to read instead of `fqdn` when
118+
a mere `hostName` is also an acceptable value; this option does not
119+
throw an error when `domain` is unset.
120+
'';
121+
};
122+
74123
networking.knownNetworkServices = mkOption {
75124
type = types.listOf types.str;
76125
default = [];

tests/networking-hostname.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, config, pkgs, ... }:
1+
{ lib, config, ... }:
22

33
{
44
networking.hostName = "EVE";

0 commit comments

Comments
 (0)