Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networking: Update fqdnOrHostName logic to handle empty hostName #357647

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oneingan
Copy link
Contributor

Motivation for this change

The current logic for networking.fqdnOrHostName does not account for cases where hostName is an empty string. This can lead to unexpected behavior in configurations where hostName is not set. This change updates the logic to handle empty hostName values appropriately.

Things done

  • Updated the logic in networking.fqdnOrHostName to check if hostName is an empty string.
  • Adjusted the defaultText to reflect the new logic.
  • Tested the changes to ensure correct behavior when hostName is empty or domain is unset.

Testing

  • Built on platform(s):
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested compilation of all packages that depend on this change.
  • Tested execution of all binary files (usually in ./result/bin/).
  • Determined the impact on package closure size (by running nix path-info -S before and after).
  • Ensured that relevant documentation is up to date.
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 20, 2024
@oneingan oneingan requested a review from roberth November 20, 2024 20:08
@roberth
Copy link
Member

roberth commented Nov 21, 2024

What is the expected use or scenario for an empty string hostname?
The default hostname is "nixos", not "", so that leaves me wondering.

@oneingan
Copy link
Contributor Author

Delegate the hostname into cloud-init or dhcp. Default behavior in srvos server profile:

https://github.com/nix-community/srvos/blob/be4533b50ac69cd871ab73d4101c47b397b8c143/nixos/server/default.nix#L57

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 21, 2024
@oneingan
Copy link
Contributor Author

What do you think @roberth ? maybe its prefered simply remove this line from os-release: https://github.com/jopejoe1/nixpkgs/blob/3dec4d4a9e42564a2f952c2899a1a81249587f6a/nixos/modules/misc/version.nix#L44

defaultText = literalExpression ''
if cfg.domain == null then cfg.hostName else cfg.fqdn
'';
default = if (cfg.hostName == "" || cfg.domain == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = if (cfg.hostName == "" || cfg.domain == null)
default = if (cfg.hostName != "" && cfg.domain == null)

shouldn't this be like this? otherwise we take an empty hostname as before.

Copy link
Contributor Author

@oneingan oneingan Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, the regression occurs when hostName is empty and domain is defined. In that case, I want fqdnOrHostname to return "", not an error (as networking.fqdn does).

Copy link
Member

@SuperSandro2000 SuperSandro2000 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the condition a bit hard to understand when we re-use the empty string hostname in that case.

Also I think this not really covers the original usecase anymore. Before you would always get either a hostname or a fqdn where as empty string probably breaks most usages of it.

Copy link
Contributor Author

@oneingan oneingan Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point, so the regression comes from os-release changes i pointed above, leveraging this function, as os-release MUST not depend on whether hostName is defined or not

@oneingan
Copy link
Contributor Author

@SuperSandro2000 Can I help with this? I have a fleet of servers blocked for 24.11 update.

@oneingan
Copy link
Contributor Author

A different path to solve this:

#359571

@oneingan
Copy link
Contributor Author

oneingan commented Nov 28, 2024

Regardless of solving my issue with this PR #359571, it is inconsistent that the fqdnOrHostName function returns well the empty hostName when the domain is null, yet fails when the domain is defined.

It should either:

  • If the hostName is empty, return an empty hostName regardless of the domain.

or

  • If the hostName is empty, always fail with an error, regardless of the domain, since it cannot compose a valid FQDN or a valid hostname.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants