about summary refs log tree commit diff
path: root/nixos/modules/tasks
diff options
context:
space:
mode:
authorRyan Lahfa <masterancpp@gmail.com>2022-12-01 16:03:04 +0100
committerGitHub <noreply@github.com>2022-12-01 16:03:04 +0100
commitbc7c15825b6e7c58b5d91a8f5aaa1f600dc667bb (patch)
treefe2965154b7f5234a8b0f36c6e784f113451624f /nixos/modules/tasks
parent2ae5aa0bd6f793b0c5f6bc5df7e697fea781006a (diff)
parent857c6490832fb5dccbac6ca7a679496e85a85e21 (diff)
Merge pull request #117371 from grahamc/sysctl-hostname
network-interfaces: set hostname from sysctl if defined
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r--nixos/modules/tasks/network-interfaces.nix7
1 files changed, 4 insertions, 3 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index b7a4282f9727f..4c211b747614b 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -1411,9 +1411,10 @@ in
     # Set the host and domain names in the activation script.  Don't
     # clear it if it's not configured in the NixOS configuration,
     # since it may have been set by dhcpcd in the meantime.
-    system.activationScripts.hostname =
-      optionalString (cfg.hostName != "") ''
-        hostname "${cfg.hostName}"
+    system.activationScripts.hostname = let
+        effectiveHostname = config.boot.kernel.sysctl."kernel.hostname" or cfg.hostName;
+      in optionalString (effectiveHostname != "") ''
+        hostname "${effectiveHostname}"
       '';
     system.activationScripts.domain =
       optionalString (cfg.domain != null) ''