From e1e633750ad2edb31b86304efa3151accacf9ffb Mon Sep 17 00:00:00 2001 From: teutat3s Date: Tue, 22 Jun 2021 02:47:43 +0200 Subject: [PATCH] Init ryzensun on Devos --- flake.nix | 1 + hosts/ryzensun/default.nix | 17 +- hosts/ryzensun/hardware-configuration.nix | 35 +++ hosts/ryzensun/ryzensun.nix | 24 ++ hosts/ryzensun/secrets/keyfile.bin | Bin 0 -> 2070 bytes .../virtualisation/create-service.nix | 77 ------ hosts/ryzensun/virtualisation/default.nix | 43 --- .../ryzensun/virtualisation/generate-xml.nix | 246 ------------------ hosts/ryzensun/virtualisation/network-xml.nix | 19 -- 9 files changed, 63 insertions(+), 399 deletions(-) create mode 100644 hosts/ryzensun/hardware-configuration.nix create mode 100644 hosts/ryzensun/ryzensun.nix create mode 100644 hosts/ryzensun/secrets/keyfile.bin delete mode 100644 hosts/ryzensun/virtualisation/create-service.nix delete mode 100644 hosts/ryzensun/virtualisation/default.nix delete mode 100644 hosts/ryzensun/virtualisation/generate-xml.nix delete mode 100644 hosts/ryzensun/virtualisation/network-xml.nix 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 0000000000000000000000000000000000000000..d7efdbee625dd2f5f5bd4ac2b105ccd931e42377 GIT binary patch literal 2070 zcmV+x2r(T$8(C~HjW74f-bH4X}E+zg_E&_ zZO8hZ6TJEuS*jo9+;`)Tk5`*JWYTgD5=MG|ZXM-?-rE5fAu1LTra`#Q0>{pdkP%eW zDQZMrgg7qy0S^D)MMvE%I+WqBn-m41|>p@muhQcf=dNl!%WN~^A<(0IeZ~DYG&)1_#dAt8TY_5}D5wy){sW|V+%6#F!6_$GY_xBqvs3u{R zw5m4~!#PaanouY&uKl1z{IDpwcqo#AQVKuX+T~R+LAsCXlaC*5V8iG0Su04Iyuv1rh&YaLNTF&#l;f9JQ=8rN#hgbw_ouC?panyTfiXV-3TwoLY;F ze5R*^J_NK#9Z+oDwEq#wye#Loq*X6Eh>CToLJ3K6e=6eryX9RwqYjN0=A{L5<3#4r zrDx-xwZea^;27>o)d?RuG8_5%`>!JLp@$S8N8f+U6%~ zAyoJ3Di>#4fYT~o66DHhTW4h-;LWowE-fcOTe_f$B9q*+W^M?7PLyfrvz95^IUM(} zKce%8_p?(MZ|8EfrqHJ!iq4~n_yFw{O=B9rBU>}W7}yV^Dns#U-ZWu8A9 z^xh-&I-af+c(xTg10_zm<4R^;rk^i`l!2TgE`9(JkJv%N`5b=e@>uS>iTll(62MT! z%gaP`*vT&FDT)~+bctYt7g0)B+8w>vJv3X$v$w3;%>aYjafH*mIFwvx~tgFQ0kA4z%?id2H?`@8~%ty7K;(61Uhb38Te6@*j z4H6AF{+&Wv=`;y{4)Id4wZwZ+vXLekNdZn88de``0lep9PoxcctgP@h=wE}H8oa2I z0%`0Hm;TGCRASeHMTDAv=%aCmortR{=_Huih{yuiMk8`Me#D>i?b=lsB0c7x3flJE zJeV$B?J@C!GaTr(g)VQN1i{sI{pVPJKu}sF9Le(5iU=!DPya=CR4Qw6)?{wa*?n)S zoHmm^pS?NDh4#FPJu+*EW%6yO==O@II`UyE1DRLwZy$2oG zrhh=asIM==_94;-psx1=k6;WZmO1{(yhY+dx$wLxR^z?{xDUJ|v3)9KE43(k(0R}t z)xj{3=F<%~{aXbDWr)a0Nr|fU-PK;+A#}Q10Bbqw%xVOug#0YbIv^AACp^F)|ujJhiT~Fm@EG)=o zpOA3b9J|0L)91B0trABha)-}{h>0Dq;`0)Rk{E)f*BXq&vBR6L8_c^3{jTh%=5(-M zQOif3+^e573&x+MV~64)oq0GI>*~^XN28fTj$hn_wqhf1dxV(hsw+$LS+b9=YtK0! z;*SRSFT!Kv87X27?&CKgyQ;$)!_nn`XZ1bqQ(dJcH@4a=wCfcqYglu zNkPItYo92R(z3k_S=DE|2Ue)|scemX`w$7xpAPomnjG4?=VW(R1}?n8Wxh%LYyq`4 z*9~BjC*=)yVTD1oJ5WHv&B9D$nTl@;7BU73XaZT$ED7JdKYA{SJ~!y9{y*D~gDnzJ zUkulE+=#Qj%MF>hh4IgZOr#wfza%=K^kustB7)%?Y5Ms?;V241c-YasVSte$nUe7{ zD{v9Du|tSbgrtZYdBEy~Fewi-#DlRMY!h1g4T<+tm^P_W>QL7ZU~Zs>9SLJhb}8!o AJpcdz literal 0 HcmV?d00001 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 ""} - - - - -
- - - - - - - - - - -
- - - - - - - -