yield
+@contextlib.contextmanager
+def hide_host_directories() -> Iterator[None]:
+ with contextlib.ExitStack() as stack:
+
+ # We want to limit the effect of host specific admin configuration on image builds, so we hide various config
+ # directories that we can't override using CLI options or environment variables so that they don't affect our
+ # builds.
+
+ for d in ("/etc/rpm",):
+ if not Path(d).exists():
+ continue
+
+ tmp = stack.enter_context(tempfile.TemporaryDirectory())
+ stack.enter_context(mount(what=tmp, where=Path(d), operation="--bind"))
+
+ yield
+
+
def check_workspace_directory(config: MkosiConfig) -> None:
wd = config.workspace_dir_or_default()
with (
complete_step(f"Building {config.image or 'default'} image"),
mount_tools(config.tools_tree),
+ hide_host_directories(),
prepend_to_environ_path(config),
):
# After tools have been mounted, check if we have what we need
# SPDX-License-Identifier: LGPL-2.1+
import os
import shutil
+import subprocess
import textwrap
from collections.abc import Iterable
from pathlib import Path
from typing import NamedTuple, Optional
-from mkosi.run import apivfs_cmd, bwrap
+from mkosi.run import apivfs_cmd, bwrap, run
from mkosi.state import MkosiState
-from mkosi.tree import rmtree
+from mkosi.tree import copy_tree, rmtree
from mkosi.types import PathString
from mkosi.util import sort_packages
f.write("\n")
+ rpmconfigdir = Path(run(["rpm", "--eval", "%{_rpmconfigdir}"], stdout=subprocess.PIPE).stdout.strip())
+ (state.pkgmngr / "usr/lib").mkdir(parents=True, exist_ok=True)
+ copy_tree(state.config, rpmconfigdir, state.pkgmngr / "usr/lib/rpm", clobber=False)
+
def dnf_cmd(state: MkosiState) -> list[PathString]:
dnf = dnf_executable(state)
cmdline: list[PathString] = [
+ "env",
+ "HOME=/", # Make sure rpm doesn't pick up ~/.rpmmacros and ~/.rpmrc.
+ f"RPM_CONFIGDIR={state.pkgmngr / 'usr/lib/rpm'}",
dnf,
"--assumeyes",
f"--config={state.pkgmngr / 'etc/dnf/dnf.conf'}",
def rpm_cmd(state: MkosiState) -> list[PathString]:
- return ["rpm", "--root", state.root]
+ return ["env", "HOME=/", f"RPM_CONFIGDIR={state.pkgmngr / 'usr/lib/rpm'}", "rpm", "--root", state.root]
subdirectory of the workspace directory instead of the OS tree. This
subdirectory of the workspace is used to configure the package manager.
+: `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 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.
+
+: Extra rpm configuration should be put in `usr/lib/rpm` in the package
+ manager trees. Any configuration in `etc/rpm` will be ignored. The
+ extra configuration in `usr/lib/rpm` should mimick the layout of
+ `usr/lib/rpm` on the host. For example, extra macro files should go in
+ `usr/lib/rpm/macros.d` in the package manager trees.
+
: `SkeletonTrees=` and `PackageManagerTrees=` fulfill similar roles. Use
`SkeletonTrees=` if you want the files to be present in the final image. Use
`PackageManagerTrees=` if you don't want the files to be present in the final