# SPDX-License-Identifier: LGPL-2.1+
+import contextlib
import enum
import logging
import os
from typing import Optional
from mkosi.log import ARG_DEBUG_SHELL
-from mkosi.mounts import finalize_passwd_mounts
+from mkosi.mounts import finalize_passwd_mounts, mount_overlay
from mkosi.run import find_binary, log_process_failure, run
from mkosi.state import MkosiState
from mkosi.types import _FILE, CompletedProcess, PathString
cmdline += [setpgid, "--foreground", "--"]
try:
- result = run(
- [*cmdline, *cmd],
- env=env,
- log=False,
- stdin=stdin,
- stdout=stdout,
- stderr=stderr,
- input=input,
- check=check,
- )
+ with (
+ mount_overlay([Path("/usr"), state.pkgmngr / "usr"], where=Path("/usr"), lazy=True)
+ if (state.pkgmngr / "usr").exists()
+ else contextlib.nullcontext()
+ ):
+ return run(
+ [*cmdline, *cmd],
+ env=env,
+ log=False,
+ stdin=stdin,
+ stdout=stdout,
+ stderr=stderr,
+ input=input,
+ check=check,
+ )
except subprocess.CalledProcessError as e:
if log:
log_process_failure([os.fspath(s) for s in cmd], e.returncode)
run([*cmdline, "sh"], stdin=sys.stdin, check=False, env=env, log=False)
raise e
- return result
-
def apivfs_cmd(root: Path) -> list[PathString]:
cmdline: list[PathString] = [
lowerdirs: Sequence[Path],
upperdir: Optional[Path] = None,
where: Optional[Path] = None,
+ lazy: bool = False,
) -> Iterator[Path]:
with contextlib.ExitStack() as stack:
if upperdir is None:
options.append("userxattr")
try:
- with mount("overlay", where, options=options, type="overlay"):
+ with mount("overlay", where, options=options, type="overlay", lazy=lazy):
yield where
finally:
delete_whiteout_files(upperdir)
: `mkosi` will look for the package manager configuration and related
files in the configured package manager trees. Unless specified
- otherwise, it will use the configuration file from its canonical
- location in `/etc` in the package manager trees. For example, it will
- look for `etc/dnf/dnf.conf` in the package manager trees if `dnf` is
- used to install packages.
+ otherwise, it will use the configuration files from their canonical
+ locations in `/usr` or `/etc` in the package manager trees. For
+ example, it will look for `etc/dnf/dnf.conf` in the package manager
+ trees if `dnf` is used to install packages.
: `SkeletonTrees=` and `PackageManagerTrees=` fulfill similar roles. Use
`SkeletonTrees=` if you want the files to be present in the final image. Use