]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move default tools tree configuration to mkosi/resources/mkosi-tools
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 16 Dec 2023 19:27:16 +0000 (20:27 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 18 Dec 2023 11:19:13 +0000 (12:19 +0100)
Our default initrd configuration already lives in
mkosi/resources/mkosi-initrd, let's do the same for our tools tree
configuration.

18 files changed:
mkosi/__init__.py
mkosi/distributions/__init__.py
mkosi/distributions/arch.py
mkosi/distributions/centos.py
mkosi/distributions/debian.py
mkosi/distributions/fedora.py
mkosi/distributions/opensuse.py
mkosi/resources/mkosi-tools/mkosi.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-arch.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf.d/10-uefi.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-debian-ubuntu.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf.d/10-uefi.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.conf.d/10-opensuse.conf [new file with mode: 0644]
mkosi/resources/mkosi-tools/mkosi.prepare.chroot [new file with mode: 0755]
pyproject.toml

index 7ec09394eeca4e8dec11646b8d05258c606013f9..09f48712bf47c4a1c0408fb8e1a0774001e110cd 100644 (file)
@@ -25,7 +25,6 @@ import mkosi.resources
 from mkosi.archive import extract_tar, make_cpio, make_tar
 from mkosi.burn import run_burn
 from mkosi.config import (
-    Architecture,
     BiosBootloader,
     Bootloader,
     Compression,
@@ -2956,62 +2955,51 @@ def prepend_to_environ_path(config: MkosiConfig) -> Iterator[None]:
 def finalize_tools(args: MkosiArgs, images: Sequence[MkosiConfig]) -> Sequence[MkosiConfig]:
     new = []
 
-    for p in images:
-        if not p.tools_tree or p.tools_tree.name != "default":
-            new.append(p)
+    for config in images:
+        if not config.tools_tree or config.tools_tree.name != "default":
+            new.append(config)
             continue
 
-        distribution = p.tools_tree_distribution or p.distribution.default_tools_tree_distribution()
+        distribution = config.tools_tree_distribution or config.distribution.default_tools_tree_distribution()
         if not distribution:
-            die(f"{p.distribution} does not have a default tools tree distribution",
+            die(f"{config.distribution} does not have a default tools tree distribution",
                 hint="use ToolsTreeDistribution= to set one explicitly")
 
-        release = p.tools_tree_release or distribution.default_release()
-        mirror = p.tools_tree_mirror or (p.mirror if p.mirror and p.distribution == distribution else None)
-
-        if p.cache_dir:
-            if p.distribution == distribution and p.release == release and p.architecture == Architecture.native():
-                cache = p.cache_dir
-            else:
-                cache = p.cache_dir / "tools"
-        else:
-            cache = None
+        release = config.tools_tree_release or distribution.default_release()
+        mirror = (
+            config.tools_tree_mirror or
+            (config.mirror if config.mirror and config.distribution == distribution else None)
+        )
 
         cmdline = [
             "--directory", "",
             "--distribution", str(distribution),
             *(["--release", release] if release else []),
             *(["--mirror", mirror] if mirror else []),
-            "--repository-key-check", str(p.repository_key_check),
-            "--cache-only", str(p.cache_only),
-            *(["--output-dir", str(p.output_dir)] if p.output_dir else []),
-            *(["--workspace-dir", str(p.workspace_dir)] if p.workspace_dir else []),
-            *(["--cache-dir", str(cache)] if cache else []),
-            "--incremental", str(p.incremental),
-            "--acl", str(p.acl),
-            "--format", "directory",
-            *flatten(
-                ["--package", package]
-                for package in itertools.chain(distribution.tools_tree_packages(), p.tools_tree_packages)
-            ),
+            "--repository-key-check", str(config.repository_key_check),
+            "--cache-only", str(config.cache_only),
+            *(["--output-dir", str(config.output_dir)] if config.output_dir else []),
+            *(["--workspace-dir", str(config.workspace_dir)] if config.workspace_dir else []),
+            *(["--cache-dir", str(config.cache_dir)] if config.cache_dir else []),
+            "--incremental", str(config.incremental),
+            "--acl", str(config.acl),
+            *([f"--package={package}" for package in config.tools_tree_packages]),
             "--output", f"{distribution}-tools",
-            "--bootable", "no",
-            "--manifest-format", "",
-            *(["--source-date-epoch", str(p.source_date_epoch)] if p.source_date_epoch is not None else []),
-            *([f"--environment={k}='{v}'" for k, v in p.environment.items()]),
-            *flatten(["--repositories", repo] for repo in distribution.tools_tree_repositories()),
-            *([f"--extra-search-path={p}" for p in p.extra_search_paths]),
+            *(["--source-date-epoch", str(config.source_date_epoch)] if config.source_date_epoch is not None else []),
+            *([f"--environment={k}='{v}'" for k, v in config.environment.items()]),
+            *([f"--extra-search-path={p}" for p in config.extra_search_paths]),
             *(["-f"] * args.force),
-            "build",
         ]
 
-        _, [config] = parse_config(cmdline)
-        config = dataclasses.replace(config, image=f"{distribution}-tools")
+        with resource_path(mkosi.resources) as r:
+            _, [tools] = parse_config(cmdline + ["--include", os.fspath(r / "mkosi-tools"), "build"])
 
-        if config not in new:
-            new.append(config)
+        tools = dataclasses.replace(tools, image=f"{distribution}-tools")
+
+        if tools not in new:
+            new.append(tools)
 
-        new.append(dataclasses.replace(p, tools_tree=config.output_dir_or_cwd() / config.output))
+        new.append(dataclasses.replace(config, tools_tree=tools.output_dir_or_cwd() / tools.output))
 
     return new
 
index 9050793c1cf15f940332fed2fa2522740980a065..993a346a2580dece206b743326a3e8c265aed06d 100644 (file)
@@ -63,14 +63,6 @@ class DistributionInstaller:
     def default_tools_tree_distribution(cls) -> Optional["Distribution"]:
         return None
 
-    @classmethod
-    def tools_tree_repositories(cls) -> list[str]:
-        return []
-
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        return []
-
 
 class Distribution(StrEnum):
     # Please consult docs/distribution-policy.md and contact one
@@ -141,12 +133,6 @@ class Distribution(StrEnum):
     def default_tools_tree_distribution(self) -> Optional["Distribution"]:
         return self.installer().default_tools_tree_distribution()
 
-    def tools_tree_repositories(self) -> list[str]:
-        return self.installer().tools_tree_repositories()
-
-    def tools_tree_packages(self) -> list[str]:
-        return self.installer().tools_tree_packages()
-
     def installer(self) -> type[DistributionInstaller]:
         modname = str(self).replace('-', '_')
         mod = importlib.import_module(f"mkosi.distributions.{modname}")
index 43743014f6b3a8abbdf7d5eede3e08edb97eb652..0761c0017e5c83d71924623e3c21b15cdd571711 100644 (file)
@@ -30,48 +30,6 @@ class Installer(DistributionInstaller):
     def default_tools_tree_distribution(cls) -> Distribution:
         return Distribution.arch
 
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        return [
-            "apt",
-            "archlinux-keyring",
-            "base",
-            "bash",
-            "btrfs-progs",
-            "bubblewrap",
-            "ca-certificates",
-            "coreutils",
-            "cpio",
-            "curl",
-            "debian-archive-keyring",
-            "dnf",
-            "dosfstools",
-            "e2fsprogs",
-            "edk2-ovmf",
-            "erofs-utils",
-            "mtools",
-            "openssh",
-            "openssl",
-            "pacman",
-            "pesign",
-            "python-cryptography",
-            "qemu-base",
-            "sbsigntools",
-            "shadow",
-            "socat",
-            "squashfs-tools",
-            "strace",
-            "swtpm",
-            "systemd-ukify",
-            "systemd",
-            "tar",
-            "util-linux",
-            "virtiofsd",
-            "xfsprogs",
-            "xz",
-            "zstd",
-        ]
-
     @classmethod
     def setup(cls, state: MkosiState) -> None:
         if state.config.local_mirror:
index e50519162d76ca765fb5c2aff750e502b2dadc3a..1a23a118fc322758ba0731600931fc982f813c16 100644 (file)
@@ -54,55 +54,6 @@ class Installer(DistributionInstaller):
     def default_tools_tree_distribution(cls) -> Distribution:
         return Distribution.fedora
 
-    @classmethod
-    def tools_tree_repositories(cls) -> list[str]:
-        return ["epel", "epel-next"]
-
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        packages = [
-            "apt",
-            "bash",
-            "bubblewrap",
-            "ca-certificates",
-            "coreutils",
-            "cpio",
-            "curl",
-            "debian-keyring",
-            "distribution-gpg-keys",
-            "dnf",
-            "dnf-plugins-core",
-            "dosfstools",
-            "e2fsprogs",
-            "mtools",
-            "openssh-clients",
-            "openssl",
-            "python3-cryptography",
-            "qemu-kvm-core",
-            "shadow-utils",
-            "socat",
-            "squashfs-tools",
-            "strace",
-            "swtpm",
-            "systemd-container",
-            "systemd-udev",
-            "systemd",
-            "tar",
-            "util-linux",
-            "virtiofsd",
-            "xfsprogs",
-            "xz",
-            "zstd",
-        ]
-
-        if Architecture.native() in (Architecture.x86_64, Architecture.arm64):
-            packages += [
-                "edk2-ovmf",
-                "pesign",
-            ]
-
-        return packages
-
     @classmethod
     def setup(cls, state: MkosiState) -> None:
         if GenericVersion(state.config.release) <= 7:
index cfc8aa2e39ee2fc51bb7e9d0df0ad9a4b56a7592..e9e68d8b3802695702f9cd43afde5eeee5a5d20f 100644 (file)
@@ -36,50 +36,6 @@ class Installer(DistributionInstaller):
     def default_tools_tree_distribution(cls) -> Distribution:
         return Distribution.debian
 
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        return [
-            "apt",
-            "bash",
-            "btrfs-progs",
-            "bubblewrap",
-            "ca-certificates",
-            "coreutils",
-            "cpio",
-            "curl",
-            "debian-archive-keyring",
-            "dnf",
-            "dnf-plugins-core",
-            "dosfstools",
-            "e2fsprogs",
-            "erofs-utils",
-            "libtss2-dev",
-            "mtools",
-            "openssh-client",
-            "openssl",
-            "ovmf",
-            "pacman-package-manager",
-            "pesign",
-            "python3-cryptography",
-            "python3-pefile",
-            "qemu-system",
-            "sbsigntool",
-            "socat",
-            "squashfs-tools",
-            "strace",
-            "swtpm",
-            "systemd-boot",
-            "systemd-container",
-            "systemd",
-            "tar",
-            "uidmap",
-            "util-linux",
-            "xfsprogs",
-            "xz-utils",
-            "zstd",
-            "zypper",
-        ]
-
     @staticmethod
     def repositories(state: MkosiState, local: bool = True) -> list[str]:
         archives = ("deb", "deb-src")
index c7e05db799d9201713fe26232f3590bce4b7b394..3ea860c545d61f5bbcbd08cb7581d93dbc15a60e 100644 (file)
@@ -35,59 +35,6 @@ class Installer(DistributionInstaller):
     def default_tools_tree_distribution(cls) -> Distribution:
         return Distribution.fedora
 
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        packages = [
-            "apt",
-            "archlinux-keyring",
-            "bash",
-            "btrfs-progs",
-            "bubblewrap",
-            "ca-certificates",
-            "coreutils",
-            "cpio",
-            "curl-minimal",
-            "debian-keyring",
-            "distribution-gpg-keys",
-            "dnf5",
-            "dnf5-plugins",
-            "dosfstools",
-            "e2fsprogs",
-            "erofs-utils",
-            "mtools",
-            "openssh-clients",
-            "openssl",
-            "pacman",
-            "python3-cryptography",
-            "qemu-kvm-core",
-            "qemu-system-aarch64-core",
-            "shadow-utils",
-            "socat",
-            "squashfs-tools",
-            "strace",
-            "swtpm",
-            "systemd-container",
-            "systemd-udev",
-            "systemd-ukify",
-            "systemd",
-            "tar",
-            "util-linux",
-            "virtiofsd",
-            "xfsprogs",
-            "xz",
-            "zstd",
-            "zypper",
-        ]
-
-        if Architecture.native() in (Architecture.x86_64, Architecture.arm64):
-            packages += [
-                "edk2-ovmf",
-                "pesign",
-                "sbsigntools",
-            ]
-
-        return packages
-
     @classmethod
     def setup(cls, state: MkosiState) -> None:
         gpgurls = (
index 6721b2fa4183c8b1224ccb651da8caab888e35bc..8bc84ce2b5702763dff7faf7a2babda79ee5ba37 100644 (file)
@@ -34,48 +34,6 @@ class Installer(DistributionInstaller):
     def default_tools_tree_distribution(cls) -> Distribution:
         return Distribution.opensuse
 
-    @classmethod
-    def tools_tree_packages(cls) -> list[str]:
-        return [
-            "bash",
-            "btrfs-progs",
-            "bubblewrap",
-            "ca-certificates",
-            "coreutils",
-            "cpio",
-            "curl",
-            "distribution-gpg-keys",
-            "dnf",
-            "dnf-plugins-core",
-            "dosfstools",
-            "e2fsprogs",
-            "erofs-utils",
-            "grep",
-            "mtools",
-            "openssh-clients",
-            "openssl",
-            "ovmf",
-            "pesign",
-            "qemu-headless",
-            "sbsigntools",
-            "shadow",
-            "socat",
-            "squashfs",
-            "strace",
-            "swtpm",
-            "systemd-boot",
-            "systemd-container",
-            "systemd-experimental",
-            "systemd",
-            "tar",
-            "util-linux",
-            "virtiofsd",
-            "xfsprogs",
-            "xz",
-            "zstd",
-            "zypper",
-        ]
-
     @classmethod
     def setup(cls, state: MkosiState) -> None:
         release = state.config.release
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf b/mkosi/resources/mkosi-tools/mkosi.conf
new file mode 100644 (file)
index 0000000..db12a58
--- /dev/null
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Output]
+Format=directory
+ManifestFormat=
+
+[Content]
+Bootable=no
+Packages=
+        bash
+        bubblewrap
+        ca-certificates
+        coreutils
+        cpio
+        diffutils
+        dnf
+        dosfstools
+        e2fsprogs
+        less
+        mtools
+        nano
+        openssl
+        socat
+        strace
+        swtpm
+        systemd
+        tar
+        util-linux
+        virtiofsd
+        xfsprogs
+        zstd
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-arch.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-arch.conf
new file mode 100644 (file)
index 0000000..ddbd1ed
--- /dev/null
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=arch
+
+[Content]
+Packages=
+        apt
+        archlinux-keyring
+        base
+        btrfs-progs
+        curl
+        debian-archive-keyring
+        edk2-ovmf
+        erofs-utils
+        openssh
+        pacman
+        pesign
+        python-cryptography
+        qemu-base
+        sbsigntools
+        shadow
+        squashfs-tools
+        systemd-ukify
+        ubuntu-keyring
+        xz
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf
new file mode 100644 (file)
index 0000000..ddf78da
--- /dev/null
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|centos
+Distribution=|alma
+Distribution=|rocky
+Distribution=|rhel
+Distribution=|fedora
+
+[Content]
+Packages=
+        apt
+        curl-minimal
+        debian-keyring
+        distribution-gpg-keys
+        dnf-plugins-core
+        openssh-clients
+        python3-cryptography
+        qemu-kvm-core
+        shadow-utils
+        squashfs-tools
+        systemd-container
+        systemd-udev
+        xz
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf.d/10-uefi.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos-fedora/mkosi.conf.d/10-uefi.conf
new file mode 100644 (file)
index 0000000..bac4324
--- /dev/null
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+HostArchitecture=|x86-64
+HostArchitecture=|arm64
+
+[Content]
+Packages=
+        edk2-ovmf
+        pesign
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-centos.conf
new file mode 100644 (file)
index 0000000..8aa105a
--- /dev/null
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|centos
+Distribution=|alma
+Distribution=|rocky
+Distribution=|rhel
+
+[Distribution]
+Repositories=
+        epel
+        epel-next
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-debian-ubuntu.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-debian-ubuntu.conf
new file mode 100644 (file)
index 0000000..805dd14
--- /dev/null
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|debian
+Distribution=|ubuntu
+
+[Content]
+Packages=
+        apt
+        archlinux-keyring
+        btrfs-progs
+        curl
+        debian-archive-keyring
+        erofs-utils
+        libtss2-dev
+        makepkg
+        openssh-client
+        ovmf
+        pacman-package-manager
+        pesign
+        python3-cryptography
+        python3-pefile
+        qemu-system
+        sbsigntool
+        squashfs-tools
+        systemd-boot
+        systemd-container
+        systemd-coredump
+        ubuntu-keyring
+        uidmap
+        xz-utils
+        zypper
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf
new file mode 100644 (file)
index 0000000..401e0e9
--- /dev/null
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=fedora
+
+[Content]
+Packages=
+        archlinux-keyring
+        btrfs-progs
+        dnf5
+        dnf5-plugins
+        erofs-utils
+        pacman
+        qemu-system-aarch64-core
+        systemd-ukify
+        zypper
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf.d/10-uefi.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-fedora/mkosi.conf.d/10-uefi.conf
new file mode 100644 (file)
index 0000000..49961ca
--- /dev/null
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+HostArchitecture=|x86-64
+HostArchitecture=|arm64
+
+[Content]
+Packages=
+        sbsigntools
diff --git a/mkosi/resources/mkosi-tools/mkosi.conf.d/10-opensuse.conf b/mkosi/resources/mkosi-tools/mkosi.conf.d/10-opensuse.conf
new file mode 100644 (file)
index 0000000..df03908
--- /dev/null
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=opensuse
+
+[Content]
+Packages=
+        btrfs-progs
+        ca-certificates-mozilla
+        curl
+        distribution-gpg-keys
+        dnf-plugins-core
+        erofs-utils
+        grep
+        openssh-clients
+        ovmf
+        pesign
+        qemu-headless
+        sbsigntools
+        shadow
+        squashfs
+        systemd-boot
+        systemd-container
+        systemd-coredump
+        systemd-experimental
+        xz
+        zypper
diff --git a/mkosi/resources/mkosi-tools/mkosi.prepare.chroot b/mkosi/resources/mkosi-tools/mkosi.prepare.chroot
new file mode 100755 (executable)
index 0000000..a2fbc69
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+if [ "$1" = "final" ] && command -v pacman-key; then
+    pacman-key --init
+    pacman-key --populate
+fi
index 2c93e8a6e22793fc02553d6f774e1f57828fafcf..69e1856da0f378cf68c9834283556355f54595ff 100644 (file)
@@ -30,7 +30,7 @@ packages = [
 ]
 
 [tool.setuptools.package-data]
-"mkosi.resources" = ["repart/**/*", "mkosi.md", "mkosi.1", "mkosi-initrd/**/*"]
+"mkosi.resources" = ["repart/**/*", "mkosi.md", "mkosi.1", "mkosi-initrd/**/*", "mkosi-tools/**/*"]
 
 [tool.isort]
 profile = "black"