]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Get rid of config_default_mirror()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 10 Oct 2023 12:02:46 +0000 (14:02 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 11 Oct 2023 09:11:40 +0000 (11:11 +0200)
The only advantage of having it in the config object is that we can
show it in the summary. If we're fine with just showing "default"
instead, we can inline the default mirror into the installer classes,
which is important for the next commit.

We also document the default mirrors used.

mkosi/config.py
mkosi/distributions/debian.py
mkosi/distributions/fedora.py
mkosi/distributions/gentoo.py
mkosi/distributions/opensuse.py
mkosi/distributions/rhel_ubi.py
mkosi/distributions/ubuntu.py
mkosi/installer/pacman.py
mkosi/resources/mkosi.md

index 2a2076b7f5f2b1dc2152374fac4c716003c469c0..a8cc8396161c8a9c288e92ea422407ceab7196d7 100644 (file)
@@ -315,31 +315,6 @@ def config_default_release(namespace: argparse.Namespace) -> str:
     return cast(str, namespace.distribution.default_release())
 
 
-def config_default_mirror(namespace: argparse.Namespace) -> Optional[str]:
-    if namespace.distribution == Distribution.debian:
-        return "http://deb.debian.org/debian"
-    elif namespace.distribution == Distribution.ubuntu:
-        if namespace.architecture in (Architecture.x86, Architecture.x86_64):
-            return "http://archive.ubuntu.com/ubuntu"
-        else:
-            return "http://ports.ubuntu.com"
-    elif namespace.distribution == Distribution.arch:
-        if namespace.architecture == Architecture.arm64:
-            return "http://mirror.archlinuxarm.org"
-        else:
-            return "https://geo.mirror.pkgbuild.com"
-    elif namespace.distribution == Distribution.opensuse:
-        return "http://download.opensuse.org"
-    elif namespace.distribution == Distribution.fedora and namespace.release == "eln":
-        return "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose"
-    elif namespace.distribution == Distribution.gentoo:
-        return "https://distfiles.gentoo.org"
-    elif namespace.distribution == Distribution.rhel_ubi:
-        return "https://cdn-ubi.redhat.com/content/public/ubi/dist/"
-
-    return None
-
-
 def config_default_source_date_epoch(namespace: argparse.Namespace) -> Optional[int]:
     for env in namespace.environment:
         if env.startswith("SOURCE_DATE_EPOCH="):
@@ -1108,8 +1083,6 @@ SETTINGS = (
         dest="mirror",
         short="-m",
         section="Distribution",
-        default_factory=config_default_mirror,
-        default_factory_depends=("distribution", "release", "architecture"),
         help="Distribution mirror to use",
     ),
     MkosiConfigSetting(
index a2c3b537f2a08c1ccdfce1025523882b698d6541..b9b62a519fe95118b2e7ce066e403fcd6b89fdc9 100644 (file)
@@ -80,16 +80,16 @@ class Installer(DistributionInstaller):
 
     @staticmethod
     def repositories(state: MkosiState, local: bool = True) -> list[str]:
-        assert state.config.mirror
-
         archives = ("deb", "deb-src")
         components = ' '.join(("main", *state.config.repositories))
 
         if state.config.local_mirror and local:
             return [f"deb [trusted=yes] {state.config.local_mirror} {state.config.release} {components}"]
 
+        mirror = state.config.mirror or "http://deb.debian.org/debian"
+
         repos = [
-            f"{archive} {state.config.mirror} {state.config.release} {components}"
+            f"{archive} {mirror} {state.config.release} {components}"
             for archive in archives
         ]
 
@@ -100,7 +100,7 @@ class Installer(DistributionInstaller):
             return repos
 
         repos += [
-            f"{archive} {state.config.mirror} {state.config.release}-updates {components}"
+            f"{archive} {mirror} {state.config.release}-updates {components}"
             for archive in archives
         ]
 
index bdbeab953b942786ab35c5b9620fd13a270421a4..d9bfe19e2c91cbd432c3ee83cee5ce65e9065266 100644 (file)
@@ -89,9 +89,9 @@ class Installer(DistributionInstaller):
         if state.config.local_mirror:
             repos += [Repo("fedora", f"baseurl={state.config.mirror}", gpgurls)]
         elif state.config.release == "eln":
-            assert state.config.mirror
+            mirror = state.config.mirror or "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose"
             for repo in ("Appstream", "BaseOS", "Extras", "CRB"):
-                url = f"baseurl={urllib.parse.urljoin(state.config.mirror, repo)}"
+                url = f"baseurl={urllib.parse.urljoin(mirror, repo)}"
                 repos += [
                     Repo(repo.lower(), f"{url}/$basearch/os", gpgurls),
                     Repo(repo.lower(), f"{url}/$basearch/debug/tree", gpgurls, enabled=False),
index d98f6c27b41e132712f7b7acaf2764a1d5edf3d3..78b0ca4f2724f9cba56e80f11369a35925c6a512 100644 (file)
@@ -86,10 +86,10 @@ class Installer(DistributionInstaller):
     def install(cls, state: MkosiState) -> None:
         arch = state.config.distribution.architecture(state.config.architecture)
 
-        assert state.config.mirror
+        mirror = state.config.mirror or "https://distfiles.gentoo.org"
         # http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3.txt
         stage3tsf_path_url = urllib.parse.urljoin(
-            state.config.mirror.partition(" ")[0],
+            mirror.partition(" ")[0],
             f"releases/{arch}/autobuilds/latest-stage3.txt",
         )
 
@@ -104,7 +104,7 @@ class Installer(DistributionInstaller):
             else:
                 die("profile names changed upstream?")
 
-        stage3_url = urllib.parse.urljoin(state.config.mirror, f"releases/{arch}/autobuilds/{stage3_latest}")
+        stage3_url = urllib.parse.urljoin(mirror, f"releases/{arch}/autobuilds/{stage3_latest}")
         stage3_tar = state.cache_dir / "stage3.tar"
         stage3 = state.cache_dir / "stage3"
 
index 639d9a20e67a1385ac1302b4e9c685590dfd718a..a8337db0ee4f3bef6a2e0e4af953606ee6cad400 100644 (file)
@@ -80,20 +80,22 @@ class Installer(DistributionInstaller):
         if release == "leap":
             release = "stable"
 
+        mirror = state.config.mirror or "http://download.opensuse.org"
+
         # If the release looks like a timestamp, it's Tumbleweed. 13.x is legacy
         # (14.x won't ever appear). For anything else, let's default to Leap.
         if state.config.local_mirror:
             release_url = f"{state.config.local_mirror}"
             updates_url = None
         if release.isdigit() or release == "tumbleweed":
-            release_url = f"{state.config.mirror}/tumbleweed/repo/oss/"
-            updates_url = f"{state.config.mirror}/update/tumbleweed/"
+            release_url = f"{mirror}/tumbleweed/repo/oss/"
+            updates_url = f"{mirror}/update/tumbleweed/"
         elif release in ("current", "stable"):
-            release_url = f"{state.config.mirror}/distribution/openSUSE-{release}/repo/oss/"
-            updates_url = f"{state.config.mirror}/update/openSUSE-{release}/"
+            release_url = f"{mirror}/distribution/openSUSE-{release}/repo/oss/"
+            updates_url = f"{mirror}/update/openSUSE-{release}/"
         else:
-            release_url = f"{state.config.mirror}/distribution/leap/{release}/repo/oss/"
-            updates_url = f"{state.config.mirror}/update/leap/{release}/oss/"
+            release_url = f"{mirror}/distribution/leap/{release}/repo/oss/"
+            updates_url = f"{mirror}/update/leap/{release}/oss/"
 
         zypper = shutil.which("zypper")
 
index a8abbb99f02045a0c5578fb55abfbd05b1df2a2d..e43df057cafe63434730823b34d03a9f050dd499 100644 (file)
@@ -21,30 +21,30 @@ class Installer(centos.Installer):
         if state.config.local_mirror:
             yield Repo(repo, f"baseurl={state.config.local_mirror}", cls.gpgurls(state))
         else:
-            assert state.config.mirror
+            mirror = state.config.mirror or "https://cdn-ubi.redhat.com/content/public/ubi/dist/"
 
             v = state.config.release
             yield Repo(
                 f"ubi-{v}-{repo}-rpms",
-                f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}",
+                f"baseurl={centos.join_mirror(mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}",
                 cls.gpgurls(state),
             )
             yield Repo(
                 f"ubi-{v}-{repo}-debug-rpms",
-                f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/debug')}",
+                f"baseurl={centos.join_mirror(mirror, f'ubi{v}/{v}/$basearch/{repo}/debug')}",
                 cls.gpgurls(state),
                 enabled=False,
             )
             yield Repo(
                 f"ubi-{v}-{repo}-source",
-                f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/source')}",
+                f"baseurl={centos.join_mirror(mirror, f'ubi{v}/{v}/$basearch/{repo}/source')}",
                 cls.gpgurls(state),
                 enabled=False,
             )
             if repo == "codeready-builder":
                 yield Repo(
                     f"ubi-{v}-{repo}",
-                    f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}",
+                    f"baseurl={centos.join_mirror(mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}",
                     cls.gpgurls(state),
                     enabled=False,
                 )
index fa2ec035f67f2591b37a7461b562adc164a487df..2f8cd8055b53570416cb237d5284e36654c2579d 100644 (file)
@@ -21,29 +21,34 @@ class Installer(debian.Installer):
 
         archives = ("deb", "deb-src")
 
+        if state.config.architecture in (Architecture.x86, Architecture.x86_64):
+            mirror = state.config.mirror or "http://archive.ubuntu.com/ubuntu"
+        else:
+            mirror = state.config.mirror or "http://ports.ubuntu.com"
+
         # From kinetic onwards, the usr-is-merged package is available in universe and is required by
         # mkosi to set up a proper usr-merged system so we add the universe repository unconditionally.
         components = ["main"] + (["universe"] if state.config.release not in ("focal", "jammy") else [])
         components = ' '.join((*components, *state.config.repositories))
 
         repos = [
-            f"{archive} {state.config.mirror} {state.config.release} {components}"
+            f"{archive} {mirror} {state.config.release} {components}"
             for archive in archives
         ]
 
         repos += [
-            f"{archive} {state.config.mirror} {state.config.release}-updates {components}"
+            f"{archive} {mirror} {state.config.release}-updates {components}"
             for archive in archives
         ]
 
         # Security updates repos are never mirrored. But !x86 are on the ports server.
         if state.config.architecture in [Architecture.x86, Architecture.x86_64]:
-            url = "http://security.ubuntu.com/ubuntu/"
+            mirror = "http://security.ubuntu.com/ubuntu/"
         else:
-            url = "http://ports.ubuntu.com/"
+            mirror = "http://ports.ubuntu.com/"
 
         repos += [
-            f"{archive} {url} {state.config.release}-security {components}"
+            f"{archive} {mirror} {state.config.release}-security {components}"
             for archive in archives
         ]
 
index 4b0489b45d2bef7a5158d058dc2e05fa3ad82eda..7a87a932dff7e8d634f09346abdd5c18b82b7107 100644 (file)
@@ -12,15 +12,13 @@ from mkosi.util import sort_packages, umask
 
 
 def setup_pacman(state: MkosiState) -> None:
-    assert state.config.mirror
-
     if state.config.local_mirror:
         server = f"Server = {state.config.local_mirror}"
     else:
         if state.config.architecture == Architecture.arm64:
-            server = f"Server = {state.config.mirror}/$arch/$repo"
+            server = f"Server = {state.config.mirror or 'http://mirror.archlinuxarm.org'}/$arch/$repo"
         else:
-            server = f"Server = {state.config.mirror}/$repo/os/$arch"
+            server = f"Server = {state.config.mirror or 'https://geo.mirror.pkgbuild.com'}/$repo/os/$arch"
 
     if state.config.repository_key_check:
         sig_level = "Required DatabaseOptional"
index f326b6a3dfdbbccbeb7be45765572c6043c53621..7d934679ed729df3f32c28ca1fe528429106f543 100644 (file)
@@ -425,7 +425,25 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 `Mirror=`, `--mirror=`, `-m`
 
 : The mirror to use for downloading the distribution packages. Expects
-  a mirror URL as argument.
+  a mirror URL as argument. If not provided, the default mirror for the
+  distribution is used.
+
+: The default mirrors for each distribution are as follows (unless
+  specified, the same mirror is used for all architectures):
+
+  |                | x86-64                            | aarch64                        |
+  |----------------|--------------------------------------------------------------------|
+  | `debian`       | http://deb.debian.org/debian      |                                |
+  | `arch`         | https://geo.mirror.pkgbuild.com   | http://mirror.archlinuxarm.org |
+  | `opensuse`     | http://download.opensuse.org      |                                |
+  | `ubuntu`       | http://archive.ubuntu.com         | http://ports.ubuntu.com        |
+  | `centos`       | https://mirrors.centos.org        |                                |
+  | `rocky`        | https://mirrors.rockylinux.org    |                                |
+  | `alma`         | https://mirrors.almalinux.org     |                                |
+  | `fedora`       | https://mirrors.fedoraproject.org |                                |
+  | `rhel-ubi`     | https://cdn-ubi.redhat.com        |                                |
+  | `mageia`       | https://www.mageia.org            |                                |
+  | `openmandriva` | http://mirrors.openmandriva.org   |                                |
 
 `LocalMirror=`, `--local-mirror=`