]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Pass arguments that look like env variables as env to systemd-nspawn 2724/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 May 2024 13:21:55 +0000 (15:21 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 May 2024 13:21:55 +0000 (15:21 +0200)
The kernel passes unknown parameters as environment variables to pid1.
Let's do the same for systemd-nspawn. Of course we don't know what is
known and unknown so let's take advantage of the fact that kernel cmdline
arguments are (usually) lower case and environment variables are (usually)
upper case and use that to determine whether to pass something as an argument
or an environment variable.

mkosi/__init__.py

index 4bd9b660628d338c065f64397ae368048135ae96..619dd172d3da2394db0c74a37a47f73ceb89d810 100644 (file)
@@ -3998,11 +3998,22 @@ def run_shell(args: Args, config: Config) -> None:
 
         if args.verb == Verb.boot:
             # Add nspawn options first since systemd-nspawn ignores all options after the first argument.
-            cmdline += args.cmdline
-            # kernel cmdline config of the form systemd.xxx= get interpreted by systemd when running in nspawn as
-            # well.
-            cmdline += config.kernel_command_line
-            cmdline += config.kernel_command_line_extra
+            argv = args.cmdline
+
+            for arg in itertools.chain(config.kernel_command_line, config.kernel_command_line_extra):
+                name, sep, _ = arg.partition("=")
+
+                if sep and name.isupper():
+                    # When invoked by the kernel, all unknown arguments are passed as environment variables to pid1.
+                    # Let's mimick the same behavior when we invoked nspawn as a container but only for upper case
+                    # arguments.
+                    cmdline += ["--setenv", arg]
+                else:
+                    # kernel cmdline config of the form systemd.xxx= get interpreted by systemd when running in nspawn
+                    # as well.
+                    argv += [arg]
+
+            cmdline += argv
         elif args.cmdline:
             cmdline += ["--"]
             cmdline += args.cmdline