From: Daan De Meyer Date: Sat, 14 Feb 2026 21:37:43 +0000 (+0100) Subject: Look at all CacheOnly= settings to determine if we need to sync metadata X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53bd2da6feef13244df06b1e286f4bde1b7831e3;p=thirdparty%2Fmkosi.git Look at all CacheOnly= settings to determine if we need to sync metadata 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a38ce440c..9c24ab693 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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, diff --git a/mkosi/config.py b/mkosi/config.py index 37d3b4912..daf3e2c6e 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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", diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 23adf9d18..6db0f08e6 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -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=`