]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add "none" distribution
authorStefan Nickl <Stefan.Nickl@gmail.com>
Wed, 27 Sep 2023 18:31:53 +0000 (20:31 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 3 Oct 2023 16:01:26 +0000 (18:01 +0200)
mkosi/__init__.py
mkosi/config.py
mkosi/distributions/__init__.py
mkosi/distributions/none.py [new file with mode: 0644]
mkosi/resources/mkosi.md

index a2175c7bbb5cda25ecb5394808af5c88cb7cac40..03ec0f65abd325efa9c261d4e4785b010596b1fb 100644 (file)
@@ -39,6 +39,7 @@ from mkosi.config import (
     parse_config,
     summary,
 )
+from mkosi.distributions import Distribution
 from mkosi.installer import clean_package_manager_metadata, package_manager_scripts
 from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules
 from mkosi.log import ARG_DEBUG, complete_step, die, log_step
@@ -138,6 +139,7 @@ def install_distribution(state: MkosiState) -> None:
             # Some distributions install EFI binaries directly to /boot/efi. Let's redirect them to /efi
             # instead.
             rmtree(state.root / "boot/efi")
+            (state.root / "boot").mkdir(exist_ok=True)
             (state.root / "boot/efi").symlink_to("../efi")
 
             if state.config.packages:
@@ -176,6 +178,14 @@ def remove_packages(state: MkosiState) -> None:
             die(f"Removing packages is not supported for {state.config.distribution}")
 
 
+def check_root_populated(state: MkosiState) -> None:
+    """Check that the root was populated by looking for a os-release file."""
+    osrelease = state.root / "usr/lib/os-release"
+    if not osrelease.exists():
+        die(f"{osrelease} not found.",
+            hint="The root must be populated by the distribution, or from base trees, skeleton trees, and prepare scripts.")
+
+
 def configure_os_release(state: MkosiState) -> None:
     """Write IMAGE_ID and IMAGE_VERSION to /usr/lib/os-release in the image."""
     if not state.config.image_id and not state.config.image_version:
@@ -969,6 +979,9 @@ def build_initrd(state: MkosiState) -> Path:
     if symlink.exists():
         return symlink.resolve()
 
+    if state.config.distribution == Distribution.none:
+        die(f"Building a default initrd is not supported with distribution {state.config.distribution}")
+
     # Default values are assigned via the parser so we go via the argument parser to construct
     # the config for the initrd.
 
@@ -1945,6 +1958,7 @@ def build_image(args: MkosiArgs, config: MkosiConfig, name: str, uid: int, gid:
                 save_cache(state)
                 reuse_cache(state)
 
+            check_root_populated(state)
             run_build_scripts(state)
 
             if state.config.output_format == OutputFormat.none:
index ffe4426ad553d85a2c963933e646d24a5883f0cb..fe8780a736ea2cc3924234e2c560a7ee0fc908e5 100644 (file)
@@ -294,7 +294,8 @@ def config_default_distribution(namespace: argparse.Namespace) -> Distribution:
     detected = detect_distribution()[0]
 
     if not detected:
-        die("Distribution of your host can't be detected or isn't a supported target. Please set Distribution= in your config.")
+        logging.info("Distribution of your host can't be detected or isn't a supported target. Defaulting to Distribution=none.")
+        return Distribution.none
 
     return detected
 
index 02373a30b591ff2f3c558e1fef1252cbd0c93472..b33334d4f8062e811a16dc6edb127e14375fde1e 100644 (file)
@@ -72,6 +72,7 @@ class DistributionInstaller:
 
 
 class Distribution(StrEnum):
+    none         = enum.auto()
     fedora       = enum.auto()
     debian       = enum.auto()
     ubuntu       = enum.auto()
diff --git a/mkosi/distributions/none.py b/mkosi/distributions/none.py
new file mode 100644 (file)
index 0000000..fced69a
--- /dev/null
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: LGPL-2.1+
+
+from collections.abc import Sequence
+
+from mkosi.distributions import DistributionInstaller
+from mkosi.log import die
+from mkosi.state import MkosiState
+
+
+class Installer(DistributionInstaller):
+    @classmethod
+    def setup(cls, state: MkosiState) -> None:
+        pass
+
+    @classmethod
+    def install(cls, state: MkosiState) -> None:
+        pass
+
+    @classmethod
+    def install_packages(cls, state: MkosiState, packages: Sequence[str]) -> None:
+        if packages:
+            die("Installing packages is not supported with distribution 'none'")
+
+    @classmethod
+    def remove_packages(cls, state: MkosiState, packages: Sequence[str]) -> None:
+        if packages:
+            die("Removing packages is not supported with distribution 'none'")
index 504f54ec3f8381dc841bf9f2916970a390c0bb60..e842399a00169e5fd18e0027ac7e63561bea9211 100644 (file)
@@ -395,8 +395,8 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 
 : The distribution to install in the image. Takes one of the following
   arguments: `fedora`, `debian`, `ubuntu`, `arch`, `opensuse`, `mageia`,
-  `centos`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`. If not
-  specified, defaults to the distribution of the host.
+  `centos`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`, `none`.
+  If not specified, defaults to the distribution of the host.
 
 `Release=`, `--release=`, `-r`
 
@@ -1284,6 +1284,8 @@ distributions:
   guarantee that it will work at all and the core maintainers will
   generally not fix gentoo specific issues**)
 
+* *None* (**Requires the user to provide a pre-built rootfs**)
+
 In theory, any distribution may be used on the host for building images
 containing any other distribution, as long as the necessary tools are
 available.
@@ -1292,6 +1294,7 @@ any distribution that packages `apt` may be used to build *Debian* or *Ubuntu* i
 Any distribution that packages `dnf` may be used to build images for any of the rpm-based distributions.
 Any distro that packages `pacman` may be used to build *Arch Linux* images.
 Any distribution that packages `zypper` may be used to build *openSUSE* images.
+Other distributions and build automation tools for embedded Linux systems such as Buildroot, OpenEmbedded and Yocto Project may be used by selecting the `none` distribution, and populating the rootfs via a combination of base trees, skeleton trees, and prepare scripts.
 
 Currently, *Fedora Linux* packages all relevant tools as of Fedora 28.