]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Allow overriding dnf selection with $MKOSI_DNF
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Oct 2023 12:09:45 +0000 (14:09 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Nov 2023 10:37:03 +0000 (11:37 +0100)
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'.)

mkosi/config.py
mkosi/installer/dnf.py
mkosi/resources/mkosi.md

index f22d9e4a5d239b7d02487c86bebd1e7f4bdba547..2c6468cc7655f4391725a59258cf1bb4e29ac753 100644 (file)
@@ -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("=")
index d5273501adb636ec0a9a9f0b5fe80957b3a66741..859e98e953ee1d8e17b4e6b6780660d2b776e69e 100644 (file)
@@ -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:
index e55e1fe327db775aa872296c8906b28840dee312..109f05d5df628cc98f6435906111d5a3a8705807 100644 (file)
@@ -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`: