initrd_include: list[Path]
dependencies: list[str]
minimum_version: Optional[GenericVersion]
+ pass_environment: list[str]
distribution: Distribution
release: str
paths=("mkosi.configure",),
help="Configure script to run before doing anything",
),
+ ConfigSetting(
+ dest="pass_environment",
+ metavar="NAME",
+ section="Config",
+ parse=config_make_list_parser(delimiter=" "),
+ help="Environment variables to pass to subimages",
+ ),
ConfigSetting(
dest="distribution",
short="-d",
elif hasattr(ParseContext.cli, s.dest):
delattr(ParseContext.cli, s.dest)
+ setattr(
+ ParseContext.cli,
+ "environment",
+ {
+ name: getattr(ParseContext.config, "environment")[name]
+ for name in getattr(ParseContext.config, "pass_environment", {})
+ if name in getattr(ParseContext.config, "environment", {})
+ }
+ )
+
for p in sorted(Path("mkosi.images").iterdir()):
if not p.is_dir() and not p.suffix == ".conf":
continue
Dependencies: {line_join_list(config.dependencies)}
Minimum Version: {none_to_none(config.minimum_version)}
Configure Scripts: {line_join_list(config.configure_scripts)}
+ Pass Environment: {line_join_list(config.pass_environment)}
{bold("DISTRIBUTION")}:
Distribution: {bold(config.distribution)}
the configure scripts for this image. See the **Scripts** section for
more information.
+`PassEnvironment=`, `--pass-environment=`
+: Takes a list of environment variable names separated by spaces. When
+ building multiple images, pass the listed environment variables to
+ each individual subimage as if they were "universal" settings. See
+ the **Building multiple images** section for more information.
+
## Specifiers
The current value of various settings can be accessed when parsing
(d / "mkosi.conf").write_text(
"""\
+ [Config]
+ PassEnvironment=PassThisEnv
+
[Content]
Environment=TestValue2=300
TestValue3=400
+ PassThisEnv=abc
EnvironmentFiles=other.env
"""
)
"""
)
+ (d / "mkosi.images").mkdir()
+ (d / "mkosi.images/sub.conf").touch()
+
with chdir(d):
- _, [config] = parse_config()
+ _, [sub, config] = parse_config()
expected = {
"TestValue1": "100", # from other.env
assert {k: config.environment[k] for k in expected.keys()} == expected
assert config.environment_files == [Path.cwd() / "mkosi.env", Path.cwd() / "other.env"]
+
+ assert sub.environment["PassThisEnv"] == "abc"
+ assert "TestValue2" not in sub.environment
}
],
"Packages": [],
+ "PassEnvironment": [
+ "abc"
+ ],
"Passphrase": null,
"PostInstallationScripts": [
"/bar/qux"
package_directories=[],
package_manager_trees=[ConfigTree(Path("/foo/bar"), None)],
packages=[],
+ pass_environment=["abc"],
passphrase=None,
postinst_scripts=[Path("/bar/qux")],
postoutput_scripts=[Path("/foo/src")],