add wayland option
This commit is contained in:
@@ -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,31 +58,42 @@ def qemu_command(
|
|||||||
] # fmt: on
|
] # fmt: on
|
||||||
|
|
||||||
if vm.graphics:
|
if vm.graphics:
|
||||||
# fmt: off
|
if vm.wayland:
|
||||||
command.extend(
|
# fmt: off
|
||||||
[
|
command.extend(
|
||||||
"-audiodev", "spice,id=audio0",
|
[
|
||||||
"-device", "intel-hda",
|
"-audiodev", "spice,id=audio0",
|
||||||
"-device", "hda-duplex,audiodev=audio0",
|
"-device", "intel-hda",
|
||||||
"-vga", "none",
|
"-device", "hda-duplex,audiodev=audio0",
|
||||||
"-device", "virtio-gpu-gl",
|
"-display", "gtk,gl=on",
|
||||||
"-display", "spice-app,gl=on",
|
"-device", "virtio-gpu-gl",
|
||||||
"-device", "virtio-serial-pci",
|
"-display", "spice-app,gl=on",
|
||||||
"-chardev", "spicevmc,id=vdagent0,name=vdagent",
|
"-device", "virtio-serial-pci",
|
||||||
"-device", "virtserialport,chardev=vdagent0,name=com.redhat.spice.0",
|
"-chardev", "spicevmc,id=vdagent0,name=vdagent",
|
||||||
"-device", "qemu-xhci,id=spicepass",
|
"-device", "virtserialport,chardev=vdagent0,name=com.redhat.spice.0",
|
||||||
"-chardev", "spicevmc,id=usbredirchardev1,name=usbredir",
|
"-device", "qemu-xhci,id=spicepass",
|
||||||
"-device", "usb-redir,chardev=usbredirchardev1,id=usbredirdev1",
|
"-chardev", "spicevmc,id=usbredirchardev1,name=usbredir",
|
||||||
"-chardev", "spicevmc,id=usbredirchardev2,name=usbredir",
|
"-device", "usb-redir,chardev=usbredirchardev1,id=usbredirdev1",
|
||||||
"-device", "usb-redir,chardev=usbredirchardev2,id=usbredirdev2",
|
"-chardev", "spicevmc,id=usbredirchardev2,name=usbredir",
|
||||||
"-chardev", "spicevmc,id=usbredirchardev3,name=usbredir",
|
"-device", "usb-redir,chardev=usbredirchardev2,id=usbredirdev2",
|
||||||
"-device", "usb-redir,chardev=usbredirchardev3,id=usbredirdev3",
|
"-chardev", "spicevmc,id=usbredirchardev3,name=usbredir",
|
||||||
"-device", "pci-ohci,id=smartpass",
|
"-device", "usb-redir,chardev=usbredirchardev3,id=usbredirdev3",
|
||||||
"-device", "usb-ccid",
|
"-device", "pci-ohci,id=smartpass",
|
||||||
"-chardev", "spicevmc,id=ccid,name=smartcard",
|
"-device", "usb-ccid",
|
||||||
]
|
"-chardev", "spicevmc,id=ccid,name=smartcard",
|
||||||
)
|
]
|
||||||
# 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 = ["qemu"]
|
packages = ["git+https://git.clan.lol/clan/clan-core.git#qemu-wayland"]
|
||||||
if vm.graphics:
|
else:
|
||||||
packages.append("virt-viewer")
|
packages = ["qemu"]
|
||||||
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
remote_viewer_mimetypes = module_root() / "vms" / "mimetypes"
|
if vm.graphics and not vm.wayland:
|
||||||
env[
|
packages.append("virt-viewer")
|
||||||
"XDG_DATA_DIRS"
|
remote_viewer_mimetypes = module_root() / "vms" / "mimetypes"
|
||||||
] = f"{remote_viewer_mimetypes}:{env.get('XDG_DATA_DIRS', '')}"
|
env[
|
||||||
print(env["XDG_DATA_DIRS"])
|
"XDG_DATA_DIRS"
|
||||||
|
] = f"{remote_viewer_mimetypes}:{env.get('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)
|
||||||
|
|||||||
Reference in New Issue
Block a user