Files
euri-mklive/euri_mklive/distros/void.py
T
c-ludenberg 5c65baeb27 fix: syntax errors in all backends, wrong import path, entry point
- fix f-string escape bug in all 5 backends (user password handling)
- fix void.py import: from ..dinit (not .dinit — dinit.py is at package root)
- fix pyproject.toml entry point: cli:cli not cli:main
- add .gitignore for __pycache__
2026-08-26 20:39:42 +02:00

85 lines
3.2 KiB
Python

"""Void Linux backend — uses xbps-install with a rootfs tarball or chroot."""
from pathlib import Path
from .base import Distro
from ..dinit import install_all
class Void(Distro):
name = "void"
host_deps = ["xbps-install", "squashfs-tools", "xorriso", "mtools", "dosfstools"]
REPOS = {
"glibc": "https://repo-default.voidlinux.org/current",
"musl": "https://repo-default.voidlinux.org/current/musl",
}
def bootstrap(self, rootfs: Path, config: dict) -> None:
libc = config.get("libc", "musl")
arch = config.get("arch", "x86_64")
repo = config.get("mirror", self.REPOS.get(f"{libc}", self.REPOS["musl"]))
init = config.get("init", "dinit")
base_pkgs = ["base-system", "xbps"]
if init == "dinit":
base_pkgs.append("dinit")
cmd = [
"xbps-install",
"-S",
"-r", str(rootfs),
"-R", repo,
*base_pkgs,
]
env = {**config.get("env", {}), "XBPS_ARCH": f"{arch}-{libc}"}
self._run(cmd, env=env)
# remove runit if we're using dinit
if init == "dinit":
self._run_chroot(rootfs, ["xbps-remove", "-y", "runit"])
def install_packages(self, rootfs: Path, packages: list[str]) -> None:
if not packages:
return
self._run_chroot(rootfs, ["xbps-install", "-Sy", *packages])
def configure_base(self, rootfs: Path, config: dict) -> None:
hostname = config.get("hostname", "euri")
(rootfs / "etc/hostname").write_text(f"{hostname}\n")
for user in config.get("users", []):
name = user["name"]
shell = user.get("shell", "/bin/bash")
self._run_chroot(rootfs, ["useradd", "-m", "-s", shell, name])
if "password" in user:
pw = user["password"]
self._run_chroot(rootfs, ["bash", "-c", f"echo '{name}:{pw}' | chpasswd"])
for group in user.get("groups", []):
self._run_chroot(rootfs, ["usermod", "-aG", group, name])
init = config.get("init", "dinit")
services = config.get("services", [])
if init == "dinit":
# install real dinit service files
install_all(rootfs, services)
# enable by symlinking into boot.d
for svc in services:
self._run_chroot(rootfs, [
"ln", "-s", f"../{svc}", f"/etc/dinit.d/boot.d/{svc}"
])
else:
for svc in services:
self._run_chroot(rootfs, [
"ln", "-s", f"/etc/runit/sv/{svc}", "/etc/runit/runsvdir/default"
])
def install_bootloader(self, rootfs: Path, config: dict) -> None:
libc = config.get("libc", "musl")
pkgs = ["grub", "grub-x86_64-efi", "efibootmgr"]
self._run_chroot(rootfs, ["xbps-install", "-Sy", *pkgs])
self._run_chroot(rootfs, ["grub-install", "--target=i386-pc", "/dev/sda"])
self._run_chroot(rootfs, ["grub-install", "--target=x86_64-efi", "--efi-directory=/boot/efi", "--bootloader-id=Void"])
self._run_chroot(rootfs, ["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])