diff --git a/flake.nix b/flake.nix index 0269457c..85a8bad3 100644 --- a/flake.nix +++ b/flake.nix @@ -107,6 +107,7 @@ teutat3s = pubsolaros ++ [ users.teutat3s ]; con = teutat3s ++ [ graphical ]; dumpyourvms = teutat3s ++ [ graphical ]; + ryzensun = teutat3s ++ [ graphical ]; }; }; }; diff --git a/hosts/ryzensun/default.nix b/hosts/ryzensun/default.nix index 56fe0a2f..3629e651 100644 --- a/hosts/ryzensun/default.nix +++ b/hosts/ryzensun/default.nix @@ -1,17 +1,6 @@ -{ config, pkgs, lib, ... }: -with lib; -let - psCfg = config.pub-solar; - xdg = config.home-manager.users."${psCfg.user.name}".xdg; -in +{ suites, ... }: { imports = [ - ./virtualisation - ]; - - config.home-manager.users."${psCfg.user.name}".xdg.configFile = mkIf psCfg.sway.enable { - "sway/config.d/autostart.conf".source = ./.config/sway/config.d/autostart.conf; - "sway/config.d/input-defaults.conf".source = ./.config/sway/config.d/input-defaults.conf; - "sway/config.d/screens.conf".source = ./.config/sway/config.d/screens.conf; - }; + ./ryzensun.nix + ] ++ suites.ryzensun; } diff --git a/hosts/ryzensun/hardware-configuration.nix b/hosts/ryzensun/hardware-configuration.nix new file mode 100644 index 00000000..53490312 --- /dev/null +++ b/hosts/ryzensun/hardware-configuration.nix @@ -0,0 +1,35 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "sd_mod" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { + device = "/dev/disk/by-uuid/bad2e49e-c8e7-4516-a6f8-77db999d12b0"; + fsType = "ext4"; + }; + + boot.initrd.luks.devices."cryptroot".device = "/dev/disk/by-uuid/ef6c5bb0-0bcf-4af4-bbc9-02c849999e54"; + + fileSystems."/boot/efi" = + { + device = "/dev/disk/by-uuid/2C62-C8B5"; + fsType = "vfat"; + }; + + swapDevices = [ ]; + + # high-resolution display + hardware.video.hidpi.enable = lib.mkDefault true; +} diff --git a/hosts/ryzensun/ryzensun.nix b/hosts/ryzensun/ryzensun.nix new file mode 100644 index 00000000..c047774a --- /dev/null +++ b/hosts/ryzensun/ryzensun.nix @@ -0,0 +1,24 @@ +{ config, pkgs, lib, ... }: +with lib; +let + psCfg = config.pub-solar; + xdg = config.home-manager.users."${psCfg.user.name}".xdg; +in +{ + imports = [ + ./hardware-configuration.nix + ]; + + config = { + pub-solar.x-os.keyfile = "/etc/nixos/hosts/con/secrets/keyfile.bin"; + pub-solar.nextcloud.enable = mkForce false; + pub-solar.docker.enable = mkForce false; + pub-solar.virtualisation.enable = true; + + home-manager.users."${psCfg.user.name}".xdg.configFile = mkIf psCfg.sway.enable { + "sway/config.d/autostart.conf".source = ./.config/sway/config.d/autostart.conf; + "sway/config.d/input-defaults.conf".source = ./.config/sway/config.d/input-defaults.conf; + "sway/config.d/screens.conf".source = ./.config/sway/config.d/screens.conf; + }; + }; +} diff --git a/hosts/ryzensun/secrets/keyfile.bin b/hosts/ryzensun/secrets/keyfile.bin new file mode 100644 index 00000000..d7efdbee Binary files /dev/null and b/hosts/ryzensun/secrets/keyfile.bin differ diff --git a/hosts/ryzensun/virtualisation/create-service.nix b/hosts/ryzensun/virtualisation/create-service.nix deleted file mode 100644 index df7453f1..00000000 --- a/hosts/ryzensun/virtualisation/create-service.nix +++ /dev/null @@ -1,77 +0,0 @@ -{ config, pkgs, lib, vm, ... }: -let - psCfg = config.pub-solar; - xdg = config.home-manager.users."${psCfg.user.name}".xdg; - varsFile = "${xdg.dataHome}/libvirt/OVMF_VARS_${vm.name}.fd"; - generateXML = import ./generate-xml.nix; -in -{ - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = "yes"; - Restart = "no"; - }; - - script = - let - networkXML = pkgs.writeText "network.xml" (import ./network-xml.nix { inherit config; inherit pkgs; inherit lib; }); - machineXML = pkgs.writeText "${vm.name}.xml" (generateXML { inherit config; inherit pkgs; inherit lib; inherit vm; varsFile = varsFile; }); - in - '' - echo "Checking if ${vm.name} is already running" - if [[ $(${pkgs.libvirt}/bin/virsh list --all | grep "${vm.name}" | ${pkgs.gawk}/bin/awk '{ print $3 " " $4 }' ) != 'shut off' ]]; then - echo "Domain ${vm.name} is already running or in an inconsistent state:" - ${pkgs.libvirt}/bin/virsh list --all - exit 0 - fi - - NET_TMP_FILE="/tmp/network.xml" - - NETUUID="$(${pkgs.libvirt}/bin/virsh net-uuid 'default' || true)" - (sed "s/UUID/$NETUUID/" '${networkXML}') > $NET_TMP_FILE - - ${pkgs.libvirt}/bin/virsh net-define $NET_TMP_FILE - ${pkgs.libvirt}/bin/virsh net-start 'default' || true - - VARS_FILE=${varsFile} - if [ ! -f "$VARS_FILE" ]; then - cp /run/libvirt/nix-ovmf/OVMF_VARS.fd $VARS_FILE - fi - - TMP_FILE="/tmp/${vm.name}.xml" - - UUID="$(${pkgs.libvirt}/bin/virsh domuuid '${vm.name}' || true)" - (sed "s/UUID/$UUID/" '${machineXML}') > $TMP_FILE - - USB_DEV=$(${pkgs.usbutils}/bin/lsusb | grep 046d:c52b | grep 'Bus 001' | cut -b 18) - LINE_NUMBER=$(cat $TMP_FILE | grep -n -A 1 0xc52b | tail -n 1 | cut -b 1,2,3) - sed -i "''${LINE_NUMBER}s/\(.\{33\}\)./\1''${USB_DEV}/" $TMP_FILE - - USB_BUS=$(${pkgs.usbutils}/bin/lsusb | grep 046d:c328 | cut -b 7) - USB_DEV=$(${pkgs.usbutils}/bin/lsusb | grep 046d:c328 | cut -b 18) - LINE_NUMBER=$(cat $TMP_FILE | grep -n -A 1 0xc328 | tail -n 1 | cut -b 1,2,3) - sed -i "''${LINE_NUMBER}s/.*/
/" $TMP_FILE - - # TODO: Set correct pci address too - - ${pkgs.libvirt}/bin/virsh define $TMP_FILE - ${pkgs.libvirt}/bin/virsh start '${vm.name}' - ''; - - preStop = - '' - ${pkgs.libvirt}/bin/virsh shutdown '${vm.name}' - let "timeout = $(date +%s) + 10" - while [ "$(${pkgs.libvirt}/bin/virsh list --name | grep --count '^${vm.name}$')" -gt 0 ]; do - if [ "$(date +%s)" -ge "$timeout" ]; then - # Meh, we warned it... - ${pkgs.libvirt}/bin/virsh destroy '${vm.name}' - else - # The machine is still running, let's give it some time to shut down - sleep 0.5 - fi - done - - ${pkgs.libvirt}/bin/virsh net-destroy 'default' || true - ''; -} diff --git a/hosts/ryzensun/virtualisation/default.nix b/hosts/ryzensun/virtualisation/default.nix deleted file mode 100644 index e44fdb08..00000000 --- a/hosts/ryzensun/virtualisation/default.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ config, pkgs, lib, ... }: -with lib; -let - psCfg = config.pub-solar; - xdg = config.home-manager.users."${psCfg.user.name}".xdg; - createService = import ./create-service.nix; -in -{ - options.pub-solar.virtualisation.rx5700xt = mkEnableOption "Use the bigger GPU for guests"; - - config = mkIf psCfg.virtualisation.enable { - boot.extraModprobeConfig = "softdep amdgpu pre: vfio vfio_pci" + (if psCfg.virtualisation.rx5700xt - then "\noptions vfio-pci ids=1002:731f,1002:ab38" - else "\noptions vfio-pci ids=1002:699f,1002:aae0"); - - systemd.user.services = { - vm-windows = createService { - inherit config; - inherit pkgs; - inherit lib; - vm = { - name = "windows"; - disk = "/dev/disk/by-id/ata-SanDisk_SDSSDA240G_162402455603"; - id = "http://microsoft.com/win/10"; - gpu = true; - mountHome = false; - }; - }; - vm-manjaro = createService { - inherit config; - inherit pkgs; - inherit lib; - vm = { - name = "manjaro"; - disk = "/dev/disk/by-id/ata-KINGSTON_SM2280S3G2240G_50026B726B0265CE"; - id = "https://manjaro.org/download/#i3"; - gpu = true; - mountHome = true; - }; - }; - }; - }; -} diff --git a/hosts/ryzensun/virtualisation/generate-xml.nix b/hosts/ryzensun/virtualisation/generate-xml.nix deleted file mode 100644 index 6ec49bc5..00000000 --- a/hosts/ryzensun/virtualisation/generate-xml.nix +++ /dev/null @@ -1,246 +0,0 @@ -{ config, pkgs, lib, vm, varsFile, ... }: -let - psCfg = config.pub-solar; - xdg = config.home-manager.users."${psCfg.user.name}".xdg; - home = config.home-manager.users."${psCfg.user.name}".home; -in -'' - - ${vm.name} - UUID - - - - - - 33554432 - 33554432 - 12 - - - - - - - - - - - - - - - - /machine - - - hvm - /run/libvirt/nix-ovmf/OVMF_CODE.fd - ${varsFile} - - - - - - - - - - - - - - - - - - EPYC-IBPB - AMD - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - destroy - restart - destroy - - - - - - ${pkgs.qemu}/bin/qemu-system-x86_64 - - - - - -
- - -
- - -
- - - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - -
- - - - -
- - -
- - ${if vm.mountHome then '' - - - -
- - '' else ""} - - - - -
- - - - - - - - - - -
- - - - - - - -