From: Daan De Meyer Date: Tue, 5 Dec 2023 09:28:31 +0000 (+0100) Subject: Fix nspawn settings X-Git-Tag: v20~114^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c38325a347c006ee357c60cf48ed79d8d962d5b8;p=thirdparty%2Fmkosi.git Fix nspawn settings When --machine= is used, nspawn looks for a settings file named after the machine so we have to make sure to copy to the right location. While we're at it, let's also stop considering the nspawn settings an output artifact, since this means we have to build the image to apply new settings. Instead, let's copy the settings when running the image and remove the copied file again afterwards. This means that new settings are applied immediately instead of only after a rebuild. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index bc33a6059..a9e6ad5e6 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1488,14 +1488,6 @@ def maybe_compress(config: MkosiConfig, compression: Compression, src: Path, dst run(compressor_command(compression), stdin=i, stdout=o) -def copy_nspawn_settings(state: MkosiState) -> None: - if state.config.nspawn_settings is None: - return None - - with complete_step("Copying nspawn settings file…"): - shutil.copy2(state.config.nspawn_settings, state.staging / state.config.output_nspawn_settings) - - def copy_vmlinuz(state: MkosiState) -> None: if (state.staging / state.config.output_split_kernel).exists(): return @@ -1694,7 +1686,6 @@ def check_outputs(config: MkosiConfig) -> None: config.output_with_compression, config.output_checksum if config.checksum else None, config.output_signature if config.sign else None, - config.output_nspawn_settings if config.nspawn_settings is not None else None, ): if f and (config.output_dir_or_cwd() / f).exists(): die(f"Output path {f} exists already. (Consider invocation with --force.)") @@ -2318,7 +2309,6 @@ def build_image(args: MkosiArgs, config: MkosiConfig) -> None: state.staging / state.config.output_with_format, state.staging / state.config.output_with_compression) - copy_nspawn_settings(state) calculate_sha256sum(state) calculate_signature(state) save_manifest(state, manifest) @@ -2411,7 +2401,7 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: cmdline: list[PathString] = ["systemd-nspawn", "--quiet"] # If we copied in a .nspawn file, make sure it's actually honoured - if config.nspawn_settings is not None: + if config.nspawn_settings: cmdline += ["--settings=trusted"] if args.verb == Verb.boot: @@ -2423,12 +2413,17 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: ] # Underscores are not allowed in machine names so replace them with hyphens. - cmdline += ["--machine", (config.image_id or config.image or config.output).replace("_", "-")] + name = config.name().replace("_", "-") + cmdline += ["--machine", name] for k, v in config.credentials.items(): cmdline += [f"--set-credential={k}:{v}"] with contextlib.ExitStack() as stack: + if config.nspawn_settings: + copy_tree(config.nspawn_settings, config.output_dir_or_cwd() / f"{name}.nspawn") + stack.callback(lambda: rmtree(config.output_dir_or_cwd() / f"{name}.nspawn")) + if config.ephemeral: fname = stack.enter_context(copy_ephemeral(config, config.output_dir_or_cwd() / config.output)) else: diff --git a/mkosi/config.py b/mkosi/config.py index e11ab9a3c..3ac3b9ad6 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1024,10 +1024,6 @@ class MkosiConfig: def output_split_initrd(self) -> str: return f"{self.output_with_version}.initrd" - @property - def output_nspawn_settings(self) -> str: - return f"{self.output_with_version}.nspawn" - @property def output_checksum(self) -> str: return f"{self.output_with_version}.SHA256SUMS"