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
nixos: provide /etc/hostname #21566
nixos: provide /etc/hostname #21566
Conversation
Create the file using attrset instead of list, to make it easier to later provide other files in the same module.
@bjornfor, thanks for your PR! By analyzing the history of the files in this pull request, we identified @wizeman, @wkennington and @ericsagnes to be potential reviewers. |
One side effect I just noticed. Without this PR, hostnamectl prints
and if I run With this PR, only the "Static hostname" line is shown. (I guess that's fine, now that it includes the proper hostname.) BUT, there is no "Transient hostname" line, even after cc @edolstra |
I added "policy discussion" since adding new files to /etc by default seems to require some discussion. Feel free to remove if you disagree :) |
Strange, why does |
@Mic92: I think it's because they are fetching more than just the "transient" hostname that you get from the kernel. Basically, they get "PrettyHostname", "StaticHostname" and "Chassis", all provided by org.freedesktop.hostname1[1]. See bluez code here: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/plugins/hostname.c#n133 [1] https://www.freedesktop.org/wiki/Software/systemd/hostnamed/ I thought about patching bluez at first. But when I saw that hostnamectl prints "Static hostname: n/a" without an Another option could be patching systemd to treat the hostname from the kernel as "static hostname". But I kind of like the idea of a static vs transient hostname. Snippet from hostnamed documentation:
|
I use the Would this change cause any issues on my setups? |
@jokogr: AFAICT, just change |
It turns out that hostnamectl caches the "Transient hostname" for a few minutes (5?). Eventually it picks up the value from "sudo hostname foo". |
This looks fine to me. |
I thought we wanted as little mutable stuff in /etc as possible, unless it makes sense. (eg. a service that can reconfigure itself without restarting) |
This PR creates an immutable /etc/hostname file, like most other files in /etc created by NixOS. (It'll be a symlink to /etc/static/hostname which in turn is a symlink to /nix/store/xybf7pjnnr1nq2j7apbx1110zqhx7qa1-etc-hostname.)
Correct. That's why systemd has the concept of static vs transient hostname. The static name is stored in /etc/hostname and the transient (dynamic) hostname is the one stored in the kernel. See https://www.freedesktop.org/wiki/Software/systemd/hostnamed/. |
With mutable I was referring to the /etc/static symlink that changes with a nixos-rebuild. Anyway it looks fine to me, I just expected there would be more discussion around this. |
# org.freedesktop.hostname1 dbus service (both provided by systemd) | ||
environment.etc."hostname" = mkIf (cfg.hostName != "") | ||
{ | ||
text = cfg.hostName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a trailing newline in this file.
$ cat /etc/hostname
turingmachine$
text = "${cfg.hostname}\n";
This would be consistent with hostnamectl's behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Fixed.
/etc/hostname is the file used by hostnamectl(1) and the org.freedesktop.hostname1 dbus service (both provided by systemd) to get the "static hostname". Better provide it so that users of those tools/services get a proper hostname. An example of an issue created by the lack of /etc/hostname is that the bluetooth stack on NixOS identifies itself to peers as "BlueZ $VERSION" instead of the hostname. References: https://www.freedesktop.org/software/systemd/man/hostname.html Changes v1 -> v2: * ensure /etc/hostname ends with a newline
Motivation for this change
/etc/hostname is the file used by hostnamectl(1) and the
org.freedesktop.hostname1 dbus service (both provided by systemd) to get
the "static hostname". Better provide it so that users of those
tools/services get a proper hostname.
An example of an issue created by the lack of /etc/hostname is that the
bluetooth stack on NixOS identifies itself to peers as "BlueZ $VERSION"
instead of the hostname.
References:
https://www.freedesktop.org/software/systemd/man/hostname.html
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)