]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
postmarketos: Set up usrmerge in install() instead of setup()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Sep 2025 08:41:59 +0000 (10:41 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Sep 2025 08:48:49 +0000 (10:48 +0200)
We try to not touch the rootfs directory in setup() at all, so set
up merged /usr in install() instead like we do for debian. Additionally,
we also make sync() does not touch the rootfs either by having it operate
on a temporary directory instead of the real rootfs.

mkosi/distributions/postmarketos.py
mkosi/installer/apk.py

index e03843c44997961ec137c8db5f52693e793fe00f..2404be30e82eea970b92af1eb3ef35552186147a 100644 (file)
@@ -38,12 +38,6 @@ class Installer(DistributionInstaller):
 
     @classmethod
     def setup(cls, context: Context) -> None:
-        # TODO: Create merged /usr manually for now until our upstream (Alpine Linux) supports it:
-        # https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/85504
-        for dir in ["lib", "bin", "sbin"]:
-            (context.root / "usr" / dir).mkdir(parents=True, exist_ok=True)
-            (context.root / dir).symlink_to(f"usr/{dir}")
-
         with complete_step("Setting up postmarketOS keyring"):
             # Create keys directory in sandbox
             keys_dir = context.sandbox_tree / "etc/apk/keys"
@@ -69,6 +63,12 @@ class Installer(DistributionInstaller):
 
     @classmethod
     def install(cls, context: Context) -> None:
+        # TODO: Create merged /usr manually for now until our upstream (Alpine Linux) supports it:
+        # https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/85504
+        for dir in ["lib", "bin", "sbin"]:
+            (context.root / "usr" / dir).mkdir(parents=True, exist_ok=True)
+            (context.root / dir).symlink_to(f"usr/{dir}")
+
         Apk.install(context, ["postmarketos-baselayout", "postmarketos-release"], apivfs=False)
 
     @classmethod
index c489ab686df951fa0cf0a7342dfdadcabc9a24a6..5f31ec140f9a14e2d457dfc05ae5a6391c24e107 100644 (file)
@@ -9,6 +9,7 @@ from mkosi.config import Config
 from mkosi.context import Context
 from mkosi.installer import PackageManager
 from mkosi.run import CompletedProcess, run, workdir
+from mkosi.tree import rmtree
 from mkosi.util import _FILE, PathString
 
 
@@ -112,9 +113,14 @@ class Apk(PackageManager):
 
     @classmethod
     def sync(cls, context: Context, force: bool) -> None:
-        # Initialize database first
+        # Updating the cache requires an initialized apk database but we don't want to touch the image root
+        # directory so temporarily replace it with an empty directory to make apk happy.
+        saved = context.root.rename(context.workspace / "saved-root")
+        context.root.mkdir()
         cls.invoke(context, "add", ["--initdb"])
         cls.invoke(context, "update", ["--update-cache"] if force else [])
+        rmtree(context.root)
+        saved.rename(context.root)
 
     @classmethod
     def createrepo(cls, context: Context) -> None: