Skip to content

Commit c8da2d4

Browse files
committed
nixos: Move system.name logic to network-interfaces.nix
1 parent c78d41a commit c8da2d4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

nixos/modules/system/activation/top-level.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ in
151151

152152
system.name = mkOption {
153153
type = types.str;
154-
default =
155-
if config.networking.hostName == ""
156-
then "unnamed"
157-
else config.networking.hostName;
154+
# when using full NixOS or importing the network-interfaces.nix module.
158155
defaultText = literalExpression ''
159156
if config.networking.hostName == ""
160157
then "unnamed"
@@ -182,6 +179,12 @@ in
182179

183180
system.build.toplevel = system;
184181

182+
# Traditionally, the option default contained the logic for taking this from
183+
# the network.hostName option, which is expected to define it at
184+
# mkOptionDefault priority. However, we'd also like to have a default when
185+
# network.hostName is not imported.
186+
system.name = mkOverride ((mkOptionDefault {}).priority + 100) "unnamed";
187+
185188
};
186189

187190
}

nixos/modules/tasks/network-interfaces.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,12 @@ in
12221222
}
12231223
];
12241224

1225+
system.name = lib.mkOptionDefault (
1226+
if config.networking.hostName == ""
1227+
then "unnamed"
1228+
else config.networking.hostName
1229+
);
1230+
12251231
boot.kernelModules = [ ]
12261232
++ optional hasVirtuals "tun"
12271233
++ optional hasSits "sit"

0 commit comments

Comments
 (0)