From 9884d07e6574ef81e1e7da94f90ee08bee036dd3 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 22 Sep 2024 15:12:25 -0700 Subject: core: move variables and virtualisation to desktop --- modules/core/default.nix | 2 -- modules/core/variables/default.nix | 20 ------------- modules/core/variables/electron.nix | 7 ----- modules/core/variables/fcitx.nix | 13 --------- modules/core/variables/mozilla.nix | 6 ---- modules/core/variables/nvidia.nix | 12 -------- modules/core/variables/opengl.nix | 7 ----- modules/core/variables/qt.nix | 11 ------- modules/core/variables/wayland.nix | 10 ------- modules/core/variables/wlroots.nix | 12 -------- modules/core/virtualisation/default.nix | 14 --------- modules/core/virtualisation/docker.nix | 32 -------------------- modules/core/virtualisation/libvirtd.nix | 15 ---------- modules/core/virtualisation/qemu.nix | 45 ----------------------------- modules/desktop/default.nix | 6 +++- modules/desktop/variables/default.nix | 20 +++++++++++++ modules/desktop/variables/electron.nix | 7 +++++ modules/desktop/variables/fcitx.nix | 13 +++++++++ modules/desktop/variables/mozilla.nix | 6 ++++ modules/desktop/variables/nvidia.nix | 12 ++++++++ modules/desktop/variables/opengl.nix | 7 +++++ modules/desktop/variables/qt.nix | 11 +++++++ modules/desktop/variables/wayland.nix | 10 +++++++ modules/desktop/variables/wlroots.nix | 12 ++++++++ modules/desktop/virtualisation/default.nix | 14 +++++++++ modules/desktop/virtualisation/docker.nix | 32 ++++++++++++++++++++ modules/desktop/virtualisation/libvirtd.nix | 15 ++++++++++ modules/desktop/virtualisation/qemu.nix | 45 +++++++++++++++++++++++++++++ 28 files changed, 209 insertions(+), 207 deletions(-) delete mode 100644 modules/core/variables/default.nix delete mode 100644 modules/core/variables/electron.nix delete mode 100644 modules/core/variables/fcitx.nix delete mode 100644 modules/core/variables/mozilla.nix delete mode 100644 modules/core/variables/nvidia.nix delete mode 100644 modules/core/variables/opengl.nix delete mode 100644 modules/core/variables/qt.nix delete mode 100644 modules/core/variables/wayland.nix delete mode 100644 modules/core/variables/wlroots.nix delete mode 100644 modules/core/virtualisation/default.nix delete mode 100644 modules/core/virtualisation/docker.nix delete mode 100644 modules/core/virtualisation/libvirtd.nix delete mode 100644 modules/core/virtualisation/qemu.nix create mode 100644 modules/desktop/variables/default.nix create mode 100644 modules/desktop/variables/electron.nix create mode 100644 modules/desktop/variables/fcitx.nix create mode 100644 modules/desktop/variables/mozilla.nix create mode 100644 modules/desktop/variables/nvidia.nix create mode 100644 modules/desktop/variables/opengl.nix create mode 100644 modules/desktop/variables/qt.nix create mode 100644 modules/desktop/variables/wayland.nix create mode 100644 modules/desktop/variables/wlroots.nix create mode 100644 modules/desktop/virtualisation/default.nix create mode 100644 modules/desktop/virtualisation/docker.nix create mode 100644 modules/desktop/virtualisation/libvirtd.nix create mode 100644 modules/desktop/virtualisation/qemu.nix (limited to 'modules') diff --git a/modules/core/default.nix b/modules/core/default.nix index 44da8e2..ef9131a 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -5,7 +5,5 @@ ./nix ./security ./software - ./variables - ./virtualisation ]; } diff --git a/modules/core/variables/default.nix b/modules/core/variables/default.nix deleted file mode 100644 index 8315ceb..0000000 --- a/modules/core/variables/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - imports = [ - ./electron.nix - ./fcitx.nix - ./mozilla.nix - ./nvidia.nix - ./opengl.nix - ./qt.nix - ./wayland.nix - ./wlroots.nix - ]; - - environment.variables = { - _JAVA_AWT_WM_NONREPARENTING = "1"; - PROTON_ENABLE_NGX_UPDATER = "1"; - GTK_USE_PORTAL = "1"; - DIRENV_LOG_FORMAT = ""; - SSH_AUTH_SOCK = "/run/user/1000/keyring/ssh"; - }; -} diff --git a/modules/core/variables/electron.nix b/modules/core/variables/electron.nix deleted file mode 100644 index 62e7c72..0000000 --- a/modules/core/variables/electron.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - environment.variables = { - # ELECTRON_OZONE_PLATFORM_HINT = "auto"; - # OZONE_PLATFORM = "wayland"; - NIXOS_OZONE_WL = "1"; - }; -} diff --git a/modules/core/variables/fcitx.nix b/modules/core/variables/fcitx.nix deleted file mode 100644 index 0ac550f..0000000 --- a/modules/core/variables/fcitx.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - environment.variables = { - # https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland - QT_IM_MODULE = "fcitx"; - XMODIFIERS = "@im=fcitx"; - # GTK_IM_MODULE = "wayland"; - # GTK_IM_MODULE = "fcitx"; - SDL_IM_MODULE = "fcitx"; - GLFW_IM_MODULE = "ibus"; - INPUT_METHOD = "fcitx"; - CUDA_CACHE_PATH = "$XDG_CACHE_HOME/nv"; - }; -} diff --git a/modules/core/variables/mozilla.nix b/modules/core/variables/mozilla.nix deleted file mode 100644 index e85d27c..0000000 --- a/modules/core/variables/mozilla.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - environment.variables = { - MOZ_ENABLE_WAYLAND = "1"; - MOZ_DISABLE_RDD_SANDBOX = "1"; - }; -} diff --git a/modules/core/variables/nvidia.nix b/modules/core/variables/nvidia.nix deleted file mode 100644 index 3d50fdf..0000000 --- a/modules/core/variables/nvidia.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs, ... }: -{ - environment.variables = { - LIBVA_DRIVER_NAME = "nvidia"; - __GLX_VENDOR_LIBRARY_NAME = "nvidia"; - GBM_BACKEND = "nvidia-drm"; - __VK_LAYER_NV_optimus = "NVIDIA_only"; - __NV_PRIME_RENDER_OFFLOAD = "1"; - NVD_BACKEND = "direct"; - CUDA_PATH = "${pkgs.cudatoolkit}"; - }; -} diff --git a/modules/core/variables/opengl.nix b/modules/core/variables/opengl.nix deleted file mode 100644 index 1edce45..0000000 --- a/modules/core/variables/opengl.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - environment.variables = { - __GL_GSYNC_ALLOWED = "1"; - __GL_VRR_ALLOWED = "0"; - __GL_MaxFramesAllowed = "1"; - }; -} diff --git a/modules/core/variables/qt.nix b/modules/core/variables/qt.nix deleted file mode 100644 index cedf6a0..0000000 --- a/modules/core/variables/qt.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - environment.variables = { - QT_AUTO_SCREEN_SCALE_FACTOR = "1"; - QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; - QT_QPA_PLATFORM = "wayland;xcb"; - DISABLE_QT5_COMPAT = "0"; - DISABLE_QT_COMPAT = "0"; - QT_QPA_PLATFORMTHEME = "qt5ct"; - # QT_STYLE_OVERRIDE = "kvantum"; - }; -} diff --git a/modules/core/variables/wayland.nix b/modules/core/variables/wayland.nix deleted file mode 100644 index ee21d52..0000000 --- a/modules/core/variables/wayland.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ - environment.variables = { - GDK_BACKEND = "wayland,x11,*"; - SDL_VIDEODRIVER = "wayland"; - CLUTTER_BACKEND = "wayland"; - XWAYLAND_NO_GLAMOR = "0"; # Gamescope - ANKI_WAYLAND = "1"; - XDG_SESSION_TYPE = "wayland"; - }; -} diff --git a/modules/core/variables/wlroots.nix b/modules/core/variables/wlroots.nix deleted file mode 100644 index 25aaf4d..0000000 --- a/modules/core/variables/wlroots.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - environment.variables = { - WLR_NO_HARDWARE_CURSORS = "1"; - WLR_DRM_NO_ATOMIC = "1"; - WLR_USE_LIBINPUT = "1"; - WLR_RENDERER_ALLOW_SOFTWARE = "1"; - WLR_DRM_DEVICES = "/dev/dri/card0"; - WLR_EGL_NO_MODIFIERS = "1"; - WLR_BACKEND = "vulkan"; - WLR_RENDERER = "vulkan"; - }; -} diff --git a/modules/core/virtualisation/default.nix b/modules/core/virtualisation/default.nix deleted file mode 100644 index 97aa4b9..0000000 --- a/modules/core/virtualisation/default.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - imports = [ - ./docker.nix - ./libvirtd.nix - ./qemu.nix - ]; - - programs.extra-container.enable = true; - - virtualisation = { - kvmgt.enable = true; - spiceUSBRedirection.enable = true; - }; -} diff --git a/modules/core/virtualisation/docker.nix b/modules/core/virtualisation/docker.nix deleted file mode 100644 index c35beb6..0000000 --- a/modules/core/virtualisation/docker.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, ... }: -{ - virtualisation.docker = { - enable = true; - storageDriver = "overlay2"; - enableOnBoot = false; - liveRestore = true; - enableNvidia = lib.mkForce true; - - daemon.settings = { - default-runtime = "nvidia"; - experimental = true; - iptables = false; - }; - - autoPrune = { - enable = true; - dates = "daily"; - }; - - rootless = { - enable = false; - setSocketVariable = true; - - daemon.settings = { - default-runtime = "nvidia"; - experimental = true; - iptables = false; - }; - }; - }; -} diff --git a/modules/core/virtualisation/libvirtd.nix b/modules/core/virtualisation/libvirtd.nix deleted file mode 100644 index 556135b..0000000 --- a/modules/core/virtualisation/libvirtd.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs, ... }: -{ - boot.extraModprobeConfig = "options kvm_intel nested=1"; - - environment.systemPackages = with pkgs; [ - virt-manager - virt-viewer - ]; - - virtualisation.libvirtd = { - enable = true; - onBoot = "ignore"; - onShutdown = "shutdown"; - }; -} diff --git a/modules/core/virtualisation/qemu.nix b/modules/core/virtualisation/qemu.nix deleted file mode 100644 index 849ead1..0000000 --- a/modules/core/virtualisation/qemu.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ pkgs, ... }: -{ - environment.systemPackages = with pkgs; [ - qemu_kvm - qemu - ]; - - hardware.pulseaudio.extraConfig = '' - load-module module-native-protocol-unix auth-group=qemu-libvirtd socket=/tmp/pulse-socket - ''; - - boot.kernelModules = [ "vfio-pci" ]; - - networking.firewall.trustedInterfaces = [ - "virbr0" - "br0" - ]; - - services.udev.extraRules = '' - SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm" - ''; - - virtualisation.libvirtd.qemu = { - package = pkgs.qemu_kvm; - runAsRoot = true; - swtpm.enable = true; - - ovmf = { - enable = true; - - packages = [ - (pkgs.OVMFFull.override { - secureBoot = true; - tpmSupport = true; - }).fd - ]; - }; - - verbatimConfig = '' - namespaces = [] - - dynamic_ownership = 0 - ''; - }; -} diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index f20e009..e4fe30d 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -1,6 +1,10 @@ { config, ... }: { - imports = [ ./networking ]; + imports = [ + ./networking + ./variables + ./virtualisation + ]; sops.defaultSopsFile = ../../secrets/${config.networking.hostName}.yaml; } diff --git a/modules/desktop/variables/default.nix b/modules/desktop/variables/default.nix new file mode 100644 index 0000000..8315ceb --- /dev/null +++ b/modules/desktop/variables/default.nix @@ -0,0 +1,20 @@ +{ + imports = [ + ./electron.nix + ./fcitx.nix + ./mozilla.nix + ./nvidia.nix + ./opengl.nix + ./qt.nix + ./wayland.nix + ./wlroots.nix + ]; + + environment.variables = { + _JAVA_AWT_WM_NONREPARENTING = "1"; + PROTON_ENABLE_NGX_UPDATER = "1"; + GTK_USE_PORTAL = "1"; + DIRENV_LOG_FORMAT = ""; + SSH_AUTH_SOCK = "/run/user/1000/keyring/ssh"; + }; +} diff --git a/modules/desktop/variables/electron.nix b/modules/desktop/variables/electron.nix new file mode 100644 index 0000000..62e7c72 --- /dev/null +++ b/modules/desktop/variables/electron.nix @@ -0,0 +1,7 @@ +{ + environment.variables = { + # ELECTRON_OZONE_PLATFORM_HINT = "auto"; + # OZONE_PLATFORM = "wayland"; + NIXOS_OZONE_WL = "1"; + }; +} diff --git a/modules/desktop/variables/fcitx.nix b/modules/desktop/variables/fcitx.nix new file mode 100644 index 0000000..0ac550f --- /dev/null +++ b/modules/desktop/variables/fcitx.nix @@ -0,0 +1,13 @@ +{ + environment.variables = { + # https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland + QT_IM_MODULE = "fcitx"; + XMODIFIERS = "@im=fcitx"; + # GTK_IM_MODULE = "wayland"; + # GTK_IM_MODULE = "fcitx"; + SDL_IM_MODULE = "fcitx"; + GLFW_IM_MODULE = "ibus"; + INPUT_METHOD = "fcitx"; + CUDA_CACHE_PATH = "$XDG_CACHE_HOME/nv"; + }; +} diff --git a/modules/desktop/variables/mozilla.nix b/modules/desktop/variables/mozilla.nix new file mode 100644 index 0000000..e85d27c --- /dev/null +++ b/modules/desktop/variables/mozilla.nix @@ -0,0 +1,6 @@ +{ + environment.variables = { + MOZ_ENABLE_WAYLAND = "1"; + MOZ_DISABLE_RDD_SANDBOX = "1"; + }; +} diff --git a/modules/desktop/variables/nvidia.nix b/modules/desktop/variables/nvidia.nix new file mode 100644 index 0000000..3d50fdf --- /dev/null +++ b/modules/desktop/variables/nvidia.nix @@ -0,0 +1,12 @@ +{ pkgs, ... }: +{ + environment.variables = { + LIBVA_DRIVER_NAME = "nvidia"; + __GLX_VENDOR_LIBRARY_NAME = "nvidia"; + GBM_BACKEND = "nvidia-drm"; + __VK_LAYER_NV_optimus = "NVIDIA_only"; + __NV_PRIME_RENDER_OFFLOAD = "1"; + NVD_BACKEND = "direct"; + CUDA_PATH = "${pkgs.cudatoolkit}"; + }; +} diff --git a/modules/desktop/variables/opengl.nix b/modules/desktop/variables/opengl.nix new file mode 100644 index 0000000..1edce45 --- /dev/null +++ b/modules/desktop/variables/opengl.nix @@ -0,0 +1,7 @@ +{ + environment.variables = { + __GL_GSYNC_ALLOWED = "1"; + __GL_VRR_ALLOWED = "0"; + __GL_MaxFramesAllowed = "1"; + }; +} diff --git a/modules/desktop/variables/qt.nix b/modules/desktop/variables/qt.nix new file mode 100644 index 0000000..cedf6a0 --- /dev/null +++ b/modules/desktop/variables/qt.nix @@ -0,0 +1,11 @@ +{ + environment.variables = { + QT_AUTO_SCREEN_SCALE_FACTOR = "1"; + QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; + QT_QPA_PLATFORM = "wayland;xcb"; + DISABLE_QT5_COMPAT = "0"; + DISABLE_QT_COMPAT = "0"; + QT_QPA_PLATFORMTHEME = "qt5ct"; + # QT_STYLE_OVERRIDE = "kvantum"; + }; +} diff --git a/modules/desktop/variables/wayland.nix b/modules/desktop/variables/wayland.nix new file mode 100644 index 0000000..ee21d52 --- /dev/null +++ b/modules/desktop/variables/wayland.nix @@ -0,0 +1,10 @@ +{ + environment.variables = { + GDK_BACKEND = "wayland,x11,*"; + SDL_VIDEODRIVER = "wayland"; + CLUTTER_BACKEND = "wayland"; + XWAYLAND_NO_GLAMOR = "0"; # Gamescope + ANKI_WAYLAND = "1"; + XDG_SESSION_TYPE = "wayland"; + }; +} diff --git a/modules/desktop/variables/wlroots.nix b/modules/desktop/variables/wlroots.nix new file mode 100644 index 0000000..25aaf4d --- /dev/null +++ b/modules/desktop/variables/wlroots.nix @@ -0,0 +1,12 @@ +{ + environment.variables = { + WLR_NO_HARDWARE_CURSORS = "1"; + WLR_DRM_NO_ATOMIC = "1"; + WLR_USE_LIBINPUT = "1"; + WLR_RENDERER_ALLOW_SOFTWARE = "1"; + WLR_DRM_DEVICES = "/dev/dri/card0"; + WLR_EGL_NO_MODIFIERS = "1"; + WLR_BACKEND = "vulkan"; + WLR_RENDERER = "vulkan"; + }; +} diff --git a/modules/desktop/virtualisation/default.nix b/modules/desktop/virtualisation/default.nix new file mode 100644 index 0000000..97aa4b9 --- /dev/null +++ b/modules/desktop/virtualisation/default.nix @@ -0,0 +1,14 @@ +{ + imports = [ + ./docker.nix + ./libvirtd.nix + ./qemu.nix + ]; + + programs.extra-container.enable = true; + + virtualisation = { + kvmgt.enable = true; + spiceUSBRedirection.enable = true; + }; +} diff --git a/modules/desktop/virtualisation/docker.nix b/modules/desktop/virtualisation/docker.nix new file mode 100644 index 0000000..c35beb6 --- /dev/null +++ b/modules/desktop/virtualisation/docker.nix @@ -0,0 +1,32 @@ +{ lib, ... }: +{ + virtualisation.docker = { + enable = true; + storageDriver = "overlay2"; + enableOnBoot = false; + liveRestore = true; + enableNvidia = lib.mkForce true; + + daemon.settings = { + default-runtime = "nvidia"; + experimental = true; + iptables = false; + }; + + autoPrune = { + enable = true; + dates = "daily"; + }; + + rootless = { + enable = false; + setSocketVariable = true; + + daemon.settings = { + default-runtime = "nvidia"; + experimental = true; + iptables = false; + }; + }; + }; +} diff --git a/modules/desktop/virtualisation/libvirtd.nix b/modules/desktop/virtualisation/libvirtd.nix new file mode 100644 index 0000000..556135b --- /dev/null +++ b/modules/desktop/virtualisation/libvirtd.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: +{ + boot.extraModprobeConfig = "options kvm_intel nested=1"; + + environment.systemPackages = with pkgs; [ + virt-manager + virt-viewer + ]; + + virtualisation.libvirtd = { + enable = true; + onBoot = "ignore"; + onShutdown = "shutdown"; + }; +} diff --git a/modules/desktop/virtualisation/qemu.nix b/modules/desktop/virtualisation/qemu.nix new file mode 100644 index 0000000..849ead1 --- /dev/null +++ b/modules/desktop/virtualisation/qemu.nix @@ -0,0 +1,45 @@ +{ pkgs, ... }: +{ + environment.systemPackages = with pkgs; [ + qemu_kvm + qemu + ]; + + hardware.pulseaudio.extraConfig = '' + load-module module-native-protocol-unix auth-group=qemu-libvirtd socket=/tmp/pulse-socket + ''; + + boot.kernelModules = [ "vfio-pci" ]; + + networking.firewall.trustedInterfaces = [ + "virbr0" + "br0" + ]; + + services.udev.extraRules = '' + SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm" + ''; + + virtualisation.libvirtd.qemu = { + package = pkgs.qemu_kvm; + runAsRoot = true; + swtpm.enable = true; + + ovmf = { + enable = true; + + packages = [ + (pkgs.OVMFFull.override { + secureBoot = true; + tpmSupport = true; + }).fd + ]; + }; + + verbatimConfig = '' + namespaces = [] + + dynamic_ownership = 0 + ''; + }; +} -- cgit v1.2.3