From: Daan De Meyer Date: Mon, 31 Mar 2025 12:37:27 +0000 (+0200) Subject: Allow adding extra tools tree configuration via mkosi.tools.conf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3636%2Fhead;p=thirdparty%2Fmkosi.git Allow adding extra tools tree configuration via mkosi.tools.conf Instead of adding ever more ToolsTreeXXX= settings, let's allow adding extra tools tree configuration via mkosi.tools.conf which can be either a file or a directory containing extra configuration for the default tools tree. --- diff --git a/mkosi.conf.d/40-tools/mkosi.conf b/mkosi.tools.conf/mkosi.conf similarity index 73% rename from mkosi.conf.d/40-tools/mkosi.conf rename to mkosi.tools.conf/mkosi.conf index 4eef1de8c..31dbbd53a 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf +++ b/mkosi.tools.conf/mkosi.conf @@ -1,6 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later -[Build] -ToolsTreePackages= +[Content] +Packages= gnupg lvm2 diff --git a/mkosi.conf.d/40-tools/mkosi.conf.d/arch.conf b/mkosi.tools.conf/mkosi.conf.d/arch.conf similarity index 72% rename from mkosi.conf.d/40-tools/mkosi.conf.d/arch.conf rename to mkosi.tools.conf/mkosi.conf.d/arch.conf index 48805ca3c..c7b6bf001 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf.d/arch.conf +++ b/mkosi.tools.conf/mkosi.conf.d/arch.conf @@ -1,10 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -ToolsTreeDistribution=arch +Distribution=arch -[Build] -ToolsTreePackages= +[Content] +Packages= cryptsetup mypy python-pytest diff --git a/mkosi.conf.d/40-tools/mkosi.conf.d/azure-centos-fedora.conf b/mkosi.tools.conf/mkosi.conf.d/azure-centos-fedora.conf similarity index 50% rename from mkosi.conf.d/40-tools/mkosi.conf.d/azure-centos-fedora.conf rename to mkosi.tools.conf/mkosi.conf.d/azure-centos-fedora.conf index a49ef929d..c2256624c 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf.d/azure-centos-fedora.conf +++ b/mkosi.tools.conf/mkosi.conf.d/azure-centos-fedora.conf @@ -1,12 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -ToolsTreeDistribution=|azure -ToolsTreeDistribution=|centos -ToolsTreeDistribution=|fedora +Distribution=|azure +Distribution=|centos +Distribution=|fedora -[Build] -ToolsTreePackages= +[Content] +Packages= cryptsetup python3-mypy python3-pytest diff --git a/mkosi.conf.d/40-tools/mkosi.conf.d/debian-kali-ubuntu.conf b/mkosi.tools.conf/mkosi.conf.d/debian-kali-ubuntu.conf similarity index 55% rename from mkosi.conf.d/40-tools/mkosi.conf.d/debian-kali-ubuntu.conf rename to mkosi.tools.conf/mkosi.conf.d/debian-kali-ubuntu.conf index 85ebe3019..ba02e0d14 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf.d/debian-kali-ubuntu.conf +++ b/mkosi.tools.conf/mkosi.conf.d/debian-kali-ubuntu.conf @@ -1,12 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -ToolsTreeDistribution=|debian -ToolsTreeDistribution=|kali -ToolsTreeDistribution=|ubuntu +Distribution=|debian +Distribution=|kali +Distribution=|ubuntu -[Build] -ToolsTreePackages= +[Content] +Packages= cryptsetup-bin fdisk mypy diff --git a/mkosi.conf.d/40-tools/mkosi.conf.d/fedora.conf b/mkosi.tools.conf/mkosi.conf.d/fedora.conf similarity index 61% rename from mkosi.conf.d/40-tools/mkosi.conf.d/fedora.conf rename to mkosi.tools.conf/mkosi.conf.d/fedora.conf index 0ec19244c..0247e1389 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf.d/fedora.conf +++ b/mkosi.tools.conf/mkosi.conf.d/fedora.conf @@ -1,9 +1,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -ToolsTreeDistribution=fedora +Distribution=fedora -[Build] -ToolsTreePackages= +[Content] +Packages= ruff sequoia-sop diff --git a/mkosi.conf.d/40-tools/mkosi.conf.d/opensuse.conf b/mkosi.tools.conf/mkosi.conf.d/opensuse.conf similarity index 80% rename from mkosi.conf.d/40-tools/mkosi.conf.d/opensuse.conf rename to mkosi.tools.conf/mkosi.conf.d/opensuse.conf index 2a7cd1118..f764b4141 100644 --- a/mkosi.conf.d/40-tools/mkosi.conf.d/opensuse.conf +++ b/mkosi.tools.conf/mkosi.conf.d/opensuse.conf @@ -1,10 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -ToolsTreeDistribution=opensuse +Distribution=opensuse -[Build] -ToolsTreePackages= +[Content] +Packages= cryptsetup grub2 # TODO: Move to default tools tree when https://bugzilla.opensuse.org/show_bug.cgi?id=1227464 is resolved. mypy diff --git a/mkosi/config.py b/mkosi/config.py index 2cabd3a18..72a7e6164 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -4951,6 +4951,10 @@ def finalize_default_tools(main: ParseContext, finalized: dict[str, Any], *, res for name in finalized.get("environment", {}).keys() & finalized.get("pass_environment", []) } + if (p := Path("mkosi.tools.conf").absolute()).exists(): + with chdir(p if p.is_dir() else Path.cwd()): + context.parse_config_one(p, parse_profiles=p.is_dir(), parse_local=p.is_dir()) + with chdir(resources / "mkosi-tools"): context.parse_config_one(resources / "mkosi-tools", parse_profiles=True) diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index b7992f163..66084b164 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -1316,7 +1316,9 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, any of the extra search paths. If set to `default`, **mkosi** will automatically add an extra tools tree - image and use it as the tools tree. + image and use it as the tools tree. This image can be further configured + using the settings below or with `mkosi.tools.conf` which can either be a + file or directory containing extra configuration for the default tools tree. The following table shows for which distributions default tools tree packages are defined and which packages are included in those default diff --git a/tests/test_config.py b/tests/test_config.py index 0f838e4d7..5d93c78ba 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,6 +9,7 @@ from pathlib import Path import pytest +import mkosi.resources from mkosi import expand_kernel_specifiers from mkosi.config import ( Architecture, @@ -24,7 +25,7 @@ from mkosi.config import ( parse_ini, ) from mkosi.distributions import Distribution, detect_distribution -from mkosi.util import chdir +from mkosi.util import chdir, resource_path def test_compression_enum_creation() -> None: @@ -1413,3 +1414,53 @@ def test_cli_collection_reset(tmp_path: Path) -> None: _, _, [config] = parse_config(["--package", "foo", "--package", ""]) assert config.packages == [] + + +def test_tools(tmp_path: Path) -> None: + d = tmp_path + argv = ["--tools-tree=default"] + + with resource_path(mkosi.resources) as resources, chdir(d): + _, tools, _ = parse_config(argv, resources=resources) + assert tools + host = detect_distribution()[0] + assert host + assert tools.distribution == host.default_tools_tree_distribution() + + (d / "mkosi.tools.conf").write_text( + f""" + [Distribution] + Distribution=debian + + [Content] + PackageDirectories={d} + """ + ) + + _, tools, _ = parse_config(argv, resources=resources) + assert tools + assert tools.distribution == Distribution.debian + assert tools.package_directories == [Path(d)] + + _, tools, _ = parse_config( + argv + ["--tools-tree-distribution=arch", "--tools-tree-package-directory=/tmp"], + resources=resources, + ) + assert tools + assert tools.distribution == Distribution.arch + assert tools.package_directories == [Path(d), Path("/tmp")] + + _, tools, _ = parse_config(argv + ["--tools-tree-package-directory="], resources=resources) + assert tools + assert tools.package_directories == [] + + (d / "mkosi.conf").write_text( + """ + [Build] + ToolsTreeDistribution=arch + """ + ) + + _, tools, _ = parse_config(argv, resources=resources) + assert tools + assert tools.distribution == Distribution.debian