]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
nspawn Environment variable passing fixes
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 May 2024 15:01:11 +0000 (17:01 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 May 2024 15:42:52 +0000 (17:42 +0200)
- Translate '-' to '_'
- Ignore names with dot in them
- Pass lowercase as environment variable as well if it has a '=' in it

mkosi/__init__.py

index 619dd172d3da2394db0c74a37a47f73ceb89d810..3fda69b59ff949952cf25a6c9a0e1353bfeefd1e 100644 (file)
@@ -4000,14 +4000,14 @@ def run_shell(args: Args, config: Config) -> None:
             # Add nspawn options first since systemd-nspawn ignores all options after the first argument.
             argv = args.cmdline
 
+            # When invoked by the kernel, all unknown arguments are passed as environment variables to pid1. Let's
+            # mimick the same behavior when we invoke nspawn as a container.
             for arg in itertools.chain(config.kernel_command_line, config.kernel_command_line_extra):
-                name, sep, _ = arg.partition("=")
+                name, sep, value = 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]
+                # If there's a '.' in the argument name, it's not considered an environment variable by the kernel.
+                if sep and "." not in name:
+                    cmdline += ["--setenv", f"{name.replace('-', '_')}={value}"]
                 else:
                     # kernel cmdline config of the form systemd.xxx= get interpreted by systemd when running in nspawn
                     # as well.