From 857c6490832fb5dccbac6ca7a679496e85a85e21 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 23 Mar 2021 11:40:54 -0400 Subject: [PATCH] network-interfaces: set hostname from sysctl if defined The `networking.hostname` option was changed to not permit periods in names, due to a strict reading of RFC 1123. For users who need the hostname to be fully qualified, the networking.hostName option suggests using boot.kernel.sysctl."kernel.hostname" as a workaround. This option works correctly at boot time, but every "nixos-rebuild switch" will change the hostname back to the unqualified version. This commit brings the activation script in line with the documentation's recommendation. --- nixos/modules/tasks/network-interfaces.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index f730ec82bdf5..a3929428f694 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -1115,9 +1115,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) ''