From 483dbe92370ef6c4a1d6f96a3973bbca4b8ae3f7 Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Sun, 21 Jun 2020 16:25:50 +0200 Subject: [PATCH] systemd: Allow setting the transient hostname via DHCP This permits using method_set_hostname but still denies method_set_static_hostname. As a result DHCP clients can now always set the transient hostname via the SetHostname method of the D-Bus interface of systemd-hostnamed (org.freedesktop.hostname1.set-hostname). If the NixOS option networking.hostName is set to an empty string (or "localhost") the static hostname (kernel.hostname but NOT /etc/hostname) will additionally be updated (this is intended). From "man hostnamectl": The transient hostname is a fallback value received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used. Fix #74847. Note: It's possible to restrict access to the org.freedesktop.hostname1 interface using Polkit rules. --- nixos/tests/systemd.nix | 5 +++++ ...ed-localed-timedated-disable-methods-that-cha.patch | 10 ---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix index ca2e36a443e9..24949c4a9f66 100644 --- a/nixos/tests/systemd.nix +++ b/nixos/tests/systemd.nix @@ -97,6 +97,11 @@ import ./make-test-python.nix ({ pkgs, ... }: { re.search(r"^Filesystem state: *clean$", extinfo, re.MULTILINE) is not None ), ("File system was not cleanly unmounted: " + extinfo) + # Regression test for https://github.com/NixOS/nixpkgs/pull/91232 + with subtest("setting transient hostnames works"): + machine.succeed("hostnamectl set-hostname --transient machine-transient") + machine.fail("hostnamectl set-hostname machine-all") + with subtest("systemd-shutdown works"): machine.shutdown() machine.wait_for_unit("multi-user.target") diff --git a/pkgs/os-specific/linux/systemd/0007-hostnamed-localed-timedated-disable-methods-that-cha.patch b/pkgs/os-specific/linux/systemd/0007-hostnamed-localed-timedated-disable-methods-that-cha.patch index 70fc147232b7..cef3280aba81 100644 --- a/pkgs/os-specific/linux/systemd/0007-hostnamed-localed-timedated-disable-methods-that-cha.patch +++ b/pkgs/os-specific/linux/systemd/0007-hostnamed-localed-timedated-disable-methods-that-cha.patch @@ -14,16 +14,6 @@ diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 21f6471495..8c5af7619f 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c -@@ -422,6 +422,9 @@ static int method_set_hostname(sd_bus_message *m, void *userdata, sd_bus_error * - if (r < 0) - return r; - -+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, -+ "Changing system settings via systemd is not supported on NixOS."); -+ - if (isempty(name)) - name = c->data[PROP_STATIC_HOSTNAME]; - @@ -478,6 +481,9 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_ if (r < 0) return r;