Merge pull request #182436 from K900/systemd-initrd-fixes

nixos/systemd: make sure all the device nodes are created in stage1
This commit is contained in:
Florian Klink 2022-07-22 15:06:59 +07:00 committed by GitHub
commit ad29dc19c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 56 additions and 126 deletions

View file

@ -592,6 +592,12 @@ in
systemd.services.systemd-importd.environment = proxy_env;
systemd.services.systemd-pstore.wantedBy = [ "sysinit.target" ]; # see #81138
# NixOS has kernel modules in a different location, so override that here.
systemd.services.kmod-static-nodes.unitConfig.ConditionFileNotEmpty = [
"" # required to unset the previous value!
"/run/booted-system/kernel-modules/lib/modules/%v/modules.devname"
];
# Don't bother with certain units in containers.
systemd.services.systemd-remount-fs.unitConfig.ConditionVirtualization = "!container";
systemd.services.systemd-random-seed.unitConfig.ConditionVirtualization = "!container";

View file

@ -420,6 +420,9 @@ in {
services."systemd-makefs@" = lib.mkIf needMakefs { unitConfig.IgnoreOnIsolate = true; };
services."systemd-growfs@" = lib.mkIf needGrowfs { unitConfig.IgnoreOnIsolate = true; };
# make sure all the /dev nodes are set up
services.systemd-tmpfiles-setup-dev.wantedBy = ["sysinit.target"];
services.initrd-nixos-activation = {
after = [ "initrd-fs.target" ];
requiredBy = [ "initrd.target" ];

View file

@ -1,7 +1,7 @@
From c8b50208dce4c467c1f85c3db3e05bdcfd43c378 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Tue, 8 Jan 2013 15:46:30 +0100
Subject: [PATCH 01/18] Start device units for uninitialised encrypted devices
Subject: [PATCH] Start device units for uninitialised encrypted devices
This is necessary because the NixOS service that initialises the
filesystem depends on the appearance of the device unit. Also, this
@ -27,6 +27,3 @@ index 25b8a590a6..d18999ea87 100644
# add symlink to GPT root disk
SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}!="crypto_LUKS", SYMLINK+="gpt-auto-root"
SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}=="crypto_LUKS", SYMLINK+="gpt-auto-root-luks"
--
2.36.1

View file

@ -1,7 +1,7 @@
From c884aee4c66c97f592ae0f8ebd97f48a39d8c53c Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Fri, 12 Apr 2013 13:16:57 +0200
Subject: [PATCH 02/18] Don't try to unmount /nix or /nix/store
Subject: [PATCH] Don't try to unmount /nix or /nix/store
They'll still be remounted read-only.
@ -37,6 +37,3 @@ index 820aa8e286..653e43053d 100644
#if ! HAVE_SPLIT_USR
|| path_equal(path, "/usr")
#endif
--
2.36.1

View file

