add wayland option

This commit is contained in:
Jörg Thalheim
2023-12-08 14:02:32 +01:00
parent 10930c27bf
commit 49010f4d46

View File

@@ -40,6 +40,7 @@ def qemu_command(
"-m", f'{nixos_config["memorySize"]}M', "-m", f'{nixos_config["memorySize"]}M',
"-smp", str(nixos_config["cores"]), "-smp", str(nixos_config["cores"]),
"-cpu", "max", "-cpu", "max",
"-enable-kvm",
"-device", "virtio-rng-pci", "-device", "virtio-rng-pci",
"-net", "nic,netdev=user.0,model=virtio", "-net", "nic,netdev=user.0,model=virtio",
"-netdev", "user,id=user.0", "-netdev", "user,id=user.0",
@@ -50,9 +51,6 @@ def qemu_command(
"-drive", f"cache=writeback,file={disk_img},format=raw,id=drive1,if=none,index=1,werror=report", "-drive", f"cache=writeback,file={disk_img},format=raw,id=drive1,if=none,index=1,werror=report",
"-device", "virtio-blk-pci,bootindex=1,drive=drive1,serial=root", "-device", "virtio-blk-pci,bootindex=1,drive=drive1,serial=root",
"-device", "virtio-keyboard", "-device", "virtio-keyboard",
# TODO: we also need to fixup timezone than...
# "-rtc", "base=localtime,clock=host,driftfix=slew",
"-vga", "virtio",
"-usb", "-device", "usb-tablet,bus=usb-bus.0", "-usb", "-device", "usb-tablet,bus=usb-bus.0",
"-kernel", f'{nixos_config["toplevel"]}/kernel', "-kernel", f'{nixos_config["toplevel"]}/kernel',
"-initrd", nixos_config["initrd"], "-initrd", nixos_config["initrd"],
@@ -60,13 +58,14 @@ def qemu_command(
] # fmt: on ] # fmt: on
if vm.graphics: if vm.graphics:
if vm.wayland:
# fmt: off # fmt: off
command.extend( command.extend(
[ [
"-audiodev", "spice,id=audio0", "-audiodev", "spice,id=audio0",
"-device", "intel-hda", "-device", "intel-hda",
"-device", "hda-duplex,audiodev=audio0", "-device", "hda-duplex,audiodev=audio0",
"-vga", "none", "-display", "gtk,gl=on",
"-device", "virtio-gpu-gl", "-device", "virtio-gpu-gl",
"-display", "spice-app,gl=on", "-display", "spice-app,gl=on",
"-device", "virtio-serial-pci", "-device", "virtio-serial-pci",
@@ -85,6 +84,16 @@ def qemu_command(
] ]
) )
# fmt: on # fmt: on
else:
# fmt: off
command.extend(
[
"-nographic",
"-vga", "none",
"-device", "virtio-gpu-rutabaga,gfxstream-vulkan=on,cross-domain=on,hostmem=4G,wsi=headless",
]
)
# fmt: on
else: else:
command.append("-nographic") command.append("-nographic")
return command return command
@@ -246,17 +255,20 @@ def run_vm(
spice_socket=spice_socket, spice_socket=spice_socket,
) )
print("$ " + shlex.join(qemu_cmd)) if vm.wayland:
packages = ["git+https://git.clan.lol/clan/clan-core.git#qemu-wayland"]
else:
packages = ["qemu"] packages = ["qemu"]
if vm.graphics:
packages.append("virt-viewer")
env = os.environ.copy() env = os.environ.copy()
if vm.graphics and not vm.wayland:
packages.append("virt-viewer")
remote_viewer_mimetypes = module_root() / "vms" / "mimetypes" remote_viewer_mimetypes = module_root() / "vms" / "mimetypes"
env[ env[
"XDG_DATA_DIRS" "XDG_DATA_DIRS"
] = f"{remote_viewer_mimetypes}:{env.get('XDG_DATA_DIRS', '')}" ] = f"{remote_viewer_mimetypes}:{env.get('XDG_DATA_DIRS', '')}"
print(env["XDG_DATA_DIRS"])
print("$ " + shlex.join(qemu_cmd))
res = subprocess.run( res = subprocess.run(
nix_shell(packages, qemu_cmd), nix_shell(packages, qemu_cmd),
env=env, env=env,
@@ -274,6 +286,7 @@ class RunOptions:
flake_url: str | None flake_url: str | None
flake: Path flake: Path
nix_options: list[str] = field(default_factory=list) nix_options: list[str] = field(default_factory=list)
wayland: bool = False
def run_command(args: argparse.Namespace) -> None: def run_command(args: argparse.Namespace) -> None:
@@ -282,10 +295,13 @@ def run_command(args: argparse.Namespace) -> None:
flake_url=args.flake_url, flake_url=args.flake_url,
flake=args.flake or Path.cwd(), flake=args.flake or Path.cwd(),
nix_options=args.option, nix_options=args.option,
wayland=args.wayland,
) )
flake_url = run_options.flake_url or run_options.flake flake_url = run_options.flake_url or run_options.flake
vm = inspect_vm(flake_url=flake_url, flake_attr=run_options.machine) vm = inspect_vm(flake_url=flake_url, flake_attr=run_options.machine)
# TODO: allow to set this in the config
vm.wayland = run_options.wayland
run_vm(vm, run_options.nix_options) run_vm(vm, run_options.nix_options)
@@ -293,4 +309,5 @@ def run_command(args: argparse.Namespace) -> None:
def register_run_parser(parser: argparse.ArgumentParser) -> None: def register_run_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument("machine", type=str, help="machine in the flake to run") parser.add_argument("machine", type=str, help="machine in the flake to run")
parser.add_argument("--flake-url", type=str, help="flake url") parser.add_argument("--flake-url", type=str, help="flake url")
parser.add_argument("--wayland", action="store_true", help="use wayland")
parser.set_defaults(func=run_command) parser.set_defaults(func=run_command)