]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Look at all CacheOnly= settings to determine if we need to sync metadata
authorDaan De Meyer <daan@amutable.com>
Sat, 14 Feb 2026 21:37:43 +0000 (22:37 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 15 Feb 2026 12:47:59 +0000 (13:47 +0100)
Instead of only looking at the CacheOnly= setting of the main image,
let's allow subimages to also configure it to instruct whether repository
metadata should be synced for that image or not.

Also, let's change the behavior of "auto". Currently, we don't sync
repository metadata as long as we have a cached image. The idea behind
this was to avoid weird problems when installing packages in postinst
scripts or such that would see newer repository metadata than the repository
metadata that the image was built with.

While this still holds, the problem with the current approach is that
for regular uses, the default initrd will always have a cache and as such,
even when the main image is out-of-date, we still won't sync repository metadata,
eventually resulting in the repository metadata being so out of date that
the packages can't be found in the mirrors anymore.

The latter is much more likely to happen than the former, so let's sync
repository metadata every time we have any image that does not have a cache.
The user now has the option to customize the behavior per image if they don't
like the default behavior.

mkosi/__init__.py
mkosi/config.py
mkosi/resources/man/mkosi.1.md

index a38ce440c256f0c3018558661778f4cb5999b0df..9c24ab6933dd5b872d0ea7ff1ca50387dcd3f7eb 100644 (file)
@@ -4872,10 +4872,14 @@ def sync_repository_metadata(
 
     (last.package_cache_dir_or_default() / "cache" / subdir).mkdir(parents=True, exist_ok=True)
 
+    def needs_sync(config: Config) -> bool:
+        if config.cacheonly != Cacheonly.auto:
+            return config.cacheonly == Cacheonly.never
+
+        return not have_cache(config)
+
     # Sync repository metadata unless explicitly disabled.
-    if last.cacheonly == Cacheonly.never or (
-        last.cacheonly == Cacheonly.auto and not any(have_cache(config) for config in images)
-    ):
+    if any(needs_sync(config) for config in images):
         with setup_workspace(args, last) as workspace:
             context = Context(
                 args,
index 37d3b49121fce824be97bdf3c494c9d4b20354e2..daf3e2c6eaaaaa35f4ff8b0f9490fcd63fc26bff 100644 (file)
@@ -3831,7 +3831,7 @@ SETTINGS: list[ConfigSetting[Any]] = [
         default=Cacheonly.auto,
         help="Only use the package cache when installing packages",
         choices=Cacheonly.choices(),
-        scope=SettingScope.multiversal,
+        scope=SettingScope.inherit,
     ),
     ConfigSetting(
         dest="sandbox_trees",
index 23adf9d18c63766c97c56bfc12e92b1a4a614205..6db0f08e64dddd501c4137f5edfbcac52018b934 100644 (file)
@@ -1564,10 +1564,9 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     as the package cache is already fully populated. If set to `metadata`,
     the package manager can still download packages, but we won't sync the
     repository metadata. If set to `auto`, the repository metadata is
-    synced unless we have a cached image (see `Incremental=`) and packages
-    can be downloaded during the build. If set to `never`, repository
-    metadata is always synced and packages can be downloaded during
-    the build.
+    synced unless the image is cached (see `Incremental=`) and packages can
+    be downloaded during the build. If set to `never`, repository metadata
+    is always synced and packages can be downloaded during the build.
 
 `SandboxTrees=`, `--sandbox-tree=`
 :   Takes a comma-separated list of colon-separated path pairs. The first
@@ -3065,7 +3064,6 @@ image:
 - `RepositoryKeyCheck=`
 - `RepositoryKeyFetch=`
 - `SourceDateEpoch=`
-- `CacheOnly=`
 - `WorkspaceDirectory=`
 - `PackageCacheDirectory=`
 - `BuildSources=`
@@ -3116,6 +3114,7 @@ the subimage will take priority over values configured on the CLI or
 in the main image config. Currently the following settings are passed
 down to subimages but can be overridden:
 
+- `CacheOnly=`
 - `Profiles=`
 - `ImageId=`
 - `ImageVersion=`