cmdline += ["--definitions", workdir(d)]
opts += ["--ro-bind", d, workdir(d)]
- def can_orphan_file(distribution: Optional[Distribution], release: Optional[str]) -> bool:
- if distribution is None:
+ def can_orphan_file(distribution: Union[Distribution, str, None], release: Optional[str]) -> bool:
+ if not isinstance(distribution, Distribution):
return True
return not (
def config_default_distribution(namespace: dict[str, Any]) -> Distribution:
- if d := os.getenv("MKOSI_HOST_DISTRIBUTION"):
+ if (d := os.getenv("MKOSI_HOST_DISTRIBUTION")) and d in Distribution.values():
return Distribution(d)
detected = detect_distribution()[0]
- if not detected:
+ if not isinstance(detected, Distribution):
logging.info(
"Distribution of your host can't be detected or isn't a supported target. "
"Defaulting to Distribution=custom."
def config_default_release(namespace: dict[str, Any]) -> str:
- hd: Optional[Distribution]
+ hd: Union[Distribution, str, None]
hr: Optional[str]
- if (d := os.getenv("MKOSI_HOST_DISTRIBUTION")) and (r := os.getenv("MKOSI_HOST_RELEASE")):
+ if (
+ (d := os.getenv("MKOSI_HOST_DISTRIBUTION"))
+ and d in Distribution.values()
+ and (r := os.getenv("MKOSI_HOST_RELEASE"))
+ ):
hd, hr = Distribution(d), r
else:
hd, hr = detect_distribution()
def config_default_tools_tree_distribution(namespace: dict[str, Any]) -> Distribution:
- if d := os.getenv("MKOSI_HOST_DISTRIBUTION"):
+ if (d := os.getenv("MKOSI_HOST_DISTRIBUTION")) and d in Distribution.values():
return Distribution(d).installer.default_tools_tree_distribution() or Distribution(d)
detected = detect_distribution()[0]
- if not detected:
+ if not isinstance(detected, Distribution):
return Distribution.custom
return detected.installer.default_tools_tree_distribution() or detected
return distribution == Distribution.arch or distribution.is_rpm_distribution()
if namespace["tools_tree"] not in (Path("default"), Path("yes")):
- return (
- detect_distribution(namespace["tools_tree"] or Path("/"))[0] == Distribution.ubuntu
- and needs_repository_key_fetch(namespace["distribution"])
- ) # fmt: skip
+ d = detect_distribution(namespace["tools_tree"] or Path("/"))[0]
+ if d == "nixos":
+ return True
+
+ return d == Distribution.ubuntu and needs_repository_key_fetch(namespace["distribution"])
return namespace["tools_tree_distribution"] == Distribution.ubuntu and needs_repository_key_fetch(
namespace["distribution"]
import urllib.parse
from collections.abc import Sequence
from pathlib import Path
-from typing import TYPE_CHECKING, Optional
+from typing import TYPE_CHECKING, Optional, Union
from mkosi.log import die
from mkosi.util import StrEnum, read_env_file
return False
-def detect_distribution(root: Path = Path("/")) -> tuple[Optional[Distribution], Optional[str]]:
+def detect_distribution(root: Path = Path("/")) -> tuple[Union[Distribution, str, None], Optional[str]]:
try:
os_release = read_env_file(root / "etc/os-release")
except FileNotFoundError:
except FileNotFoundError:
return None, None
- dist_id = os_release.get("ID", "linux")
+ dist_id = os_release.get("ID")
dist_id_like = os_release.get("ID_LIKE", "").split()
version_id = os_release.get("VERSION_ID", None) if dist_id != "opensuse-tumbleweed" else "tumbleweed"
version_codename = os_release.get("VERSION_CODENAME", None)
quirks = {
- "azurelinux": Distribution.azure,
+ "azurelinux": "azure",
}
d: Optional[Distribution] = None
for the_id in [dist_id, *dist_id_like]:
- d = Distribution.__members__.get(the_id, quirks.get(the_id))
- if d is not None:
+ if not the_id:
+ continue
+
+ if the_id in Distribution.values() or the_id in quirks:
+ d = Distribution(quirks.get(the_id, the_id))
break
if d and d.is_apt_distribution() and version_codename:
version_id = version_codename
- return d, version_id
+ return d or dist_id, version_id
def join_mirror(mirror: str, link: str) -> str:
from mkosi.config import Config
from mkosi.context import Context
-from mkosi.distribution import detect_distribution
+from mkosi.distribution import Distribution, detect_distribution
from mkosi.installer import PackageManager
from mkosi.log import complete_step
from mkosi.run import CompletedProcess, run, workdir
if (
(d := detect_distribution(context.config.tools())[0])
+ and isinstance(d, Distribution)
and d.is_apt_distribution()
and (context.sandbox_tree / "usr/share/pacman/keyrings").exists()
):
@classmethod
def values(cls) -> list[str]:
- return list(s.replace("_", "-") for s in map(str, cls.__members__))
+ return [d.value for d in cls.__members__.values()]
@classmethod
def choices(cls) -> list[str]:
_, tools, _ = parse_config(argv, resources=resources)
assert tools
host = detect_distribution()[0]
- if host:
+ if isinstance(host, Distribution):
assert tools.distribution == (
host.installer.default_tools_tree_distribution() or tools.distribution
)