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

nixos/systemd: make sure all the device nodes are created in stage1

authored by Florian Klink and committed by GitHub ad29dc19 3707e389

+56 -126
+6
nixos/modules/system/boot/systemd.nix
··· 592 592 systemd.services.systemd-importd.environment = proxy_env; 593 593 systemd.services.systemd-pstore.wantedBy = [ "sysinit.target" ]; # see #81138 594 594 595 + # NixOS has kernel modules in a different location, so override that here. 596 + systemd.services.kmod-static-nodes.unitConfig.ConditionFileNotEmpty = [ 597 + "" # required to unset the previous value! 598 + "/run/booted-system/kernel-modules/lib/modules/%v/modules.devname" 599 + ]; 600 + 595 601 # Don't bother with certain units in containers. 596 602 systemd.services.systemd-remount-fs.unitConfig.ConditionVirtualization = "!container"; 597 603 systemd.services.systemd-random-seed.unitConfig.ConditionVirtualization = "!container";
+3
nixos/modules/system/boot/systemd/initrd.nix
··· 420 420 services."systemd-makefs@" = lib.mkIf needMakefs { unitConfig.IgnoreOnIsolate = true; }; 421 421 services."systemd-growfs@" = lib.mkIf needGrowfs { unitConfig.IgnoreOnIsolate = true; }; 422 422 423 + # make sure all the /dev nodes are set up 424 + services.systemd-tmpfiles-setup-dev.wantedBy = ["sysinit.target"]; 425 + 423 426 services.initrd-nixos-activation = { 424 427 after = [ "initrd-fs.target" ]; 425 428 requiredBy = [ "initrd.target" ];
+2 -5
pkgs/os-specific/linux/systemd/0001-Start-device-units-for-uninitialised-encrypted-devic.patch
··· 1 - From c8b50208dce4c467c1f85c3db3e05bdcfd43c378 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Tue, 8 Jan 2013 15:46:30 +0100 4 - Subject: [PATCH 01/18] Start device units for uninitialised encrypted devices 4 + Subject: [PATCH] Start device units for uninitialised encrypted devices 5 5 6 6 This is necessary because the NixOS service that initialises the 7 7 filesystem depends on the appearance of the device unit. Also, this ··· 27 27 # add symlink to GPT root disk 28 28 SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}!="crypto_LUKS", SYMLINK+="gpt-auto-root" 29 29 SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}=="crypto_LUKS", SYMLINK+="gpt-auto-root-luks" 30 - -- 31 - 2.36.1 32 -
+2 -5
pkgs/os-specific/linux/systemd/0002-Don-t-try-to-unmount-nix-or-nix-store.patch
··· 1 - From c884aee4c66c97f592ae0f8ebd97f48a39d8c53c Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Fri, 12 Apr 2013 13:16:57 +0200 4 - Subject: [PATCH 02/18] Don't try to unmount /nix or /nix/store 4 + Subject: [PATCH] Don't try to unmount /nix or /nix/store 5 5 6 6 They'll still be remounted read-only. 7 7 ··· 37 37 #if ! HAVE_SPLIT_USR 38 38 || path_equal(path, "/usr") 39 39 #endif 40 - -- 41 - 2.36.1 42 -
+3 -6
pkgs/os-specific/linux/systemd/0003-Fix-NixOS-containers.patch
··· 1 - From eb3ff76f95bfe248f517e029ea1b152f4983370a Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Wed, 16 Apr 2014 10:59:28 +0200 4 - Subject: [PATCH 03/18] Fix NixOS containers 4 + Subject: [PATCH] Fix NixOS containers 5 5 6 6 In NixOS containers, the init script is bind-mounted into the 7 7 container, so checking early whether it exists will fail. ··· 10 10 1 file changed, 2 insertions(+) 11 11 12 12 diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c 13 - index c5fd978395..0fa415f5b5 100644 13 + index 4ce80bba70..bb149192bd 100644 14 14 --- a/src/nspawn/nspawn.c 15 15 +++ b/src/nspawn/nspawn.c 16 16 @@ -5651,6 +5651,7 @@ static int run(int argc, char *argv[]) { ··· 29 29 } 30 30 31 31 } else { 32 - -- 33 - 2.36.1 34 -
+2 -5
pkgs/os-specific/linux/systemd/0004-Look-for-fsck-in-the-right-place.patch
··· 1 - From 789ca236fdc81dc3f514ddad3354eeb5fa8cc7d8 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Thu, 1 May 2014 14:10:10 +0200 4 - Subject: [PATCH 04/18] Look for fsck in the right place 4 + Subject: [PATCH] Look for fsck in the right place 5 5 6 6 --- 7 7 src/fsck/fsck.c | 2 +- ··· 20 20 cmdline[i++] = arg_repair; 21 21 cmdline[i++] = "-T"; 22 22 23 - -- 24 - 2.36.1 25 -
+3 -6
pkgs/os-specific/linux/systemd/0005-Add-some-NixOS-specific-unit-directories.patch
··· 1 - From 6871d9637bc653a976e04cd595697d7244a293e2 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Fri, 19 Dec 2014 14:46:17 +0100 4 - Subject: [PATCH 05/18] Add some NixOS-specific unit directories 4 + Subject: [PATCH] Add some NixOS-specific unit directories 5 5 6 6 Look in `/nix/var/nix/profiles/default/lib/systemd/{system,user}` for 7 7 units provided by packages installed into the default profile via ··· 92 92 93 93 if (!add) 94 94 diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in 95 - index fc0f8c34fa..162432e77f 100644 95 + index 693433b34b..5932a21b5b 100644 96 96 --- a/src/core/systemd.pc.in 97 97 +++ b/src/core/systemd.pc.in 98 98 @@ -38,10 +38,10 @@ systemdsystemconfdir=${systemd_system_conf_dir} ··· 121 121 systemdusergeneratorpath=${systemd_user_generator_path} 122 122 123 123 systemd_sleep_dir=${root_prefix}/lib/systemd/system-sleep 124 - -- 125 - 2.36.1 126 -
+2 -5
pkgs/os-specific/linux/systemd/0006-Get-rid-of-a-useless-message-in-user-sessions.patch
··· 1 - From 67daf22c74a780e283a493a0f9fdbbea2ce0aaba Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Eelco Dolstra <eelco.dolstra@logicblox.com> 3 3 Date: Mon, 11 May 2015 15:39:38 +0200 4 - Subject: [PATCH 06/18] Get rid of a useless message in user sessions 4 + Subject: [PATCH] Get rid of a useless message in user sessions 5 5 6 6 Namely lots of variants of 7 7 ··· 26 26 27 27 /* If stopping a unit fails continuously we might enter a stop loop here, hence stop acting on the 28 28 * service being unnecessary after a while. */ 29 - -- 30 - 2.36.1 31 -
+3 -6
pkgs/os-specific/linux/systemd/0007-hostnamed-localed-timedated-disable-methods-that-cha.patch
··· 1 - From 21b9acb1d4202a022475a24db727055f9dd2532a Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Gabriel Ebner <gebner@gebner.org> 3 3 Date: Sun, 6 Dec 2015 14:26:36 +0100 4 - Subject: [PATCH 07/18] hostnamed, localed, timedated: disable methods that 5 - change system settings. 4 + Subject: [PATCH] hostnamed, localed, timedated: disable methods that change 5 + system settings. 6 6 7 7 --- 8 8 src/hostname/hostnamed.c | 6 ++++++ ··· 103 103 r = context_update_ntp_status(c, bus, m); 104 104 if (r < 0) 105 105 return r; 106 - -- 107 - 2.36.1 108 -
+2 -5
pkgs/os-specific/linux/systemd/0008-Fix-hwdb-paths.patch
··· 1 - From 3894fcd76e5791e094c685c0095006b6867893c1 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Nikolay Amiantov <ab@fmap.me> 3 3 Date: Thu, 7 Jul 2016 02:47:13 +0300 4 - Subject: [PATCH 08/18] Fix hwdb paths 4 + Subject: [PATCH] Fix hwdb paths 5 5 6 6 Patch by vcunat. 7 7 --- ··· 23 23 - UDEVLIBEXECDIR "/hwdb.bin\0" 24 24 + "/etc/udev/hwdb.bin\0" 25 25 + 26 - -- 27 - 2.36.1 28 -
+4 -7
pkgs/os-specific/linux/systemd/0009-Change-usr-share-zoneinfo-to-etc-zoneinfo.patch
··· 1 - From 322fe2a15ac92d38f6952a2f7fd66e56eaa0f1f4 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Nikolay Amiantov <ab@fmap.me> 3 3 Date: Tue, 11 Oct 2016 13:12:08 +0300 4 - Subject: [PATCH 09/18] Change /usr/share/zoneinfo to /etc/zoneinfo 4 + Subject: [PATCH] Change /usr/share/zoneinfo to /etc/zoneinfo 5 5 6 6 NixOS uses this path. 7 7 --- ··· 35 35 <literal>Etc/UTC</literal>. The resulting link should lead to the 36 36 corresponding binary 37 37 diff --git a/src/basic/time-util.c b/src/basic/time-util.c 38 - index c309369406..e0d84a7cfa 100644 38 + index 0ad8de4b9a..b794c6c7d0 100644 39 39 --- a/src/basic/time-util.c 40 40 +++ b/src/basic/time-util.c 41 41 @@ -1281,7 +1281,7 @@ static int get_timezones_from_zone1970_tab(char ***ret) { ··· 88 88 (void) mkdir_parents(etc_localtime, 0755); 89 89 if (symlink(e, etc_localtime) < 0) 90 90 diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c 91 - index 0fa415f5b5..b4404fff49 100644 91 + index bb149192bd..08751ed944 100644 92 92 --- a/src/nspawn/nspawn.c 93 93 +++ b/src/nspawn/nspawn.c 94 94 @@ -1901,8 +1901,8 @@ int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid ··· 136 136 if (!p) 137 137 return -ENOMEM; 138 138 139 - -- 140 - 2.36.1 141 -
+2 -5
pkgs/os-specific/linux/systemd/0010-localectl-use-etc-X11-xkb-for-list-x11.patch
··· 1 - From 35dd77fafe73cc4a648f101163945cbcae8ed6b9 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Imuli <i@imu.li> 3 3 Date: Wed, 19 Oct 2016 08:46:47 -0400 4 - Subject: [PATCH 10/18] localectl: use /etc/X11/xkb for list-x11-* 4 + Subject: [PATCH] localectl: use /etc/X11/xkb for list-x11-* 5 5 6 6 NixOS has an option to link the xkb data files to /etc/X11, but not to 7 7 /usr/share/X11. ··· 22 22 if (!f) 23 23 return log_error_errno(errno, "Failed to open keyboard mapping list. %m"); 24 24 25 - -- 26 - 2.36.1 27 -
+4 -7
pkgs/os-specific/linux/systemd/0011-build-don-t-create-statedir-and-don-t-touch-prefixdi.patch
··· 1 - From 1928e1d8eda7d3e296170bb5bd813463cc3e679c Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Franz Pletz <fpletz@fnordicwalking.de> 3 3 Date: Sun, 11 Feb 2018 04:37:44 +0100 4 - Subject: [PATCH 11/18] build: don't create statedir and don't touch prefixdir 4 + Subject: [PATCH] build: don't create statedir and don't touch prefixdir 5 5 6 6 --- 7 7 meson.build | 3 --- 8 8 1 file changed, 3 deletions(-) 9 9 10 10 diff --git a/meson.build b/meson.build 11 - index 36cbfa4893..a10d6a3eb7 100644 11 + index 9c170acc0a..818b7a3eb5 100644 12 12 --- a/meson.build 13 13 +++ b/meson.build 14 - @@ -3926,9 +3926,6 @@ install_data('LICENSE.GPL2', 14 + @@ -3928,9 +3928,6 @@ install_data('LICENSE.GPL2', 15 15 install_subdir('LICENSES', 16 16 install_dir : docdir) 17 17 ··· 21 21 ############################################################ 22 22 23 23 # Ensure that changes to the docs/ directory do not break the 24 - -- 25 - 2.36.1 26 -
+2 -5
pkgs/os-specific/linux/systemd/0012-add-rootprefix-to-lookup-dir-paths.patch
··· 1 - From 201b588b4b30fb53aefaed43e5d434373a076cb0 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Andreas Rammhold <andreas@rammhold.de> 3 3 Date: Thu, 9 May 2019 11:15:22 +0200 4 - Subject: [PATCH 12/18] add rootprefix to lookup dir paths 4 + Subject: [PATCH] add rootprefix to lookup dir paths 5 5 6 6 systemd does not longer use the UDEVLIBEXEC directory as root for 7 7 discovery default udev rules. By adding `$out/lib` to the lookup paths ··· 33 33 34 34 #define CONF_PATHS(n) \ 35 35 CONF_PATHS_USR(n) \ 36 - -- 37 - 2.36.1 38 -
+2 -5
pkgs/os-specific/linux/systemd/0013-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch
··· 1 - From 67434c58caddf7dd3cef66dd3e3f704d39e4bcb0 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Nikolay Amiantov <ab@fmap.me> 3 3 Date: Thu, 25 Jul 2019 20:45:55 +0300 4 - Subject: [PATCH 13/18] systemd-shutdown: execute scripts in 4 + Subject: [PATCH] systemd-shutdown: execute scripts in 5 5 /etc/systemd/system-shutdown 6 6 7 7 This is needed for NixOS to use such scripts as systemd directory is immutable. ··· 22 22 23 23 /* The log target defaults to console, but the original systemd process will pass its log target in through a 24 24 * command line argument, which will override this default. Also, ensure we'll never log to the journal or 25 - -- 26 - 2.36.1 27 -
+2 -6
pkgs/os-specific/linux/systemd/0014-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch
··· 1 - From db1280d020e6d46a994240e755ce369d895322c5 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Nikolay Amiantov <ab@fmap.me> 3 3 Date: Thu, 25 Jul 2019 20:46:58 +0300 4 - Subject: [PATCH 14/18] systemd-sleep: execute scripts in 5 - /etc/systemd/system-sleep 4 + Subject: [PATCH] systemd-sleep: execute scripts in /etc/systemd/system-sleep 6 5 7 6 This is needed for NixOS to use such scripts as systemd directory is immutable. 8 7 --- ··· 21 20 NULL 22 21 }; 23 22 24 - -- 25 - 2.36.1 26 -
-27
pkgs/os-specific/linux/systemd/0015-kmod-static-nodes.service-Update-ConditionFileNotEmp.patch
··· 1 - From ac9f97341e6fe3fb4b5fe22e72f43312ef5b1ca4 Mon Sep 17 00:00:00 2001 2 - From: Florian Klink <flokli@flokli.de> 3 - Date: Sat, 7 Mar 2020 22:40:27 +0100 4 - Subject: [PATCH 15/18] kmod-static-nodes.service: Update ConditionFileNotEmpty 5 - 6 - On NixOS, kernel modules of the currently booted systems are located at 7 - /run/booted-system/kernel-modules/lib/modules/%v/, not /lib/modules/%v/. 8 - --- 9 - units/kmod-static-nodes.service.in | 2 +- 10 - 1 file changed, 1 insertion(+), 1 deletion(-) 11 - 12 - diff --git a/units/kmod-static-nodes.service.in b/units/kmod-static-nodes.service.in 13 - index 777e82d16b..b6abc2bba0 100644 14 - --- a/units/kmod-static-nodes.service.in 15 - +++ b/units/kmod-static-nodes.service.in 16 - @@ -12,7 +12,7 @@ Description=Create List of Static Device Nodes 17 - DefaultDependencies=no 18 - Before=sysinit.target systemd-tmpfiles-setup-dev.service 19 - ConditionCapability=CAP_SYS_MODULE 20 - -ConditionFileNotEmpty=/lib/modules/%v/modules.devname 21 - +ConditionFileNotEmpty=/run/booted-system/kernel-modules/lib/modules/%v/modules.devname 22 - 23 - [Service] 24 - Type=oneshot 25 - -- 26 - 2.36.1 27 -
+2 -5
pkgs/os-specific/linux/systemd/0016-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch pkgs/os-specific/linux/systemd/0015-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch
··· 1 - From 6f40d7a9d0029b5a805245b938ac62e7b150ea75 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Florian Klink <flokli@flokli.de> 3 3 Date: Sun, 8 Mar 2020 01:05:54 +0100 4 - Subject: [PATCH 16/18] path-util.h: add placeholder for DEFAULT_PATH_NORMAL 4 + Subject: [PATCH] path-util.h: add placeholder for DEFAULT_PATH_NORMAL 5 5 6 6 This will be the $PATH used to lookup ExecStart= etc. options, which 7 7 systemd itself uses extensively. ··· 28 28 29 29 #if HAVE_SPLIT_USR 30 30 # define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR 31 - -- 32 - 2.36.1 33 -
+3 -6
pkgs/os-specific/linux/systemd/0017-pkg-config-derive-prefix-from-prefix.patch pkgs/os-specific/linux/systemd/0016-pkg-config-derive-prefix-from-prefix.patch
··· 1 - From 8d9355264f11034a28ad78e4e70809908acfdb3e Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io> 3 3 Date: Sun, 6 Dec 2020 08:34:19 +0100 4 - Subject: [PATCH 17/18] pkg-config: derive prefix from --prefix 4 + Subject: [PATCH] pkg-config: derive prefix from --prefix 5 5 6 6 Point prefix to the one configured, instead of `/usr` `systemd` has limited 7 7 support for making the pkgconfig prefix overridable, and interpolates those ··· 16 16 1 file changed, 1 insertion(+), 1 deletion(-) 17 17 18 18 diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in 19 - index 162432e77f..2fc20daf03 100644 19 + index 5932a21b5b..20bf8e316d 100644 20 20 --- a/src/core/systemd.pc.in 21 21 +++ b/src/core/systemd.pc.in 22 22 @@ -11,7 +11,7 @@ ··· 28 28 root_prefix={{ROOTPREFIX_NOSLASH}} 29 29 rootprefix=${root_prefix} 30 30 sysconf_dir={{SYSCONF_DIR}} 31 - -- 32 - 2.36.1 33 -
+2 -5
pkgs/os-specific/linux/systemd/0018-inherit-systemd-environment-when-calling-generators.patch pkgs/os-specific/linux/systemd/0017-inherit-systemd-environment-when-calling-generators.patch
··· 1 - From 291ead07daab980fa39fd18512c8266c23161540 Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Yuriy Taraday <yorik.sar@gmail.com> 3 3 Date: Fri, 17 Jun 2022 12:45:10 +0000 4 - Subject: [PATCH 18/18] inherit systemd environment when calling generators. 4 + Subject: [PATCH] inherit systemd environment when calling generators. 5 5 6 6 Systemd generators need access to the environment configured in 7 7 stage-2-init.sh since it schedules fsck and mkfs executions based on ··· 37 37 38 38 r = strv_env_assign(&nl, "SYSTEMD_SCOPE", MANAGER_IS_SYSTEM(m) ? "system" : "user"); 39 39 if (r < 0) 40 - -- 41 - 2.36.1 42 -
+5 -5
pkgs/os-specific/linux/systemd/default.nix
··· 149 149 150 150 # On major changes, or when otherwise required, you *must* reformat the patches, 151 151 # `git am path/to/00*.patch` them into a systemd worktree, rebase to the more recent 152 - # systemd version, and export the patches again via `git -c format.signoff=false format-patch v${version}`. 152 + # systemd version, and export the patches again via 153 + # `git -c format.signoff=false format-patch v${version} --no-numbered --zero-commit --no-signature`. 153 154 # Use `find . -name "*.patch" | sort` to get an up-to-date listing of all patches 154 155 patches = [ 155 156 ./0001-Start-device-units-for-uninitialised-encrypted-devic.patch ··· 166 167 ./0012-add-rootprefix-to-lookup-dir-paths.patch 167 168 ./0013-systemd-shutdown-execute-scripts-in-etc-systemd-syst.patch 168 169 ./0014-systemd-sleep-execute-scripts-in-etc-systemd-system-.patch 169 - ./0015-kmod-static-nodes.service-Update-ConditionFileNotEmp.patch 170 - ./0016-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch 171 - ./0017-pkg-config-derive-prefix-from-prefix.patch 172 - ./0018-inherit-systemd-environment-when-calling-generators.patch 170 + ./0015-path-util.h-add-placeholder-for-DEFAULT_PATH_NORMAL.patch 171 + ./0016-pkg-config-derive-prefix-from-prefix.patch 172 + ./0017-inherit-systemd-environment-when-calling-generators.patch 173 173 ] ++ lib.optional stdenv.hostPlatform.isMusl ( 174 174 let 175 175 oe-core = fetchzip {