else:
cmdline += ["--image", fname]
+ if config.runtime_build_sources:
+ with finalize_source_mounts(config, ephemeral=False) as mounts:
+ for mount in mounts:
+ uidmap = "rootidmap" if Path(mount.src).stat().st_uid == INVOKING_USER.uid else "noidmap"
+ cmdline += ["--bind", f"{mount.src}:{mount.dst}:norbind,{uidmap}"]
+
+ if config.build_dir:
+ cmdline += ["--bind", f"{config.build_dir}:/work/build:norbind,noidmap"]
+
for tree in config.runtime_trees:
target = Path("/root/src") / (tree.target or "")
# We add norbind because very often RuntimeTrees= will be used to mount the source directory into the
runtime_size: Optional[int]
runtime_scratch: ConfigFeature
runtime_network: Network
+ runtime_build_sources: bool
ssh_key: Optional[Path]
ssh_certificate: Optional[Path]
machine: Optional[str]
help="Set networking backend to use when booting the image",
default=Network.user,
),
+ ConfigSetting(
+ dest="runtime_build_sources",
+ metavar="BOOL",
+ section="Host",
+ parse=config_parse_boolean,
+ help="Mount build sources and build directory in /work when booting the image",
+ ),
ConfigSetting(
dest="ssh_key",
metavar="PATH",
Runtime Size: {format_bytes_or_none(config.runtime_size)}
Runtime Scratch: {config.runtime_scratch}
Runtime Network: {config.runtime_network}
+ Runtime Build Sources: {config.runtime_build_sources}
SSH Signing Key: {none_to_none(config.ssh_key)}
SSH Certificate: {none_to_none(config.ssh_certificate)}
Machine: {config.machine_or_name()}
want_selinux_relabel,
)
from mkosi.log import ARG_DEBUG, die
+from mkosi.mounts import finalize_source_mounts
from mkosi.partition import finalize_root, find_partitions
from mkosi.run import SD_LISTEN_FDS_START, AsyncioThread, find_binary, fork_and_wait, run, spawn
from mkosi.sandbox import Mount
@contextlib.contextmanager
-def start_virtiofsd(config: Config, directory: Path, *, name: str, selinux: bool = False) -> Iterator[Path]:
- uidmap = directory.stat().st_uid == INVOKING_USER.uid
+def start_virtiofsd(config: Config, directory: PathString, *, name: str, selinux: bool = False) -> Iterator[Path]:
+ uidmap = Path(directory).stat().st_uid == INVOKING_USER.uid
virtiofsd = find_virtiofsd(tools=config.tools())
if virtiofsd is None:
# A shared memory backend might increase ram usage so only add one if actually necessary for virtiofsd.
shm = []
- if config.runtime_trees or config.output_format == OutputFormat.directory:
+ if config.runtime_trees or config.runtime_build_sources or config.output_format == OutputFormat.directory:
shm = ["-object", f"memory-backend-memfd,id=mem,size={config.qemu_mem // 1024**2}M,share=on"]
machine = f"type={config.architecture.default_qemu_machine()}"
]
kcl += ["root=root", "rootfstype=virtiofs", "rw"]
- for tree in config.runtime_trees:
- sock = stack.enter_context(start_virtiofsd(config, tree.source, name=os.fspath(tree.source)))
- tag = tree.target.name if tree.target else tree.source.name
+ def add_virtiofs_mount(
+ sock: Path,
+ dst: PathString,
+ cmdline: list[PathString],
+ kcl: list[str],
+ *, tag: str
+ ) -> None:
cmdline += [
"-chardev", f"socket,id={sock.name},path={sock}",
"-device", f"vhost-user-fs-pci,queue-size=1024,chardev={sock.name},tag={tag}",
]
- target = Path("/root/src") / (tree.target or "")
- kcl += [f"systemd.mount-extra={tag}:{target}:virtiofs"]
+ kcl += [f"systemd.mount-extra={tag}:{dst}:virtiofs"]
+
+ if config.runtime_build_sources:
+ with finalize_source_mounts(config, ephemeral=False) as mounts:
+ for mount in mounts:
+ sock = stack.enter_context(start_virtiofsd(config, mount.src, name=os.fspath(mount.src)))
+ add_virtiofs_mount(sock, mount.dst, cmdline, kcl, tag=Path(mount.src).name)
+
+ if config.build_dir:
+ sock = stack.enter_context(start_virtiofsd(config, config.build_dir, name=os.fspath(config.build_dir)))
+ add_virtiofs_mount(sock, "/work/build", cmdline, kcl, tag="build")
+
+ for tree in config.runtime_trees:
+ sock = stack.enter_context(start_virtiofsd(config, tree.source, name=os.fspath(tree.source)))
+ add_virtiofs_mount(
+ sock,
+ Path("/root/src") / (tree.target or ""),
+ cmdline,
+ kcl,
+ tag=tree.target.name if tree.target else tree.source.name,
+ )
if want_scratch(config) or config.output_format in (OutputFormat.disk, OutputFormat.esp):
cmdline += ["-device", "virtio-scsi-pci,id=scsi"]
yes_no,
)
from mkosi.log import die
+from mkosi.mounts import finalize_source_mounts
from mkosi.qemu import (
apply_runtime_size,
copy_ephemeral,
apply_runtime_size(config, fname)
+ if config.runtime_build_sources:
+ with finalize_source_mounts(config, ephemeral=False) as mounts:
+ for mount in mounts:
+ cmdline += ["--bind", f"{mount.src}:{mount.dst}"]
+
+ if config.build_dir:
+ cmdline += ["--bind", f"{config.build_dir}:/work/build"]
+
for tree in config.runtime_trees:
target = Path("/root/src") / (tree.target or "")
cmdline += ["--bind", f"{tree.source}:{target}"]
false
],
"RootShell": "/bin/tcsh",
+ "RuntimeBuildSources": true,
"RuntimeNetwork": "interface",
"RuntimeScratch": "enabled",
"RuntimeSize": 8589934592,
repository_key_check = False,
root_password = ("test1234", False),
root_shell = "/bin/tcsh",
+ runtime_build_sources = True,
runtime_network = Network.interface,
runtime_scratch = ConfigFeature.enabled,
runtime_size = 8589934592,