: When used with the `qemu` verb, this options sets `qemu`'s `-m`
argument which controls the amount of guest's RAM. Defaults to `1G`.
+`NspawnKeepUnit=`, `--nspawn-keep-unit`
+
+: When used, this option instructs underlying calls of systemd-nspawn to
+ use the current unit scope, instead of creating a dedicated transcient
+ scope unit for the containers. This option should be used when mkosi is
+ run by a service unit.
+
`Netdev=`, `--netdev`
: When used with the boot or qemu verbs, this option creates a virtual
group.add_argument("--qemu-headless", action=BooleanAction, help="Configure image for qemu's -nographic mode")
group.add_argument("--qemu-smp", help="Configure guest's SMP settings", metavar="SMP", default="2")
group.add_argument("--qemu-mem", help="Configure guest's RAM size", metavar="MEM", default="1G")
+ group.add_argument(
+ "--nspawn-keep-unit",
+ action=BooleanAction,
+ help="If specified, underlying systemd-nspawn containers use the ressources of the current unit."
+ )
group.add_argument(
"--network-veth",
dest="netdev",
if args.usr_only:
cmdline += [f"--bind={root_home(args, root)}:/root"]
+ if args.nspawn_keep_unit:
+ cmdline += ["--keep-unit"]
+
cmdline += [f"/root/{args.build_script.name}"]
cmdline += args.cmdline
cmdline += ["--machine", virt_name(args)]
+ if args.nspawn_keep_unit:
+ cmdline += ["--keep-unit"]
+
if commands or args.cmdline:
# If the verb is 'shell', args.cmdline contains the command to run.
# Otherwise, the verb is 'boot', and we assume args.cmdline contains nspawn arguments.
qemu_smp: str
qemu_mem: str
+ # systemd-nspawn specific options
+ nspawn_keep_unit: bool
+
# Some extra stuff that's stored in MkosiArgs for convenience but isn't populated by arguments
machine_id_is_fixed: bool
original_umask: int
stdout = subprocess.PIPE
nspawn += ["--console=pipe"]
+ if args.nspawn_keep_unit:
+ nspawn += ["--keep-unit"]
+
result = run([*nspawn, "--", *cmd], check=False, stdout=stdout, text=capture_stdout)
if result.returncode != 0:
if "workspace-command" in ARG_DEBUG:
"qemu_headless": False,
"qemu_smp": "2",
"qemu_mem": "1G",
+ "nspawn_keep_unit": False,
"netdev": False,
"ephemeral": False,
"with_unified_kernel_images": True,