]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add --repository-directory option
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 30 Mar 2022 14:00:04 +0000 (16:00 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 31 Mar 2022 12:41:19 +0000 (13:41 +0100)
The repository directory can contain extra repositories to be
used when installing packages. If mkosi.reposdir/ exists, it's
used as the repository directory unless it's explicitly
specified.

Only supported for rpm based distros and Arch for now. We don't
support Ubuntu/Debian atm because we can't point apt to the
extra repositories directory because apt runs inside the image
compared to dnf and pacman which run outside of the image.

mkosi.md
mkosi/__init__.py
mkosi/backend.py
tests/test_config_parser.py

index 335b489901705e3a8ca2fbdd7da830b772d1e6ce..cd974fad81894ec77f619b3ee6576ad73e25629e 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -314,14 +314,22 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
 
 `UseHostRepositories=`, `--use-host-repositories`
 
-: This option is only applicable for dnf-based distributions:
+: This option is only applicable for RPM-based distributions:
   *CentOS*, *Fedora Linux*, *Mageia*, *Photon*, *Rocky Linux*, *Alma Linux*
   and *OpenMandriva*.
-  Allows use of the host's existing dnf repositories.
-  By default, a hardcoded set of default dnf repositories is generated and used.
+  Allows use of the host's existing RPM repositories.
+  By default, a hardcoded set of default RPM repositories is generated and used.
   Use `--repositories=` to identify a custom set of repositories to be enabled
   and used for the build.
 
+`RepositoryDirectory`, `--repository-directory`
+
+: This option can (for now) only be used with RPM-based istributions and Arch
+  Linux. It identifies a directory containing extra repository definitions that
+  will be used when installing packages. The files are passed directly to the
+  corresponding package manager and should be written in the format expected by
+  the package manager of the image's distro.
+
 `Architecture=`, `--architecture=`
 
 : The architecture to build the image for. Note that this currently
@@ -1508,6 +1516,10 @@ local directory:
   build result of a preceding run might be copied into a build image
   as part of the source tree (see above).
 
+* The **`mkosi.reposdir/`** directory, if it exists, is automatically
+  used as the repository directory for extra repository files. See
+  the `RepositoryDirectory` option for more information.
+
 All these files are optional.
 
 Note that the location of all these files may also be configured
index 61188106726819c8f9b08ba861bcbcd0c89eaed9..e47881dfa024bcc05734659b21713f734358767c 100644 (file)
@@ -81,6 +81,7 @@ from .backend import (
     Verb,
     die,
     install_grub,
+    is_rpm_distribution,
     nspawn_params_for_blockdev_access,
     nspawn_rlimit_params,
     patch_file,
@@ -2109,7 +2110,8 @@ def setup_dnf(args: MkosiArgs, root: Path, repos: Sequence[Repo] = ()) -> None:
     if args.use_host_repositories:
         default_repos  = ""
     else:
-        default_repos  = f"{'repodir' if args.distribution == Distribution.photon else 'reposdir'}={workspace(root)}"
+        option = "repodir" if args.distribution == Distribution.photon else "reposdir"
+        default_repos  = f"{option}={workspace(root)} {args.repos_dir if args.repos_dir else ''}"
 
     config_file = workspace(root) / "dnf.conf"
     config_file.write_text(
@@ -2901,6 +2903,8 @@ def install_arch(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None
 
                 [community]
                 {server}
+
+                {f"Include = {args.repos_dir}/*" if args.repos_dir else ""}
                 """
             )
         )
@@ -5125,6 +5129,8 @@ def create_parser() -> ArgumentParserMkosi:
         action=BooleanAction,
         help="Use host's existing software repositories (only for dnf-based distributions)",
     )
+    group.add_argument("--repository-directory", metavar="PATH", dest="repos_dir",
+                       help="Directory container extra distribution specific repository files")
     group.add_argument("--architecture", help="Override the architecture of installation")
 
     group = parser.add_argument_group("Output")
@@ -6214,6 +6220,7 @@ def load_args(args: argparse.Namespace) -> MkosiArgs:
     args_find_path(args, "output_dir", "mkosi.output/")
     args_find_path(args, "workspace_dir", "mkosi.workspace/")
     args_find_path(args, "mksquashfs_tool", "mkosi.mksquashfs-tool", as_list=True)
+    args_find_path(args, "repos_dir", "mkosi.reposdir/")
 
     find_extra(args)
     find_skeleton(args)
@@ -6581,6 +6588,9 @@ def load_args(args: argparse.Namespace) -> MkosiArgs:
     if args.ssh_port <= 0:
         die("--ssh-port must be > 0")
 
+    if args.repos_dir and not (is_rpm_distribution(args.distribution) or args.distribution == Distribution.arch):
+        die("--repository-directory is only supported on RPM based distributions and Arch")
+
     # We set a reasonable umask so that files that are created in the image
     # will have reasonable permissions. We don't want those permissions to be
     # influenced by the caller's umask which will be used only for output files.
index af9c50446875476f50da71ce413254164d9df1f5..f69277399258e902ab7e91e94721effab2494c41 100644 (file)
@@ -168,6 +168,20 @@ class Distribution(enum.Enum):
     def __str__(self) -> str:
         return self.name
 
+def is_rpm_distribution(d: Distribution) -> bool:
+    return d in (
+        Distribution.fedora,
+        Distribution.mageia,
+        Distribution.centos,
+        Distribution.centos_epel,
+        Distribution.photon,
+        Distribution.openmandriva,
+        Distribution.rocky,
+        Distribution.rocky_epel,
+        Distribution.alma,
+        Distribution.alma_epel
+    )
+
 
 class SourceFileTransfer(enum.Enum):
     copy_all = "copy-all"
@@ -404,6 +418,7 @@ class MkosiArgs:
     mirror: Optional[str]
     repositories: List[str]
     use_host_repositories: bool
+    repos_dir: Optional[str]
     architecture: Optional[str]
     output_format: OutputFormat
     manifest_format: List[ManifestFormat]
index a8c8a057e3d5bd15d2c1930008d76e8f161bf2a5..f51658dfd705f107d27c20603ad7bcfcfa208bff 100644 (file)
@@ -104,6 +104,7 @@ class MkosiConfig:
             "release": None,
             "repositories": [],
             "use_host_repositories": False,
+            "repos_dir": None,
             "base_image": None,
             "root_size": None,
             "secure_boot": False,