1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Yuriy Taraday <yorik.sar@gmail.com>
3Date: Fri, 17 Jun 2022 12:45:10 +0000
4Subject: [PATCH] inherit systemd environment when calling generators.
5
6Systemd generators need access to the environment configured in
7stage-2-init.sh since it schedules fsck and mkfs executions based on
8being able to find an appropriate binary for the target filesystem.
9
10With this commit I am altering the systemd behaviour since upstream
11tries to gather environments with that they call
12"environment-generators" and then seems to pass that on to all the other
13executables that are being called from managers.
14---
15 src/core/manager.c | 8 ++++++++
16 1 file changed, 8 insertions(+)
17
18diff --git a/src/core/manager.c b/src/core/manager.c
19index 4c24ce5c98..3c944559fc 100644
20--- a/src/core/manager.c
21+++ b/src/core/manager.c
22@@ -4135,9 +4135,17 @@ static int build_generator_environment(Manager *m, char ***ret) {
23 * adjust generated units to that. Let's pass down some bits of information that are easy for us to
24 * determine (but a bit harder for generator scripts to determine), as environment variables. */
25
26+ // On NixOS we must propagate PATH to generators so they are
27+ // able to find binaries such as `fsck.${fstype}` and
28+ // `mkfs.${fstype}`. That is why we ignore transient_environment that
29+ // overrides the PATH variable. This propagates systemd's
30+ // environment (e.g. PATH) that was setup
31+ // before calling systemd from stage-2-init.sh.
32+#if 0
33 nl = strv_copy(m->transient_environment);
34 if (!nl)
35 return -ENOMEM;
36+#endif
37
38 r = strv_env_assign(&nl, "SYSTEMD_SCOPE", runtime_scope_to_string(m->runtime_scope));
39 if (r < 0)