From: Daan De Meyer Date: Wed, 30 Mar 2022 14:00:04 +0000 (+0200) Subject: Add --repository-directory option X-Git-Tag: v13~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8efc4c5c540a589d3bbb2723ddbe2ab58a30e528;p=thirdparty%2Fmkosi.git Add --repository-directory option 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. --- diff --git a/mkosi.md b/mkosi.md index 335b48990..cd974fad8 100644 --- 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 diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 611881067..e47881dfa 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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. diff --git a/mkosi/backend.py b/mkosi/backend.py index af9c50446..f69277399 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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] diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index a8c8a057e..f51658dfd 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -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,