return Compression.none
+def config_default_distribution(namespace: argparse.Namespace) -> Distribution:
+ detected = detect_distribution()[0]
+
+ if not detected:
+ die("Distribution of your host can't be detected or isn't a supported target. Please set Distribution= in your config.")
+
+ return detected
+
+
def config_default_release(namespace: argparse.Namespace) -> str:
# If the configured distribution matches the host distribution, use the same release as the host.
hd, hr = detect_distribution()
section="Distribution",
parse=config_make_enum_parser(Distribution),
match=config_make_enum_matcher(Distribution),
- default=detect_distribution()[0],
+ default_factory=config_default_distribution,
choices=Distribution.values(),
help="Distribution to install",
),
def test_parse_load_verb(tmp_path: Path) -> None:
+ (tmp_path / "mkosi.conf").write_text("[Distribution]\nDistribution=fedora")
with chdir(tmp_path):
assert parse_config(["build"])[0].verb == Verb.build
assert parse_config(["clean"])[0].verb == Verb.clean
confd = Path("mkosi.conf.d")
confd.mkdir()
- (confd / "10-file.conf").write_text("[Content]\nPackages=yes")
- (confd / "20-file.noconf").write_text("[Content]\nPackages=nope")
+ (confd / "10-file.conf").write_text(
+ """\
+ [Distribution]
+ Distribution=fedora
+
+ [Content]
+ Packages=yes
+ """
+ )
+ (confd / "20-file.noconf").write_text(
+ """\
+ [Distribution]
+ Distribution=fedora
+
+ [Content]
+ Packages=yes
+ """
+ )
_, [config] = parse_config()
assert config.packages == ["yes"]
def test_compression(tmp_path: Path) -> None:
with chdir(tmp_path):
- _, [config] = parse_config(["--format", "disk", "--compress-output", "False"])
+ _, [config] = parse_config(["--format", "disk", "--compress-output", "False", "--distribution", "fedora"])
assert config.compress_output == Compression.none
parent.write_text(
"""\
[Distribution]
+ Distribution=fedora
ImageId=testimage
ImageVersion=123
"""
with chdir(tmp_path):
config = Path("mkosi.conf")
with config.open("w") as f:
- f.write("[Content]\n")
+ f.write(
+ """
+ [Distribution]
+ Distribution=fedora
+
+ [Content]
+ """
+ )
if skel is not None:
- f.write(f"SkeletonTrees={skel}\n")
+ f.write(f"""
+ SkeletonTrees={skel}
+ """
+ )
if pkgmngr is not None:
- f.write(f"PackageManagerTrees={pkgmngr}\n")
+ f.write(f"""
+ PackageManagerTrees={pkgmngr}
+ """
+ )
_, [conf] = parse_config()