@ -1,7 +1,7 @@
From eb3ff76f95bfe248f517e029ea1b152f4983370a Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Wed, 16 Apr 2014 10:59:28 +0200
Subject: [PATCH 03/18] Fix NixOS containers
Subject: [PATCH] Fix NixOS containers
In NixOS containers, the init script is bind-mounted into the
container, so checking early whether it exists will fail.
@ -10,7 +10,7 @@ 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 c5fd978395..0fa415f5b5 100644
index 4ce80bba70..bb149192bd 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -5651,6 +5651,7 @@ static int run(int argc, char *argv[]) {
@ -29,6 +29,3 @@ index c5fd978395..0fa415f5b5 100644
}
} else {
--
2.36.1

View file

@ -1,7 +1,7 @@
From 789ca236fdc81dc3f514ddad3354eeb5fa8cc7d8 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Thu, 1 May 2014 14:10:10 +0200
Subject: [PATCH 04/18] Look for fsck in the right place
Subject: [PATCH] Look for fsck in the right place
---
src/fsck/fsck.c | 2 +-
@ -20,6 +20,3 @@ index 745d01ff50..dd4eef45c3 100644
cmdline[i++] = arg_repair;
cmdline[i++] = "-T";
--
2.36.1

View file

@ -1,7 +1,7 @@
From 6871d9637bc653a976e04cd595697d7244a293e2 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Fri, 19 Dec 2014 14:46:17 +0100
Subject: [PATCH 05/18] Add some NixOS-specific unit directories
Subject: [PATCH] Add some NixOS-specific unit directories
Look in `/nix/var/nix/profiles/default/lib/systemd/{system,user}` for
units provided by packages installed into the default profile via
@ -92,7 +92,7 @@ index 1f4331a8bf..4b9a8ae26e 100644
if (!add)
diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in
index fc0f8c34fa..162432e77f 100644
index 693433b34b..5932a21b5b 100644
--- a/src/core/systemd.pc.in
+++ b/src/core/systemd.pc.in
@@ -38,10 +38,10 @@ systemdsystemconfdir=${systemd_system_conf_dir}
@ -121,6 +121,3 @@ index fc0f8c34fa..162432e77f 100644
systemdusergeneratorpath=${systemd_user_generator_path}
systemd_sleep_dir=${root_prefix}/lib/systemd/system-sleep
--
2.36.1

View file

@ -1,7 +1,7 @@
From 67daf22c74a780e283a493a0f9fdbbea2ce0aaba Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Mon, 11 May 2015 15:39:38 +0200
Subject: [PATCH 06/18] Get rid of a useless message in user sessions
Subject: [PATCH] Get rid of a useless message in user sessions
Namely lots of variants of
@ -26,6 +26,3 @@ index 296b759959..71ef7f27b4 100644
/* If stopping a unit fails continuously we might enter a stop loop here, hence stop acting on the
* service being unnecessary after a while. */
--
2.36.1

View file

@ -1,8 +1,8 @@
From 21b9acb1d4202a022475a24db727055f9dd2532a Mon Sep 17 00:00:00 2001
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 07/18] hostnamed, localed, timedated: disable methods that
change system settings.
Subject: [PATCH] hostnamed, localed, timedated: disable methods that change
system settings.
---
src/hostname/hostnamed.c | 6 ++++++
@ -103,6 +103,3 @@ index 9ca5d37b75..e41d8d73df 100644
r = context_update_ntp_status(c, bus, m);
if (r < 0)
return r;
--
2.36.1

View file

@ -1,7 +1,7 @@
From 3894fcd76e5791e094c685c0095006b6867893c1 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikolay Amiantov <ab@fmap.me>
Date: Thu, 7 Jul 2016 02:47:13 +0300
Subject: [PATCH 08/18] Fix hwdb paths
Subject: [PATCH] Fix hwdb paths
Patch by vcunat.
---
@ -23,6 +23,3 @@ index 62d27f7b89..87318e041b 100644
- UDEVLIBEXECDIR "/hwdb.bin\0"
+ "/etc/udev/hwdb.bin\0"
+
--
2.36.1

View file

