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

Systemd 257 #356818

Merged
merged 9 commits into from
Dec 20, 2024
837 changes: 472 additions & 365 deletions nixos/lib/make-disk-image.nix

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nixos/tests/systemd-journal-gateway.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import ./make-test-python.nix (
def copy_pem(file: str):
machine.copy_from_host(source=f"{tmpdir}/{file}", target=f"/run/secrets/{file}")
machine.succeed(f"chmod 644 /run/secrets/{file}")
machine.succeed(f"chmod 600 /run/secrets/{file} && chown systemd-journal-gateway /run/secrets/{file}")
with subtest("Copying keys and certificates"):
machine.succeed("mkdir -p /run/secrets/{client,server}")
Expand Down
3 changes: 2 additions & 1 deletion nixos/tests/systemd-repart.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let
shutil.copyfile("${machine.system.build.diskImage}/nixos.img", tmp_disk_image.name)

subprocess.run([
"${machine.config.virtualisation.qemu.package}/bin/qemu-img",
"${machine.virtualisation.qemu.package}/bin/qemu-img",
"resize",
"-f",
"raw",
Expand Down Expand Up @@ -151,6 +151,7 @@ in
}:
{
virtualisation.useDefaultFilesystems = false;
virtualisation.mountHostNixStore = false;
virtualisation.fileSystems = {
"/" = {
device = "/dev/disk/by-partlabel/created-root";
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import ./make-test-python.nix (
# it's not possible because we're not in a tty when grepping
# (i.e. hacky way to ensure that the error from above doesn't appear here).
_, out = machine.execute("systemctl --user edit testservice2.service 2>&1")
assert out.rstrip("\n") == "Cannot edit units if not on a tty."
assert out.rstrip("\n") == "Cannot edit units interactively if not on a tty."
# Regression test for https://github.com/NixOS/nixpkgs/issues/105049
with subtest("systemd reads timezone database in /etc/zoneinfo"):
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/ni/nixos-enter/nixos-enter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ -z "$NIXOS_ENTER_REEXEC" ]; then
if [ "$(id -u)" != 0 ]; then
extraFlags="-r"
fi
exec unshare --fork --mount --uts --mount-proc --pid $extraFlags -- "$0" "$@"
exec unshare --fork --mount --uts --mount-proc $extraFlags -- "$0" "$@"
else
mount --make-rprivate /
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ unit. (However, this ignores the fsck unit, so it's not perfect...)
1 file changed, 4 deletions(-)

diff --git a/rules.d/99-systemd.rules.in b/rules.d/99-systemd.rules.in
index ad0c7e2fb5..79f3086e78 100644
index 882cda0dcd..8e8d1f04ce 100644
--- a/rules.d/99-systemd.rules.in
+++ b/rules.d/99-systemd.rules.in
@@ -26,10 +26,6 @@ SUBSYSTEM=="block", ACTION=="add", KERNEL=="dm-*", ENV{DM_NAME}!="?*", ENV{SYSTE
@@ -30,10 +30,6 @@ SUBSYSTEM=="block", ACTION=="add", KERNEL=="dm-*", ENV{DM_NAME}!="?*", ENV{SYSTE
# Import previous SYSTEMD_READY state.
SUBSYSTEM=="block", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", ENV{SYSTEMD_READY}=="", IMPORT{db}="SYSTEMD_READY"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Original-Author: Eelco Dolstra <[email protected]>
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c
index eac5bb8d3b..d8187bfa99 100644
index d6a256c4a7..f74d5198f1 100644
--- a/src/shared/fstab-util.c
+++ b/src/shared/fstab-util.c
@@ -66,6 +66,8 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) {
Expand All @@ -27,7 +27,7 @@ index eac5bb8d3b..d8187bfa99 100644
"/etc"))
return true;
diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c
index ca6d36e054..0a9227c9a8 100644
index 4bc01c75e0..ede9ac7b87 100644
--- a/src/shutdown/umount.c
+++ b/src/shutdown/umount.c
@@ -170,8 +170,10 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ container, so checking early whether it exists will fail.
1 file changed, 2 insertions(+)

diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 4fee8a693c..756ce11b1f 100644
index 500725d35f..2b735e4df4 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -6028,6 +6028,7 @@ static int run(int argc, char *argv[]) {
@@ -6189,6 +6189,7 @@ static int run(int argc, char *argv[]) {
goto finish;
}
} else {
+#if 0
_cleanup_free_ char *p = NULL;

if (arg_pivot_root_new)
@@ -6044,6 +6045,7 @@ static int run(int argc, char *argv[]) {
"Directory %s doesn't look like it has an OS tree (/usr/ directory is missing). Refusing.", arg_directory);
@@ -6208,6 +6209,7 @@ static int run(int argc, char *argv[]) {
log_error_errno(r, "Unable to determine if %s looks like it has an OS tree (i.e. whether /usr/ exists): %m", arg_directory);
goto finish;
}
+#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,105 +11,24 @@ Also, remove /usr and /lib as these don't exist on NixOS.

Original-Author: Eelco Dolstra <[email protected]>
---
src/basic/path-lookup.c | 18 ++----------------
src/core/systemd.pc.in | 8 ++++----
2 files changed, 6 insertions(+), 20 deletions(-)
src/core/systemd.pc.in | 8 ++++----
src/libsystemd/sd-path/path-lookup.c | 20 +++-----------------
2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c
index 540256b73b..a115ec09a3 100644
--- a/src/basic/path-lookup.c
+++ b/src/basic/path-lookup.c
@@ -123,11 +123,7 @@ int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
}

static const char* const user_data_unit_paths[] = {
- "/usr/local/lib/systemd/user",
- "/usr/local/share/systemd/user",
USER_DATA_UNIT_DIR,
- "/usr/lib/systemd/user",
- "/usr/share/systemd/user",
NULL
};

@@ -634,16 +630,13 @@ int lookup_paths_init(
persistent_config,
SYSTEM_CONFIG_UNIT_DIR,
"/etc/systemd/system",
+ "/nix/var/nix/profiles/default/lib/systemd/system",
STRV_IFNOTNULL(persistent_attached),
runtime_config,
"/run/systemd/system",
STRV_IFNOTNULL(runtime_attached),
STRV_IFNOTNULL(generator),
- "/usr/local/lib/systemd/system",
SYSTEM_DATA_UNIT_DIR,
- "/usr/lib/systemd/system",
- /* To be used ONLY for images which might be legacy split-usr */
- STRV_IFNOTNULL(flags & LOOKUP_PATHS_SPLIT_USR ? "/lib/systemd/system" : NULL),
STRV_IFNOTNULL(generator_late));
break;

@@ -659,14 +652,11 @@ int lookup_paths_init(
persistent_config,
USER_CONFIG_UNIT_DIR,
"/etc/systemd/user",
+ "/nix/var/nix/profiles/default/lib/systemd/user",
runtime_config,
"/run/systemd/user",
STRV_IFNOTNULL(generator),
- "/usr/local/share/systemd/user",
- "/usr/share/systemd/user",
- "/usr/local/lib/systemd/user",
USER_DATA_UNIT_DIR,
- "/usr/lib/systemd/user",
STRV_IFNOTNULL(generator_late));
break;

@@ -825,7 +815,6 @@ char **generator_binary_paths(RuntimeScope scope) {
case RUNTIME_SCOPE_SYSTEM:
add = strv_new("/run/systemd/system-generators",
"/etc/systemd/system-generators",
- "/usr/local/lib/systemd/system-generators",
SYSTEM_GENERATOR_DIR);
break;

@@ -833,7 +822,6 @@ char **generator_binary_paths(RuntimeScope scope) {
case RUNTIME_SCOPE_USER:
add = strv_new("/run/systemd/user-generators",
"/etc/systemd/user-generators",
- "/usr/local/lib/systemd/user-generators",
USER_GENERATOR_DIR);
break;

@@ -872,14 +860,12 @@ char **env_generator_binary_paths(RuntimeScope runtime_scope) {
case RUNTIME_SCOPE_SYSTEM:
add = strv_new("/run/systemd/system-environment-generators",
"/etc/systemd/system-environment-generators",
- "/usr/local/lib/systemd/system-environment-generators",
SYSTEM_ENV_GENERATOR_DIR);
break;

case RUNTIME_SCOPE_USER:
add = strv_new("/run/systemd/user-environment-generators",
"/etc/systemd/user-environment-generators",
- "/usr/local/lib/systemd/user-environment-generators",
USER_ENV_GENERATOR_DIR);
break;

diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in
index f3b85b0190..8ae544b495 100644
index f3b85b0190..f7aa5fca50 100644
--- a/src/core/systemd.pc.in
+++ b/src/core/systemd.pc.in
@@ -43,10 +43,10 @@ systemdsystemconfdir=${systemd_system_conf_dir}
systemd_user_conf_dir=${sysconfdir}/systemd/user
systemduserconfdir=${systemd_user_conf_dir}

-systemd_system_unit_path=${systemd_system_conf_dir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemd_system_unit_dir}:/usr/lib/systemd/system:/lib/systemd/system
+systemd_system_unit_path=${systemd_system_conf_dir}:/etc/systemd/system:/nix/var/nix/profiles/default/lib/systemd/system:/run/systemd/system:${systemdsystemunitdir}
+systemd_system_unit_path=${systemd_system_conf_dir}:/etc/systemd/system:/nix/var/nix/profiles/default/lib/systemd/system:/run/systemd/system:${systemd_system_unit_dir}
systemdsystemunitpath=${systemd_system_unit_path}

-systemd_user_unit_path=${systemd_user_conf_dir}:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:${systemd_user_unit_dir}:/usr/lib/systemd/user:/usr/share/systemd/user
+systemd_user_unit_path=${systemd_user_conf_dir}:/etc/systemd/user:/nix/var/nix/profiles/default/lib/systemd/user:/run/systemd/user:${systemduserunitdir}
+systemd_user_unit_path=${systemd_user_conf_dir}:/etc/systemd/user:/nix/var/nix/profiles/default/lib/systemd/user:/run/systemd/user:${systemd_user_unit_dir}
systemduserunitpath=${systemd_user_unit_path}

systemd_system_generator_dir=${prefix}/lib/systemd/system-generators
Expand All @@ -126,3 +45,85 @@ index f3b85b0190..8ae544b495 100644
systemdusergeneratorpath=${systemd_user_generator_path}

systemd_sleep_dir=${prefix}/lib/systemd/system-sleep
diff --git a/src/libsystemd/sd-path/path-lookup.c b/src/libsystemd/sd-path/path-lookup.c
index a3b09208cb..91a085c6bc 100644
--- a/src/libsystemd/sd-path/path-lookup.c
+++ b/src/libsystemd/sd-path/path-lookup.c
@@ -69,11 +69,7 @@ int runtime_directory(RuntimeScope scope, const char *suffix, char **ret) {
}

static const char* const user_data_unit_paths[] = {
- "/usr/local/lib/systemd/user",
- "/usr/local/share/systemd/user",
USER_DATA_UNIT_DIR,
- "/usr/lib/systemd/user",
- "/usr/share/systemd/user",
NULL
};

@@ -481,16 +477,13 @@ int lookup_paths_init(
persistent_config,
SYSTEM_CONFIG_UNIT_DIR,
"/etc/systemd/system",
+ "/nix/var/nix/profiles/default/lib/systemd/system",
ASSERT_PTR(persistent_attached),
ASSERT_PTR(runtime_config),
"/run/systemd/system",
ASSERT_PTR(runtime_attached),
STRV_IFNOTNULL(generator),
- "/usr/local/lib/systemd/system",
SYSTEM_DATA_UNIT_DIR,
- "/usr/lib/systemd/system",
- /* To be used ONLY for images which might be legacy split-usr */
- FLAGS_SET(flags, LOOKUP_PATHS_SPLIT_USR) ? "/lib/systemd/system" : STRV_IGNORE,
STRV_IFNOTNULL(generator_late));
break;

@@ -508,13 +501,10 @@ int lookup_paths_init(
add = strv_new(persistent_config,
USER_CONFIG_UNIT_DIR,
"/etc/systemd/user",
+ "/nix/var/nix/profiles/default/lib/systemd/user",
ASSERT_PTR(runtime_config),
"/run/systemd/user",
- "/usr/local/share/systemd/user",
- "/usr/share/systemd/user",
- "/usr/local/lib/systemd/user",
- USER_DATA_UNIT_DIR,
- "/usr/lib/systemd/user");
+ USER_DATA_UNIT_DIR);
break;

case RUNTIME_SCOPE_USER:
@@ -653,7 +643,6 @@ void lookup_paths_log(LookupPaths *lp) {
static const char* const system_generator_paths[] = {
"/run/systemd/system-generators",
"/etc/systemd/system-generators",
- "/usr/local/lib/systemd/system-generators",
SYSTEM_GENERATOR_DIR,
NULL,
};
@@ -661,7 +650,6 @@ static const char* const system_generator_paths[] = {
static const char* const user_generator_paths[] = {
"/run/systemd/user-generators",
"/etc/systemd/user-generators",
- "/usr/local/lib/systemd/user-generators",
USER_GENERATOR_DIR,
NULL,
};
@@ -669,7 +657,6 @@ static const char* const user_generator_paths[] = {
static const char* const system_env_generator_paths[] = {
"/run/systemd/system-environment-generators",
"/etc/systemd/system-environment-generators",
- "/usr/local/lib/systemd/system-environment-generators",
SYSTEM_ENV_GENERATOR_DIR,
NULL,
};
@@ -677,7 +664,6 @@ static const char* const system_env_generator_paths[] = {
static const char* const user_env_generator_paths[] = {
"/run/systemd/user-environment-generators",
"/etc/systemd/user-environment-generators",
- "/usr/local/lib/systemd/user-environment-generators",
USER_ENV_GENERATOR_DIR,
NULL,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ in containers.
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index 04103e0fe9..e26c6c5cfd 100644
index f21a4f7ceb..4c24ce5c98 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1611,7 +1611,8 @@ static unsigned manager_dispatch_stop_when_bound_queue(Manager *m) {
@@ -1672,7 +1672,8 @@ static unsigned manager_dispatch_stop_when_bound_queue(Manager *m) {
if (!unit_is_bound_by_inactive(u, &culprit))
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Subject: [PATCH] hostnamed, localed, timedated: disable methods that change
3 files changed, 25 insertions(+)

diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 82d08803fa..8e40b77eba 100644
index ba50b59f92..9827487453 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -1116,6 +1116,9 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
@@ -1115,6 +1115,9 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
if (r < 0)
return r;

Expand All @@ -24,7 +24,7 @@ index 82d08803fa..8e40b77eba 100644
name = empty_to_null(name);

context_read_etc_hostname(c);
@@ -1178,6 +1181,9 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
@@ -1177,6 +1180,9 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
if (r < 0)
return r;

Expand All @@ -35,7 +35,7 @@ index 82d08803fa..8e40b77eba 100644

context_read_machine_info(c);
diff --git a/src/locale/localed.c b/src/locale/localed.c
index c0d104578d..51a714ee23 100644
index 062744519d..95bde4b1c3 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -226,6 +226,9 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
Expand Down Expand Up @@ -69,10 +69,10 @@ index c0d104578d..51a714ee23 100644

r = x11_context_verify_and_warn(&in, LOG_ERR, error);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index e3b4367ec0..448aa7e94d 100644
index c79bb864df..cbd30214b7 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -673,6 +673,10 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
@@ -676,6 +676,10 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
if (r < 0)
return r;

Expand All @@ -83,7 +83,7 @@ index e3b4367ec0..448aa7e94d 100644
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);

@@ -750,6 +754,9 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
@@ -754,6 +758,9 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
if (r < 0)
return r;

Expand All @@ -93,7 +93,7 @@ index e3b4367ec0..448aa7e94d 100644
if (lrtc == c->local_rtc && !fix_system)
return sd_bus_reply_method_return(m, NULL);

@@ -928,6 +935,9 @@ static int method_set_ntp(sd_bus_message *m, void *userdata, sd_bus_error *error
@@ -948,6 +955,9 @@ static int method_set_ntp(sd_bus_message *m, void *userdata, sd_bus_error *error
if (r < 0)
return r;

Expand Down
Loading
Loading