nixos/os-release: make default_hostname distribution default#359571
nixos/os-release: make default_hostname distribution default#359571jopejoe1 merged 1 commit intoNixOS:masterfrom
Conversation
There was a problem hiding this comment.
For reference, the relevant /etc/os-release manual page.
Distribution-level defaults and metadata
DEFAULT_HOSTNAME=
A string specifying the hostname if
hostname(5)is not
present and no other configuration source specifies the
hostname. Must be either a single DNS label (a string
composed of 7-bit ASCII lower-case characters and no spaces
or dots, limited to the format allowed for DNS domain name
labels), or a sequence of such labels separated by single
dots that forms a valid DNS FQDN. The hostname must be at
most 64 characters, which is a Linux limitation (DNS allows
longer names).See
org.freedesktop.hostname1(5)for a description of how
systemd-hostnamed.service(8)determines the fallback
hostname.Added in version 248.
|
I accept your changes and have also updated the PR title. My only concern is whether this change can be backported, as the regression exists in 24.11 |
SigmaSquadron
left a comment
There was a problem hiding this comment.
Please squash the commits; otherwise LGTM.
|
Successfully created backport PR for |
|
Sure |
|
This change brings a regression because this breaks hostname fetching from DHCP with dhcpcd. The default behaviour of dhcpcd is to change the hostname only if it is |
Motivation for this change
The current implementation of
DEFAULT_HOSTNAMEinversion.nixdoes not account for cases wherenetworking.hostNameis an empty string. This can lead to incorrect or unexpected behavior in scenarios wherenetworking.hostNameis unset or explicitly set to an empty value, even whennetworking.domainis defined.In such corner cases,
fqdnOrHostNamecan produce inconsistent results or cause runtime errors due to assumptions abouthostNamealways being set. By explicitly checking for an emptyhostName, we can ensure thatDEFAULT_HOSTNAMEonly propagates valid values.Changes Made
DEFAULT_HOSTNAMEdefinition innixos/modules/misc/version.nixto:Impact
This change ensures that configurations with
networking.hostName = "";do not inadvertently propagate invalid or unexpected values forDEFAULT_HOSTNAME. It also prevents potential errors whenhostNameis empty butdomainis defined, asfqdnOrHostNamemay behave unpredictably in such cases.Things Done:
nixos/modules/misc/version.nixto handle emptynetworking.hostName.networking.hostNameandnetworking.domainsettings to verify behavior.Testing:
nixos-rebuildwith varying configurations:networking.hostName = ""; networking.domain = null;networking.hostName = ""; networking.domain = "example.com";networking.hostName = "example"; networking.domain = "example.com";networking.hostName = null; networking.domain = null;Submission Checklist:
Make sure you’ve followed the Nixpkgs contribution guidelines: