systemd: re-introduce hostnamed-localed-timedated-disable-methods-that-cha.patch

In NixOS, /etc is NOT read-only, and most things in /etc are symlinks
to /etc/static, which is a symlink into the nix store - so the upstream
systemd "/etc is read-only" detection doesn't work.

Fixes #224080.
This commit is contained in:
Florian Klink 2023-04-14 21:50:05 +02:00
parent 4e0210b76d
commit 16ee1b18a4
14 changed files with 119 additions and 13 deletions

View file

@ -0,0 +1,105 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gabriel Ebner <gebner@gebner.org>
Date: Sun, 6 Dec 2015 14:26:36 +0100
Subject: [PATCH] hostnamed, localed, timedated: disable methods that change
system settings.
---
src/hostname/hostnamed.c | 6 ++++++
src/locale/localed.c | 9 +++++++++
src/timedate/timedated.c | 10 ++++++++++
3 files changed, 25 insertions(+)
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 36ab0148b9..7d458d196d 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -1028,6 +1028,9 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
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.");
+
name = empty_to_null(name);
context_read_etc_hostname(c);
@@ -1091,6 +1094,9 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
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.");
+
name = empty_to_null(name);
context_read_machine_info(c);
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 841e5e3e91..a21e34430b 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -264,6 +264,9 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
use_localegen = locale_gen_check_available();
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
+ "Changing system settings via systemd is not supported on NixOS.");
+
/* If single locale without variable name is provided, then we assume it is LANG=. */
if (strv_length(l) == 1 && !strchr(l[0], '=')) {
if (!locale_is_valid(l[0]))
@@ -382,6 +385,9 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
if (r < 0)
return bus_log_parse_error(r);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
+ "Changing system settings via systemd is not supported on NixOS.");
+
vc_context_empty_to_null(&in);
FOREACH_STRING(name, in.keymap ?: in.toggle, in.keymap ? in.toggle : NULL) {
@@ -607,6 +613,9 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
if (r < 0)
return bus_log_parse_error(r);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
+ "Changing system settings via systemd is not supported on NixOS.");
+
x11_context_empty_to_null(&in);
if (!x11_context_is_safe(&in))
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index ad483301ef..31ed86955b 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -665,6 +665,10 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
if (r < 0)
return r;
+ if (getenv("NIXOS_STATIC_TIMEZONE"))
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
+ "Changing timezone via systemd is not supported when it is set in NixOS configuration.");
+
if (!timezone_is_valid(z, LOG_DEBUG))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid or not installed time zone '%s'", z);
@@ -743,6 +747,9 @@ static int method_set_local_rtc(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 (lrtc == c->local_rtc && !fix_system)
return sd_bus_reply_method_return(m, NULL);
@@ -923,6 +930,9 @@ static int method_set_ntp(sd_bus_message *m, void *userdata, sd_bus_error *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.");
+
r = context_update_ntp_status(c, bus, m);
if (r < 0)
return r;

View file

@ -103,7 +103,7 @@ index 65d9e7e398..dd44d529ca 100644
static bool etc_writable(void) {
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index ad483301ef..a7f22b1c86 100644
index 31ed86955b..8db8d8c288 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -282,7 +282,7 @@ static int context_read_data(Context *c) {

View file

@ -172,18 +172,19 @@ stdenv.mkDerivation (finalAttrs: {
./0004-fsck-look-for-fsck-binary-not-just-in-sbin.patch
./0005-Add-some-NixOS-specific-unit-directories.patch
./0006-Get-rid-of-a-useless-message-in-user-sessions.patch
./0007-Fix-hwdb-paths.patch
./0008-Change-usr-share-zoneinfo-to-etc-zoneinfo.patch
./0009-localectl-use-etc-X11-xkb-for-list-x11.patch
./0010-build-don-t-create-statedir-and-don-t-touch-prefixdi.patch
./0011-add-rootprefix-to-lookup-dir-paths.patch
./0012-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch
./0013-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch
./0014-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch
./0015-pkg-config-derive-prefix-from-prefix.patch
./0016-inherit-systemd-environment-when-calling-generators.patch
./0017-core-don-t-taint-on-unmerged-usr.patch
./0018-tpm2_context_init-fix-driver-name-checking.patch
./0007-hostnamed-localed-timedated-disable-methods-that-cha.patch
./0008-Fix-hwdb-paths.patch
./0009-Change-usr-share-zoneinfo-to-etc-zoneinfo.patch
./0010-localectl-use-etc-X11-xkb-for-list-x11.patch
./0011-build-don-t-create-statedir-and-don-t-touch-prefixdi.patch
./0012-add-rootprefix-to-lookup-dir-paths.patch
./0013-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch
./0014-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch
./0015-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch
./0016-pkg-config-derive-prefix-from-prefix.patch
./0017-inherit-systemd-environment-when-calling-generators.patch
./0018-core-don-t-taint-on-unmerged-usr.patch
./0019-tpm2_context_init-fix-driver-name-checking.patch
] ++ lib.optional stdenv.hostPlatform.isMusl (
let
oe-core = fetchzip {