]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fixed running prepare and post-install scripts when UsrOnly is in use
authorMichael A Cassaniti <michael@cassaniti.id.au>
Mon, 18 Jul 2022 01:26:28 +0000 (11:26 +1000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 18 Jul 2022 16:22:16 +0000 (18:22 +0200)
Includes moving root_home() to backend

mkosi/__init__.py
mkosi/backend.py

index 1f3b939571343b48139fe1edf988ba2df57d7dcb..7eb9326d74775321120c32a1c0195dce0ae31ee8 100644 (file)
@@ -89,6 +89,7 @@ from .backend import (
     nspawn_version,
     patch_file,
     path_relative_to_cwd,
+    root_home,
     run,
     run_workspace_command,
     set_umask,
@@ -1776,20 +1777,6 @@ def prepare_tree_root(args: MkosiArgs, root: Path) -> None:
             btrfs_subvol_create(root)
 
 
-def root_home(args: MkosiArgs, root: Path) -> Path:
-
-    # If UsrOnly= is turned on the /root/ directory (i.e. the root
-    # user's home directory) is not persistent (after all everything
-    # outside of /usr/ is not around). In that case let's mount it in
-    # from an external place, so that we can have persistency. It is
-    # after all where we place our build sources and suchlike.
-
-    if args.usr_only:
-        return workspace(root) / "home-root"
-
-    return root / "root"
-
-
 def prepare_tree(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: bool) -> None:
     if cached:
         # Reuse machine-id from cached image.
index 831aa2a248b7dca39222ed52d1473031f4920171..2c0605353e0a72700ae865cacc6a6f10e668aaa6 100644 (file)
@@ -675,6 +675,9 @@ def run_workspace_command(
         stdout = subprocess.PIPE
         nspawn += ["--console=pipe"]
 
+    if args.usr_only:
+        nspawn += [f"--bind={root_home(args, root)}:/root"]
+
     if args.nspawn_keep_unit:
         nspawn += ["--keep-unit"]
 
@@ -686,6 +689,20 @@ def run_workspace_command(
         die(f"Workspace command {shell_join(cmd)} returned non-zero exit code {e.returncode}.")
 
 
+def root_home(args: MkosiArgs, root: Path) -> Path:
+
+    # If UsrOnly= is turned on the /root/ directory (i.e. the root
+    # user's home directory) is not persistent (after all everything
+    # outside of /usr/ is not around). In that case let's mount it in
+    # from an external place, so that we can have persistency. It is
+    # after all where we place our build sources and suchlike.
+
+    if args.usr_only:
+        return workspace(root) / "home-root"
+
+    return root / "root"
+
+
 @contextlib.contextmanager
 def do_delay_interrupt() -> Iterator[None]:
     # CTRL+C is sent to the entire process group. We delay its handling in mkosi itself so the subprocess can