]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add VolatilePackages= and InitrdVolatilePackages= settings
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Apr 2024 14:40:56 +0000 (16:40 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Apr 2024 14:57:31 +0000 (16:57 +0200)
Let's allow configuring packages which should be installed after
running build scripts and which are not cached. This is useful for
installing packages which are built in a build script or which change
often and shouldn't invalidate the cache.

mkosi/__init__.py
mkosi/config.py
mkosi/resources/mkosi.md
tests/test_json.py

index 8e97685c12a756ce5ef712e1d424792c7b866890..f8c9cf8c2f32a1fb2f2dbb5d8d8b5f53b3f9f336 100644 (file)
@@ -182,6 +182,14 @@ def install_build_packages(context: Context) -> None:
         context.config.distribution.install_packages(context, context.config.build_packages)
 
 
+def install_volatile_packages(context: Context) -> None:
+    if not context.config.volatile_packages:
+        return
+
+    with complete_step(f"Installing volatile packages for {context.config.distribution.pretty_name()}"):
+        context.config.distribution.install_packages(context, context.config.volatile_packages)
+
+
 def remove_packages(context: Context) -> None:
     """Remove packages listed in config.remove_packages"""
 
@@ -1699,6 +1707,7 @@ def finalize_default_initrd(
         "--incremental", str(config.incremental),
         "--acl", str(config.acl),
         *(f"--package={package}" for package in config.initrd_packages),
+        *(f"--volatile-package={package}" for package in config.initrd_volatile_packages),
         *(["--package-directory", str(package_dir)] if package_dir else []),
         "--output", "initrd",
         *(["--image-id", config.image_id] if config.image_id else []),
@@ -3592,6 +3601,7 @@ def build_image(context: Context) -> None:
             finalize_staging(context)
             return
 
+        install_volatile_packages(context)
         install_build_dest(context)
         install_extra_trees(context)
         run_postinst_scripts(context)
index 8440a2cfff4bd1f8f9fc91b4b33b5f4b09d6baee..7ef100789d1b0a816965e8c3fa8219bdb56e5e64 100644 (file)
@@ -1388,6 +1388,7 @@ class Config:
 
     packages: list[str]
     build_packages: list[str]
+    volatile_packages: list[str]
     package_directories: list[Path]
     with_recommends: bool
     with_docs: bool
@@ -1422,6 +1423,7 @@ class Config:
     unified_kernel_images: ConfigFeature
     initrds: list[Path]
     initrd_packages: list[str]
+    initrd_volatile_packages: list[str]
     microcode_host: bool
     kernel_command_line: list[str]
     kernel_modules_include: list[str]
@@ -2111,6 +2113,14 @@ SETTINGS = (
         parse=config_make_list_parser(delimiter=","),
         help="Additional packages needed for build scripts",
     ),
+    ConfigSetting(
+        dest="volatile_packages",
+        long="--volatile-package",
+        metavar="PACKAGE",
+        section="Content",
+        parse=config_make_list_parser(delimiter=","),
+        help="Packages to install after executing build scripts",
+    ),
     ConfigSetting(
         dest="package_directories",
         long="--package-directory",
@@ -2368,6 +2378,14 @@ SETTINGS = (
         parse=config_make_list_parser(delimiter=","),
         help="Add additional packages to the default initrd",
     ),
+    ConfigSetting(
+        dest="initrd_volatile_packages",
+        long="--initrd-volatile-package",
+        metavar="PACKAGE",
+        section="Content",
+        parse=config_make_list_parser(delimiter=","),
+        help="Packages to install in the initrd that are not cached",
+    ),
     ConfigSetting(
         dest="kernel_command_line",
         metavar="OPTIONS",
@@ -3900,6 +3918,7 @@ def summary(config: Config) -> str:
     {bold("CONTENT")}:
                            Packages: {line_join_list(config.packages)}
                      Build Packages: {line_join_list(config.build_packages)}
+                  Volatile Packages: {line_join_list(config.volatile_packages)}
                  With Documentation: {yes_no(config.with_docs)}
 
                          Base Trees: {line_join_list(config.base_trees)}
@@ -3929,6 +3948,7 @@ def summary(config: Config) -> str:
                     Shim Bootloader: {config.shim_bootloader}
                             Initrds: {line_join_list(config.initrds)}
                     Initrd Packages: {line_join_list(config.initrd_packages)}
+           Initrd Volatile Packages: {line_join_list(config.initrd_volatile_packages)}
                 Kernel Command Line: {line_join_list(config.kernel_command_line)}
              Kernel Modules Include: {line_join_list(config.kernel_modules_include)}
              Kernel Modules Exclude: {line_join_list(config.kernel_modules_exclude)}
index e0793e264ae36aa7ec3c2762ddc7e1233cceea48..27c8718541561df6652deb736cfd1c7f9f90aa38 100644 (file)
@@ -951,6 +951,15 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
   `mkosi.build` scripts require to operate. Note that packages listed
   here will be absent in the final image.
 
+`VolatilePackages=`, `--volatile-package=`
+
+: Similar to `Packages=`, but packages configured with this setting are
+  not cached when `Incremental=` is enabled and are installed after
+  executing any build scripts.
+
+: Specifically, this setting can be used to install packages that change
+  often or which are built by a build script.
+
 `PackageDirectories=`, `--package-directory=`
 
 : Specify directories containing extra packages to be made available during
@@ -1243,6 +1252,11 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
   separated list of package specifications. This option may be used
   multiple times in which case the specified package lists are combined.
 
+`InitrdVolatilePackages=`, `--initrd-volatile-package=`
+
+: Similar to `VolatilePackages=`, except it applies to the default
+  initrd.
+
 `MicrocodeHost=`, `--microcode-host=`
 
 : When set to true only include microcode for the host's CPU in the image.
index 4af13232ba54c7738fce1b630dc930024cf1b871..5e2203731044aae55ac18a62bc84a9807d5908dc 100644 (file)
@@ -157,6 +157,9 @@ def test_config() -> None:
             "InitrdPackages": [
                 "clevis"
             ],
+            "InitrdVolatilePackages": [
+                "abc"
+            ],
             "Initrds": [
                 "/efi/initrd1",
                 "/efi/initrd2"
@@ -336,6 +339,9 @@ def test_config() -> None:
                 "Type": "file"
             },
             "VirtualMachineMonitor": "qemu",
+            "VolatilePackages": [
+                "abc"
+            ],
             "WithDocs": true,
             "WithNetwork": false,
             "WithRecommends": true,
@@ -386,6 +392,7 @@ def test_config() -> None:
         incremental = False,
         initrd_include = [Path("/foo/bar"),],
         initrd_packages = ["clevis"],
+        initrd_volatile_packages = ["abc"],
         initrds = [Path("/efi/initrd1"), Path("/efi/initrd2")],
         microcode_host=True,
         kernel_command_line = [],
@@ -485,6 +492,7 @@ def test_config() -> None:
         verity_certificate = Path("/path/to/cert"),
         verity_key = None,
         verity_key_source = KeySource(type=KeySource.Type.file),
+        volatile_packages = ["abc"],
         with_docs = True,
         with_network = False,
         with_recommends = True,