Skip to content

Commit 903958e

Browse files
authored
Merge pull request #2338 from DaanDeMeyer/fix
Fixes
2 parents 36b7618 + d138aa9 commit 903958e

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

mkosi/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,10 +2945,13 @@ def setup_workspace(args: Args, config: Config) -> Iterator[Path]:
29452945
raise
29462946

29472947

2948-
def copy_package_manager_state(context: Context) -> None:
2948+
def copy_repository_metadata(context: Context) -> None:
29492949
if have_cache(context.config) or context.config.base_trees:
29502950
return
29512951

2952+
if context.package_cache_dir.exists() and any(context.package_cache_dir.iterdir()):
2953+
return
2954+
29522955
subdir = context.config.distribution.package_manager(context.config).subdir(context.config)
29532956

29542957
for d in ("cache", "lib"):
@@ -2965,7 +2968,7 @@ def copy_package_manager_state(context: Context) -> None:
29652968
# the directories we want to exclude.
29662969
exclude = flatten(["--ro-bind", tmp, os.fspath(p)] for p in caches)
29672970

2968-
dst = context.root / "mkosi" / d / subdir
2971+
dst = context.package_cache_dir / d / subdir
29692972
with umask(~0o755):
29702973
dst.mkdir(parents=True, exist_ok=True)
29712974

@@ -2989,10 +2992,9 @@ def build_image(context: Context) -> None:
29892992
install_base_trees(context)
29902993
cached = reuse_cache(context)
29912994

2992-
# The repository metadata is copied into the image root directory to ensure it remains static and available
2993-
# when using the image to build system extensions. This has to be ordered after setup() as cache keys might
2994-
# depend on config files created by the distribution's setup() method.
2995-
copy_package_manager_state(context)
2995+
if not cached:
2996+
with mount_cache_overlay(context):
2997+
copy_repository_metadata(context)
29962998

29972999
context.config.distribution.setup(context)
29983000
install_package_directories(context)

mkosi/distributions/custom.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from collections.abc import Sequence
44

5-
from mkosi.config import Architecture
5+
from mkosi.config import Architecture, Config
66
from mkosi.context import Context
77
from mkosi.distributions import DistributionInstaller
8+
from mkosi.installer import PackageManager
89
from mkosi.log import die
910

1011

@@ -13,6 +14,10 @@ class Installer(DistributionInstaller):
1314
def architecture(cls, arch: Architecture) -> str:
1415
return str(arch)
1516

17+
@classmethod
18+
def package_manager(cls, config: Config) -> type[PackageManager]:
19+
return PackageManager
20+
1621
@classmethod
1722
def setup(cls, context: Context) -> None:
1823
pass

mkosi/installer/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
class PackageManager:
1616
@classmethod
1717
def subdir(cls, config: Config) -> Path:
18-
raise NotImplementedError
18+
return Path("custom")
1919

2020
@classmethod
2121
def cache_subdirs(cls, cache: Path) -> list[Path]:
22-
raise NotImplementedError
22+
return []
2323

2424
@classmethod
2525
def scripts(cls, context: Context) -> dict[str, list[PathString]]:
26-
raise NotImplementedError
26+
return {}
2727

2828
@classmethod
2929
def mounts(cls, context: Context) -> list[PathString]:

mkosi/resources/mkosi.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,19 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
14791479
be used to specify a size in kilobytes, megabytes and gigabytes
14801480
respectively. `directory` optionally specifies the directory in which
14811481
to create the file backing the drive. `options` optionally specifies
1482-
extra comma-delimited properties which are passed verbatime to qemu's
1482+
extra comma-delimited properties which are passed verbatim to qemu's
14831483
`-drive` option.
14841484

1485+
: Example usage:
1486+
1487+
```conf
1488+
[Host]
1489+
QemuDrives=btrfs:10G
1490+
ext4:20G
1491+
QemuArgs=-device nvme,serial=btrfs,drive=btrfs
1492+
-device nvme,serial=ext4,drive=ext4
1493+
```
1494+
14851495
`QemuArgs=`
14861496

14871497
: Space-delimited list of additional arguments to pass when invoking
@@ -1751,10 +1761,13 @@ in consecutive runs with data from the cached one.
17511761
Then, for each image, we execute the following steps:
17521762

17531763
1. Copy package manager trees into the workspace
1764+
1. Sync the package manager repository metadata
17541765
1. Copy base trees (`--base-tree=`) into the image
1766+
1. Reuse a cached image if one is available
1767+
1. Copy a snapshot of the package manager repository metadata into the
1768+
image
17551769
1. Copy skeleton trees (`mkosi.skeleton`) into image
1756-
1. Install distribution and packages into image or use cache tree if
1757-
available
1770+
1. Install distribution and packages into image
17581771
1. Run prepare scripts on image with the `final` argument (`mkosi.prepare`)
17591772
1. Install build packages in overlay if any build scripts are configured
17601773
1. Run prepare scripts on overlay with the `build` argument if any build

0 commit comments

Comments
 (0)