From 6104923534685d015a4e91db95d5f94f0f826eb7 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Mon, 28 Jul 2025 12:12:29 +0100 Subject: [PATCH] env: export $EFI_ARCHITECTURE in hook scripts on EFI arches Saves from having to do the translations manually a bunch of times --- mkosi/__init__.py | 24 ++++++++++++++++++++++++ mkosi/resources/man/mkosi.1.md | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1ebb627c7..2abd46043 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -609,6 +609,9 @@ def run_configure_scripts(config: Config) -> Config: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(config.architecture.to_efi()) + if config.profiles: env["PROFILES"] = " ".join(config.profiles) @@ -656,6 +659,9 @@ def run_sync_scripts(config: Config) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(config.architecture.to_efi()) + if config.profiles: env["PROFILES"] = " ".join(config.profiles) @@ -777,6 +783,9 @@ def run_prepare_scripts(context: Context, build: bool) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if context.config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(context.config.architecture.to_efi()) + if context.config.profiles: env["PROFILES"] = " ".join(context.config.profiles) @@ -847,6 +856,9 @@ def run_build_scripts(context: Context) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if context.config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(context.config.architecture.to_efi()) + if context.config.profiles: env["PROFILES"] = " ".join(context.config.profiles) @@ -920,6 +932,9 @@ def run_postinst_scripts(context: Context) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if context.config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(context.config.architecture.to_efi()) + if context.config.profiles: env["PROFILES"] = " ".join(context.config.profiles) @@ -989,6 +1004,9 @@ def run_finalize_scripts(context: Context) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if context.config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(context.config.architecture.to_efi()) + if context.config.profiles: env["PROFILES"] = " ".join(context.config.profiles) @@ -1050,6 +1068,9 @@ def run_postoutput_scripts(context: Context) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if context.config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(context.config.architecture.to_efi()) + if context.config.profiles: env["PROFILES"] = " ".join(context.config.profiles) @@ -4592,6 +4613,9 @@ def run_clean_scripts(config: Config) -> None: MKOSI_DEBUG=one_zero(ARG_DEBUG.get()), ) + if config.architecture.to_efi() is not None: + env["EFI_ARCHITECTURE"] = str(config.architecture.to_efi()) + if config.profiles: env["PROFILES"] = " ".join(config.profiles) diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 207db8624..d08cdc452 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -2463,6 +2463,10 @@ Scripts executed by **mkosi** receive the following environment variables: the format used by **qemu**. Useful for finding the qemu binary ( `qemu-system-$QEMU_ARCHITECTURE`). +* `$EFI_ARCHITECTURE` contains the architecture from `$ARCHITECTURE` in + the format used by **UEFI**. It is unset on architectures that do not + support **UEFI**. + * `$DISTRIBUTION` contains the distribution from the `Distribution=` setting. * `$RELEASE` contains the release from the `Release=` setting. @@ -2582,6 +2586,7 @@ Consult this table for which script receives which environment variables: | `DESTDIR` | | | | ✓ | | | | | | `DISTRIBUTION` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `DISTRIBUTION_ARCHITECTURE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| `EFI_ARCHITECTURE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `IMAGE_ID` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `IMAGE_VERSION` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `MKOSI_CONFIG` | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -- 2.47.3