From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Oct 2023 12:09:45 +0000 (+0200) Subject: Allow overriding dnf selection with $MKOSI_DNF X-Git-Tag: v19~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9d69279a80e1907f9dee1d8bbe33bd594b8ed11;p=thirdparty%2Fmkosi.git Allow overriding dnf selection with $MKOSI_DNF dnf5 is nice, but it has some issues, for example installation of rhel9 currently fails with some error about signature. Using dnf instead works around the problem. Allow the user to override the selection using an environment variable (or Environment=). (We have the tools directory, but it doesn't help here because we want to use 'dnf' instead of 'dnf5' and not a different version of 'dnf5'.) --- diff --git a/mkosi/config.py b/mkosi/config.py index f22d9e4a5..2c6468cc7 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -2576,10 +2576,12 @@ def load_environment(args: argparse.Namespace) -> dict[str, str]: env["IMAGE_VERSION"] = args.image_version if args.source_date_epoch is not None: env["SOURCE_DATE_EPOCH"] = str(args.source_date_epoch) - if (proxy := os.environ.get("http_proxy")): + if proxy := os.getenv("http_proxy"): env["http_proxy"] = proxy - if (proxy := os.environ.get("https_proxy")): + if proxy := os.getenv("https_proxy"): env["https_proxy"] = proxy + if dnf := os.getenv("MKOSI_DNF"): + env["MKOSI_DNF"] = dnf for s in args.environment: key, sep, value = s.partition("=") diff --git a/mkosi/installer/dnf.py b/mkosi/installer/dnf.py index d5273501a..859e98e95 100644 --- a/mkosi/installer/dnf.py +++ b/mkosi/installer/dnf.py @@ -34,7 +34,10 @@ def find_rpm_gpgkey(state: MkosiState, key: str, url: str) -> str: def dnf_executable(state: MkosiState) -> str: - return shutil.which("dnf5") or shutil.which("dnf") or "yum" + # Allow the user to override autodetection with an environment variable + dnf = state.config.environment.get("MKOSI_DNF") + + return dnf or shutil.which("dnf5") or shutil.which("dnf") or "yum" def setup_dnf(state: MkosiState, repos: Iterable[Repo], filelists: bool = True) -> None: diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index e55e1fe32..109f05d5d 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -1842,6 +1842,9 @@ repository. * `$MKOSI_LESS` overrides options for `less` when it is invoked by `mkosi` to page output. +* `$MKOSI_DNF` can be used to override the executable used as `dnf`. + This is particularly useful to select between `dnf` and `dnf5`. + # EXAMPLES Create and run a raw *GPT* image with *ext4*, as `image.raw`: