Skip to content

Commit

Permalink
Merge pull request #2338 from DaanDeMeyer/fix
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
behrmann authored Feb 1, 2024
2 parents 36b7618 + d138aa9 commit 903958e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
14 changes: 8 additions & 6 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,10 +2945,13 @@ def setup_workspace(args: Args, config: Config) -> Iterator[Path]:
raise


def copy_package_manager_state(context: Context) -> None:
def copy_repository_metadata(context: Context) -> None:
if have_cache(context.config) or context.config.base_trees:
return

if context.package_cache_dir.exists() and any(context.package_cache_dir.iterdir()):
return

subdir = context.config.distribution.package_manager(context.config).subdir(context.config)

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

dst = context.root / "mkosi" / d / subdir
dst = context.package_cache_dir / d / subdir
with umask(~0o755):
dst.mkdir(parents=True, exist_ok=True)

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

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

context.config.distribution.setup(context)
install_package_directories(context)
Expand Down
7 changes: 6 additions & 1 deletion mkosi/distributions/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from collections.abc import Sequence

from mkosi.config import Architecture
from mkosi.config import Architecture, Config
from mkosi.context import Context
from mkosi.distributions import DistributionInstaller
from mkosi.installer import PackageManager
from mkosi.log import die


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

@classmethod
def package_manager(cls, config: Config) -> type[PackageManager]:
return PackageManager

@classmethod
def setup(cls, context: Context) -> None:
pass
Expand Down
6 changes: 3 additions & 3 deletions mkosi/installer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class PackageManager:
@classmethod
def subdir(cls, config: Config) -> Path:
raise NotImplementedError
return Path("custom")

@classmethod
def cache_subdirs(cls, cache: Path) -> list[Path]:
raise NotImplementedError
return []

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

@classmethod
def mounts(cls, context: Context) -> list[PathString]:
Expand Down
19 changes: 16 additions & 3 deletions mkosi/resources/mkosi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1479,9 +1479,19 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
be used to specify a size in kilobytes, megabytes and gigabytes
respectively. `directory` optionally specifies the directory in which
to create the file backing the drive. `options` optionally specifies
extra comma-delimited properties which are passed verbatime to qemu's
extra comma-delimited properties which are passed verbatim to qemu's
`-drive` option.

: Example usage:

```conf
[Host]
QemuDrives=btrfs:10G
ext4:20G
QemuArgs=-device nvme,serial=btrfs,drive=btrfs
-device nvme,serial=ext4,drive=ext4
```

`QemuArgs=`

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

1. Copy package manager trees into the workspace
1. Sync the package manager repository metadata
1. Copy base trees (`--base-tree=`) into the image
1. Reuse a cached image if one is available
1. Copy a snapshot of the package manager repository metadata into the
image
1. Copy skeleton trees (`mkosi.skeleton`) into image
1. Install distribution and packages into image or use cache tree if
available
1. Install distribution and packages into image
1. Run prepare scripts on image with the `final` argument (`mkosi.prepare`)
1. Install build packages in overlay if any build scripts are configured
1. Run prepare scripts on overlay with the `build` argument if any build
Expand Down

0 comments on commit 903958e

Please sign in to comment.