["chroot", "/work/prepare", "build"],
apivfs=state.root,
scripts=dict(chroot=chroot_cmd(state.root, options=options, network=True)),
- env=dict(SRCDIR="/work/src") | state.environment,
+ env=dict(SRCDIR="/work/src") | state.config.environment,
)
shutil.rmtree(state.root / "work")
else:
["chroot", "/work/prepare", "final"],
apivfs=state.root,
scripts=dict(chroot=chroot_cmd(state.root, options=options, network=True)),
- env=dict(SRCDIR="/work/src") | state.environment,
+ env=dict(SRCDIR="/work/src") | state.config.environment,
)
shutil.rmtree(state.root / "work")
network=state.config.with_network,
),
),
- env=state.environment,
+ env=state.config.environment,
)
shutil.rmtree(state.root / "work")
with complete_step("Running finalize script…"):
run([state.config.finalize_script],
- env={**state.environment, "BUILDROOT": str(state.root), "OUTPUTDIR": str(state.staging)})
+ env={**state.config.environment, "BUILDROOT": str(state.root), "OUTPUTDIR": str(state.staging)})
def certificate_common_name(state: MkosiState, certificate: Path) -> str:
cmd=["chroot", "sh", "-c", cmd],
apivfs=state.root,
scripts=dict(chroot=chroot_cmd(state.root)),
- env=state.environment,
+ env=state.config.environment,
)
for fs, options in state.installer.filesystem_options(state).items():
env[f"SYSTEMD_REPART_MKFS_OPTIONS_{fs.upper()}"] = " ".join(options)
- for option, value in state.environment.items():
+ for option, value in state.config.environment.items():
if option.startswith("SYSTEMD_REPART_MKFS_OPTIONS_"):
env[option] = value
["chroot", "/work/build-script"],
apivfs=state.root,
scripts=dict(chroot=chroot_cmd(state.root, options=options, network=state.config.with_network)),
- env=env | state.environment,
+ env=env | state.config.environment,
)
return cmdline
+def load_environment(args: argparse.Namespace) -> dict[str, str]:
+ env = {}
+
+ if args.image_id is not None:
+ env["IMAGE_ID"] = args.image_id
+ if args.image_version is not None:
+ env["IMAGE_VERSION"] = args.image_version
+ if (proxy := os.environ.get("http_proxy")):
+ env["http_proxy"] = proxy
+ if (proxy := os.environ.get("https_proxy")):
+ env["https_proxy"] = proxy
+
+ # Mypy doesn't like | here.
+ return {**env, **args.environment}
+
+
def load_args(args: argparse.Namespace) -> MkosiArgs:
if args.debug:
ARG_DEBUG.set(args.debug)
args.credentials = load_credentials(args)
args.kernel_command_line_extra = load_kernel_command_line_extra(args)
+ args.environment = load_environment(args)
if args.secure_boot and args.verb != Verb.genkey:
if args.secure_boot_key is None:
bwrap(cmdline,
apivfs=state.root if apivfs else None,
- env=dict(KERNEL_INSTALL_BYPASS="1") | state.environment)
+ env=dict(KERNEL_INSTALL_BYPASS="1") | state.config.environment)
bwrap(["apt-get", *options, operation, *packages],
apivfs=state.root if apivfs else None,
- env=env | state.environment)
+ env=env | state.config.environment)
def install_apt_sources(state: MkosiState, repos: Sequence[str]) -> None:
bwrap(cmdline,
apivfs=state.root if apivfs else None,
- env=dict(KERNEL_INSTALL_BYPASS="1") | env | state.environment)
+ env=dict(KERNEL_INSTALL_BYPASS="1") | env | state.config.environment)
fixup_rpmdb_location(state.root)
"parallel-install",
*(["noman", "nodoc", "noinfo"] if state.config.with_docs else []),
]),
- ) | env | state.environment,
+ ) | env | state.config.environment,
)
bwrap(cmdline,
apivfs=state.root if apivfs else None,
- env=dict(ZYPP_CONF=str(state.pkgmngr / "etc/zypp/zypp.conf"), KERNEL_INSTALL_BYPASS="1") | state.environment)
+ env=dict(ZYPP_CONF=str(state.pkgmngr / "etc/zypp/zypp.conf"), KERNEL_INSTALL_BYPASS="1") | state.config.environment)
fixup_rpmdb_location(state.root)
# SPDX-License-Identifier: LGPL-2.1+
import importlib
-import os
import tempfile
from pathlib import Path
self._workspace = tempfile.TemporaryDirectory(dir=config.workspace_dir or Path.cwd(), prefix=".mkosi.tmp")
- self.environment = self.config.environment.copy()
- if self.config.image_id is not None:
- self.environment["IMAGE_ID"] = self.config.image_id
- if self.config.image_version is not None:
- self.environment["IMAGE_VERSION"] = self.config.image_version
- if (proxy := os.environ.get("http_proxy")):
- self.environment["http_proxy"] = proxy
- if (proxy := os.environ.get("https_proxy")):
- self.environment["https_proxy"] = proxy
-
try:
distro = str(self.config.distribution)
mod = importlib.import_module(f"mkosi.distributions.{distro}")