@ -1,7 +1,7 @@
From 322fe2a15ac92d38f6952a2f7fd66e56eaa0f1f4 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikolay Amiantov <ab@fmap.me>
Date: Tue, 11 Oct 2016 13:12:08 +0300
Subject: [PATCH 09/18] Change /usr/share/zoneinfo to /etc/zoneinfo
Subject: [PATCH] Change /usr/share/zoneinfo to /etc/zoneinfo
NixOS uses this path.
---
@ -35,7 +35,7 @@ index e486474c44..5f373d0723 100644
<literal>Etc/UTC</literal>. The resulting link should lead to the
corresponding binary
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index c309369406..e0d84a7cfa 100644
index 0ad8de4b9a..b794c6c7d0 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1281,7 +1281,7 @@ static int get_timezones_from_zone1970_tab(char ***ret) {
@ -88,7 +88,7 @@ index 39160182ef..8dcc3307c8 100644
(void) mkdir_parents(etc_localtime, 0755);
if (symlink(e, etc_localtime) < 0)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 0fa415f5b5..b4404fff49 100644
index bb149192bd..08751ed944 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1901,8 +1901,8 @@ int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid
@ -136,6 +136,3 @@ index e41d8d73df..ff1a384b3b 100644
if (!p)
return -ENOMEM;
--
2.36.1

View file

@ -1,7 +1,7 @@
From 35dd77fafe73cc4a648f101163945cbcae8ed6b9 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Imuli <i@imu.li>
Date: Wed, 19 Oct 2016 08:46:47 -0400
Subject: [PATCH 10/18] localectl: use /etc/X11/xkb for list-x11-*
Subject: [PATCH] localectl: use /etc/X11/xkb for list-x11-*
NixOS has an option to link the xkb data files to /etc/X11, but not to
/usr/share/X11.
@ -22,6 +22,3 @@ index 661d54c27d..e98b578531 100644
if (!f)
return log_error_errno(errno, "Failed to open keyboard mapping list. %m");
--
2.36.1

View file

@ -1,17 +1,17 @@
From 1928e1d8eda7d3e296170bb5bd813463cc3e679c Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Franz Pletz <fpletz@fnordicwalking.de>
Date: Sun, 11 Feb 2018 04:37:44 +0100
Subject: [PATCH 11/18] build: don't create statedir and don't touch prefixdir
Subject: [PATCH] build: don't create statedir and don't touch prefixdir
---
meson.build | 3 ---
1 file changed, 3 deletions(-)
diff --git a/meson.build b/meson.build
index 36cbfa4893..a10d6a3eb7 100644
index 9c170acc0a..818b7a3eb5 100644
--- a/meson.build
+++ b/meson.build
@@ -3926,9 +3926,6 @@ install_data('LICENSE.GPL2',
@@ -3928,9 +3928,6 @@ install_data('LICENSE.GPL2',
install_subdir('LICENSES',
install_dir : docdir)
@ -21,6 +21,3 @@ index 36cbfa4893..a10d6a3eb7 100644
############################################################
# Ensure that changes to the docs/ directory do not break the
--
2.36.1

View file

@ -1,7 +1,7 @@
From 201b588b4b30fb53aefaed43e5d434373a076cb0 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andreas Rammhold <andreas@rammhold.de>
Date: Thu, 9 May 2019 11:15:22 +0200
Subject: [PATCH 12/18] add rootprefix to lookup dir paths
Subject: [PATCH] add rootprefix to lookup dir paths
systemd does not longer use the UDEVLIBEXEC directory as root for
discovery default udev rules. By adding `$out/lib` to the lookup paths
@ -33,6 +33,3 @@ index 0a1ae023a3..cc00ff6c68 100644
#define CONF_PATHS(n) \
CONF_PATHS_USR(n) \
--
2.36.1

View file

@ -1,7 +1,7 @@
From 67434c58caddf7dd3cef66dd3e3f704d39e4bcb0 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikolay Amiantov <ab@fmap.me>
Date: Thu, 25 Jul 2019 20:45:55 +0300
Subject: [PATCH 13/18] systemd-shutdown: execute scripts in
Subject: [PATCH] systemd-shutdown: execute scripts in
/etc/systemd/system-shutdown
This is needed for NixOS to use such scripts as systemd directory is immutable.
@ -22,6 +22,3 @@ index 2c3cbec02c..1b876203c6 100644
/* The log target defaults to console, but the original systemd process will pass its log target in through a
* command line argument, which will override this default. Also, ensure we'll never log to the journal or
--
2.36.1

View file

@ -1,8 +1,7 @@
From db1280d020e6d46a994240e755ce369d895322c5 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nikolay Amiantov <ab@fmap.me>
Date: Thu, 25 Jul 2019 20:46:58 +0300
Subject: [PATCH 14/18] systemd-sleep: execute scripts in
/etc/systemd/system-sleep
Subject: [PATCH] systemd-sleep: execute scripts in /etc/systemd/system-sleep
This is needed for NixOS to use such scripts as systemd directory is immutable.
---
@ -21,6 +20,3 @@ index 65e391d02a..28af2f8bf5 100644
NULL
};
--
2.36.1

View file

@ -1,27 +0,0 @@
From ac9f97341e6fe3fb4b5fe22e72f43312ef5b1ca4 Mon Sep 17 00:00:00 2001
From: Florian Klink <flokli@flokli.de>
Date: Sat, 7 Mar 2020 22:40:27 +0100
Subject: [PATCH 15/18] kmod-static-nodes.service: Update ConditionFileNotEmpty
On NixOS, kernel modules of the currently booted systems are located at
/run/booted-system/kernel-modules/lib/modules/%v/, not /lib/modules/%v/.
---
units/kmod-static-nodes.service.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/units/kmod-static-nodes.service.in b/units/kmod-static-nodes.service.in
index 777e82d16b..b6abc2bba0 100644
--- a/units/kmod-static-nodes.service.in
+++ b/units/kmod-static-nodes.service.in
@@ -12,7 +12,7 @@ Description=Create List of Static Device Nodes
DefaultDependencies=no
Before=sysinit.target systemd-tmpfiles-setup-dev.service
ConditionCapability=CAP_SYS_MODULE
-ConditionFileNotEmpty=/lib/modules/%v/modules.devname
+ConditionFileNotEmpty=/run/booted-system/kernel-modules/lib/modules/%v/modules.devname
[Service]
Type=oneshot
--
2.36.1

View file

@ -1,7 +1,7 @@
From 6f40d7a9d0029b5a805245b938ac62e7b150ea75 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Florian Klink <flokli@flokli.de>
Date: Sun, 8 Mar 2020 01:05:54 +0100
Subject: [PATCH 16/18] path-util.h: add placeholder for DEFAULT_PATH_NORMAL
Subject: [PATCH] path-util.h: add placeholder for DEFAULT_PATH_NORMAL
This will be the $PATH used to lookup ExecStart= etc. options, which
systemd itself uses extensively.
@ -28,6 +28,3 @@ index 553aa4fb58..46294f4bb1 100644
#if HAVE_SPLIT_USR
# define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR
--
2.36.1

View file

@ -1,7 +1,7 @@
From 8d9355264f11034a28ad78e4e70809908acfdb3e Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Sun, 6 Dec 2020 08:34:19 +0100
Subject: [PATCH 17/18] pkg-config: derive prefix from --prefix
Subject: [PATCH] pkg-config: derive prefix from --prefix
Point prefix to the one configured, instead of `/usr` `systemd` has limited
support for making the pkgconfig prefix overridable, and interpolates those
@ -16,7 +16,7 @@ Co-Authored-By: Florian Klink <flokli@flokli.de>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in
index 162432e77f..2fc20daf03 100644
index 5932a21b5b..20bf8e316d 100644
--- a/src/core/systemd.pc.in
+++ b/src/core/systemd.pc.in
@@ -11,7 +11,7 @@
@ -28,6 +28,3 @@ index 162432e77f..2fc20daf03 100644
root_prefix={{ROOTPREFIX_NOSLASH}}
rootprefix=${root_prefix}
sysconf_dir={{SYSCONF_DIR}}
--
2.36.1

View file

@ -1,7 +1,7 @@
From 291ead07daab980fa39fd18512c8266c23161540 Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Yuriy Taraday <yorik.sar@gmail.com>
Date: Fri, 17 Jun 2022 12:45:10 +0000
Subject: [PATCH 18/18] inherit systemd environment when calling generators.
Subject: [PATCH] inherit systemd environment when calling generators.
Systemd generators need access to the environment configured in
stage-2-init.sh since it schedules fsck and mkfs executions based on
@ -37,6 +37,3 @@ index 71ef7f27b4..33ded94a7c 100644
r = strv_env_assign(&nl, "SYSTEMD_SCOPE", MANAGER_IS_SYSTEM(m) ? "system" : "user");
if (r < 0)
--
2.36.1

View file

@ -149,7 +149,8 @@ stdenv.mkDerivation {
# On major changes, or when otherwise required, you *must* reformat the patches,
# `git am path/to/00*.patch` them into a systemd worktree, rebase to the more recent
# systemd version, and export the patches again via `git -c format.signoff=false format-patch v${version}`.
# systemd version, and export the patches again via
# `git -c format.signoff=false format-patch v${version} --no-numbered --zero-commit --no-signature`.
# Use `find . -name "*.patch" | sort` to get an up-to-date listing of all patches
patches = [
./0001-Start-device-units-for-uninitialised-encrypted-devic.patch
@ -166,10 +167,9 @@ stdenv.mkDerivation {
./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-kmod-static-nodes.service-Update-ConditionFileNotEmp.patch
./0016-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch
./0017-pkg-config-derive-prefix-from-prefix.patch
./0018-inherit-systemd-environment-when-calling-generators.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
] ++ lib.optional stdenv.hostPlatform.isMusl (
let
oe-core = fetchzip {