Open hacker1024 opened 9 months ago
This makes sense to me.
Also see: https://github.com/NixOS/nixpkgs/issues/224080#issuecomment-1509170912
It might make sense to conditionally allow setting the static hostname interactively when networking.hostName
is not set.
I'd be happy to review such patch.
Since I came here while searching for a way to dynamically change the hostname
to the machine-id
on boot I want to leave my (hacky) solution here:
# /etc/hostname symlink is not created on empty hostName in config
networking.hostName = lib.mkForce "";
systemd.services.set-machine-id-as-hostname = {
description = "Set hostname from /etc/machine-id";
# Run after the system has booted and the filesystem is mounted
after = [ "network.target" ];
# Set to run before the hostname is set
before = [ "systemd-hostnamed.service" ];
serviceConfig = {
User = "root";
Group = "root";
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
${pkgs.coreutils}/bin/echo "system-''$(cat /etc/machine-id)" > /etc/hostname
'';
# Ensure the service runs on boot
wantedBy = [ "multi-user.target" ];
};
It seems to be working fine. But I am not sure if this will break anything.
Describe the bug
hostnamectl hostname --static
is currently blocked.There are valid use-cases for this tool on NixOS, though. I, for example, want to set the static hostname dynamically based on system properties. The transient hostname is not used by NetworkManager for DHCP requests, which is why the static hostname must be used.
Steps To Reproduce
A service like the following does not currently work.
Expected behavior
hostnamectl hostname --static
should not fail.Notify maintainers
@NixOS/systemd
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Add a :+1: reaction to issues you find important.