From 3568719372c3458e9e4d9f7ca4991e24cc1327a0 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Sat, 28 Mar 2026 14:21:32 +0100 Subject: [PATCH] feat: nb add epicenter-vm --- hosts/nb/modules/epicenter.nix | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/hosts/nb/modules/epicenter.nix b/hosts/nb/modules/epicenter.nix index 14cb508..7b48969 100644 --- a/hosts/nb/modules/epicenter.nix +++ b/hosts/nb/modules/epicenter.nix @@ -1,5 +1,45 @@ -{ lib, pkgs, ... }: +{ lib, pkgs, ... }: let + epicenter-vm = pkgs.writeShellScriptBin "epicenter-vm" '' + set -euo pipefail + + VM_DIR="$HOME/epicenter-vm" + DISK="$VM_DIR/disk.qcow2" + ISO="" + + while [[ $# -gt 0 ]]; do + case "$1" in + --iso) ISO="$2"; shift 2 ;; + *) echo "Usage: epicenter-vm [--iso /path/to/file.iso]"; exit 1 ;; + esac + done + + # Create disk if it doesn't exist + if [ ! -f "$DISK" ]; then + mkdir -p "$VM_DIR" + ${pkgs.qemu}/bin/qemu-img create -f qcow2 "$DISK" 60G + fi + + QEMU_ARGS=( + -enable-kvm + -m 4G + -smp 2 + -drive "file=$DISK,format=qcow2,if=virtio" + -bios ${pkgs.OVMF.fd}/FV/OVMF.fd + -display gtk,gl=on + -device virtio-vga-gl + -device virtio-net-pci,netdev=net0 + -netdev user,id=net0,hostfwd=tcp::2222-:22 + ) + + # Attach ISO if provided + if [ -n "$ISO" ]; then + QEMU_ARGS+=(-cdrom "$ISO" -boot d) + fi + + exec ${pkgs.qemu}/bin/qemu-system-x86_64 "''${QEMU_ARGS[@]}" + ''; + wrapperScript = pkgs.writeShellScriptBin "rustdesk-epicenter-wrapper" '' # Grant epicenter user access to the Wayland socket ${pkgs.acl}/bin/setfacl -m u:epicenter:x "$XDG_RUNTIME_DIR" @@ -22,6 +62,7 @@ let }; in { environment.systemPackages = [ + epicenter-vm rustdeskEpicenterDesktopItem ];