From 86970a7f6c15e9a6fb361ee54d5d766c34bf28e2 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 23 Dec 2024 15:35:36 -0500 Subject: [PATCH] updated modules to work for cloud --- flake.lock | 13 +-- flake.nix | 2 +- modules/apps/flatpak.nix | 10 -- modules/apps/gaming.nix | 49 +++------ modules/graphics/default.nix | 135 ++++++++++++++++++------ modules/machine/cloud/configuration.nix | 55 ++++++---- modules/networking/core.nix | 27 +++-- modules/pwrMgmt/default.nix | 12 +-- modules/sound/shairport.nix | 2 +- modules/virtualization/podman.nix | 4 +- 10 files changed, 178 insertions(+), 131 deletions(-) diff --git a/flake.lock b/flake.lock index 8f97c01..b5e0cf8 100644 --- a/flake.lock +++ b/flake.lock @@ -28,15 +28,16 @@ ] }, "locked": { - "lastModified": 1734344598, - "narHash": "sha256-wNX3hsScqDdqKWOO87wETUEi7a/QlPVgpC/Lh5rFOuA=", + "lastModified": 1734366194, + "narHash": "sha256-vykpJ1xsdkv0j8WOVXrRFHUAdp9NXHpxdnn1F4pYgSw=", "owner": "nix-community", "repo": "home-manager", - "rev": "83ecd50915a09dca928971139d3a102377a8d242", + "rev": "80b0fdf483c5d1cb75aaad909bd390d48673857f", "type": "github" }, "original": { "owner": "nix-community", + "ref": "release-24.11", "repo": "home-manager", "type": "github" } @@ -93,11 +94,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1734323986, - "narHash": "sha256-m/lh6hYMIWDYHCAsn81CDAiXoT3gmxXI9J987W5tZrE=", + "lastModified": 1734737257, + "narHash": "sha256-GIMyMt1pkkoXdCq9un859bX6YQZ/iYtukb9R5luazLM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "394571358ce82dff7411395829aa6a3aad45b907", + "rev": "1c6e20d41d6a9c1d737945962160e8571df55daa", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c82c021..63300fe 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ nix-flatpak.url = "github:gmodena/nix-flatpak/?ref=v0.4.1"; nix-ld.url = "github:Mic92/nix-ld"; home-manager = { - url = "github:nix-community/home-manager"; + url = "github:nix-community/home-manager/release-24.11"; inputs.nixpkgs.follows = "nixpkgs"; }; darwin = { diff --git a/modules/apps/flatpak.nix b/modules/apps/flatpak.nix index 16782c8..f6191fe 100644 --- a/modules/apps/flatpak.nix +++ b/modules/apps/flatpak.nix @@ -16,16 +16,6 @@ } ] else flatpakRemotes; - # packages = [ - # "com.github.tchx84.Flatseal" - # "com.slack.Slack" - # "info.beyondallreason.bar" - # "io.dbeaver.DBeaverCommunity" - # "io.openrct2.OpenRCT2" - # "md.obsidian.Obsidian" - # "org.prismlauncher.PrismLauncher" - # "sh.cider.Cider" - # ]; packages = flatpakPackages; update = { auto = { diff --git a/modules/apps/gaming.nix b/modules/apps/gaming.nix index d7efb49..534b4e5 100644 --- a/modules/apps/gaming.nix +++ b/modules/apps/gaming.nix @@ -71,15 +71,10 @@ in { }; wine = { - enable = lib.mkOption { - type = lib.types.bool; - default = true; - description = "Enable Wine support for Lutris"; - }; - + enable = lib.mkEnableOption "Enable Wine support for Lutris"; package = lib.mkOption { type = lib.types.package; - default = pkgs.wineWow; + default = pkgs.wine-staging; description = "Wine package to use with Lutris"; }; }; @@ -107,10 +102,10 @@ in { }; }; - minecraft = lib.mkOption { + minecraft = { enable = lib.mkEnableOption "Minecraft in the form of PrismLauncher, a tool for launching Minecraft"; }; - ffxiv = lib.mkOption { + ffxiv = { enable = lib.mkEnableOption "Final Fantasy XIV and it's accompanied (unofficial) launcher"; }; }; @@ -145,36 +140,20 @@ in { }; environment.systemPackages = - lib.mkIf cfg.lutris.enable ( - # Base Lutris package - [cfg.lutris.package] - ++ - # Wine packages if enabled + (lib.optionals cfg.lutris.enable ( + [cfg.lutris.package] ++ (lib.optionals cfg.lutris.wine.enable [ cfg.lutris.wine.package pkgs.winetricks - ]) - ++ - # Proton and compatibility tools + ]) ++ (lib.optionals cfg.lutris.compatibility.protonSupport [ - pkgs.proton-ge-custom - ]) - ++ - # Extra compatibility tools - cfg.lutris.compatibility.extraTools - ++ - # User-specified extra packages + pkgs.protonup-ng + pkgs.protonup-qt + ]) ++ + cfg.lutris.compatibility.extraTools ++ cfg.lutris.extraPackages - ) - lib.mkIf - cfg.minecraft.enable [pkgs.prismlauncher] - lib.mkIf - cfg.ffxiv.enable [pkgs.xivlauncher]; - - # Wine configuration - programs.wine = lib.mkIf (cfg.lutris.enable && cfg.lutris.wine.enable) { - enable = true; - package = cfg.lutris.wine.package; - }; + )) ++ + (lib.optionals cfg.minecraft.enable [pkgs.prismlauncher]) ++ + (lib.optionals cfg.ffxiv.enable [pkgs.xivlauncher]); }; } diff --git a/modules/graphics/default.nix b/modules/graphics/default.nix index 62b4668..75ca407 100644 --- a/modules/graphics/default.nix +++ b/modules/graphics/default.nix @@ -1,42 +1,107 @@ { - pkgs, - lib, config, + lib, + pkgs, ... -}: { - nixosModules.gpuHardware = {gpuVendor ? null, ...}: { - hardware.opengl = { - # Always enable OpenGL support - enable = true; +}: +with lib; let + cfg = config.graphics; +in { + options.graphics = { + gpuVendor = mkOption { + type = types.enum ["nvidia" "amd" "intel" "none"]; + default = "none"; + description = "GPU vendor to configure graphics drivers for"; + }; - # Dynamically select packages based on GPU vendor - extraPackages = with pkgs; ( - # Base packages that are always included - [ - mesa - libvdpau-va-gl - libva - libva-utils - ] - # Vendor-specific packages - ++ ( - if gpuVendor == "intel" - then [ - intel-vaapi-driver - intel-media-driver - ] - else if gpuVendor == "amd" - then [ - rocm-opencl-icd - ] - else if gpuVendor == "nvidia" - then [ - # Add Nvidia-specific packages if needed - nvidia-vaapi-driver - ] - else [] - ) - ); + enable = mkEnableOption "graphics configuration"; + + wayland = { + enable = mkEnableOption "Wayland support"; + + variableRefreshRate = mkOption { + type = types.bool; + default = false; + description = "Enable variable refresh rate (FreeSync/G-Sync) support"; + }; + }; + + vulkan = { + enable = mkEnableOption "Vulkan support"; + + debug = mkOption { + type = types.bool; + default = false; + description = "Enable Vulkan validation layers"; + }; }; }; + + config = mkIf cfg.enable (mkMerge [ + { + environment.systemPackages = with pkgs; [ + glxinfo + vulkan-tools + mesa-demos + ]; + } + + (mkIf (cfg.gpuVendor == "nvidia") { + services.xserver.videoDrivers = ["nvidia"]; + hardware.nvidia = { + package = config.boot.kernelPackages.nvidiaPackages.stable; + open = true; + modesetting.enable = true; + powerManagement.enable = true; + }; + environment.systemPackages = with pkgs; [ + nvidia-vaapi-driver + nvtopPackages.full + ]; + }) + + (mkIf (cfg.gpuVendor == "amd") { + services.xserver.videoDrivers = ["amdgpu"]; + hardware.opengl.extraPackages = with pkgs; [ + rocm-opencl-icd + rocm-opencl-runtime + amdvlk + ]; + environment.systemPackages = with pkgs; [ + radeontop + ]; + }) + + (mkIf (cfg.gpuVendor == "intel") { + services.xserver.videoDrivers = ["modesetting"]; + hardware.opengl.extraPackages = with pkgs; [ + intel-media-driver + intel-compute-runtime + ]; + }) + + (mkIf cfg.wayland.enable { + programs.xwayland.enable = true; + environment.sessionVariables = { + MOZ_ENABLE_WAYLAND = "1"; + QT_QPA_PLATFORM = "wayland"; + SDL_VIDEODRIVER = "wayland"; + }; + }) + + (mkIf cfg.vulkan.enable { + environment.systemPackages = with pkgs; + [ + vulkan-loader + vulkan-validation-layers + ] + ++ ( + if cfg.vulkan.debug + then [ + vulkan-tools + ] + else [] + ); + }) + ]); } diff --git a/modules/machine/cloud/configuration.nix b/modules/machine/cloud/configuration.nix index 85913ee..df3b495 100644 --- a/modules/machine/cloud/configuration.nix +++ b/modules/machine/cloud/configuration.nix @@ -1,17 +1,32 @@ { config, + lib, pkgs, userName, ... -}: { +}: + let flatpakPackages = [ + "com.github.tchx84.Flatseal" + "com.slack.Slack" + "info.beyondallreason.bar" + "io.dbeaver.DBeaverCommunity" + "io.openrct2.OpenRCT2" + "md.obsidian.Obsidian" + "org.prismlauncher.PrismLauncher" + "sh.cider.Cider" + ]; +in { imports = [ - ../../apps/flatpak.nix + (import ../../apps/flatpak.nix { + inherit lib pkgs flatpakPackages; + }) + ../../apps/gaming.nix + ../../graphics ../../pwrMgmt ../../sound/pipewire.nix ../../sound/shairport.nix ../../virtualization/podman.nix ../../virtualization/hardware.nix - (config.nixosModules.gpuHardware {gpuVendor = "amd";}) ]; # Enable flakes for NixOS @@ -68,8 +83,15 @@ # Enable Polkit security.polkit.enable = true; + graphics = { + enable = true; + gpuVendor = "nvidia"; # or "amd" or "intel" + wayland.enable = true; + vulkan.enable = true; + }; + # Gaming module (see ../../apps/gaming.nix) - customGaming = { + gaming = { steam = { enable = true; firewall = { @@ -83,13 +105,10 @@ enable = true; wine = { enable = true; - package = pkgs.wine; + package = pkgs.wine-staging; }; compatibility = { protonSupport = true; - extraTools = with pkgs; [ - proton-ge-custom - ]; }; extraPackages = with pkgs; [ gamemode @@ -97,17 +116,18 @@ ]; }; + ffxiv.enable = true; minecraft.enable = true; }; # Power management (see ../../pwrMgmt/default.nix) - customPowerManagement = { + pwrMgmt = { enable = true; cpuFreqGovernor = "performance"; powertop.enable = false; }; - containers.podman = { + podman = { enable = true; extraPackages = with pkgs; [ docker-credential-helpers @@ -119,9 +139,9 @@ ]; }; - customNetworking = { + networking = { firewall.enable = true; - networkManager.enable = true; + networkmanager.enable = true; }; # Enable dconf @@ -130,6 +150,9 @@ # Add username to groups "wheel" and "video" - more may be added here later users.users.${userName}.extraGroups = ["wheel" "video" "gamemode" "podman" "network"]; + # Flatpak packages (see ../../apps/flatpak.nix) + services.flatpak.packages = flatpakPackages; + # XDG stuff xdg = { portal = { @@ -150,11 +173,5 @@ }; }; - # Firewall stuff not allowed in common user and network creation - networking.firewall.enable = true; # VERY important, do not touch - networking.firewall.allowedTCPPorts = []; - networking.firewall.allowedUDPPorts = []; - networking.networkmanager.enable = true; # Linux tool for managing network connections - - system.stateVersion = "24.05"; + system.stateVersion = "24.11"; } diff --git a/modules/networking/core.nix b/modules/networking/core.nix index c7e0500..98d8ef1 100644 --- a/modules/networking/core.nix +++ b/modules/networking/core.nix @@ -1,15 +1,14 @@ { config, lib, - pkgs, ... }: let - cfg = config.customNetworking; + cfg = config.networking; in { - options.customNetworking = { + options.networking = { # Firewall Configuration firewall = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = true; description = "Enable system firewall"; @@ -18,49 +17,49 @@ in { tcpPorts = { # Predefined, default common service ports ssh = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open SSH service port (22)"; }; }; web = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open common web service ports (80, 443)"; }; }; smtp = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open SMTP service ports (25, 465, 587)"; }; }; imap = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open IMAP service ports (143, 993)"; }; }; mysql = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open MySQL service port (3306)"; }; }; mssql = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open Microsoft SQL Server service port (1433)"; }; }; postgres = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open Postgres service port (5432)"; @@ -75,14 +74,14 @@ in { udpPorts = { dns = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open DNS service port (53)"; }; }; ntp = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = false; description = "Open NTP service port (123)"; @@ -97,7 +96,7 @@ in { }; networkManager = { - enable = lib.mkOption { + enable = lib.mkEnableOption { type = lib.types.bool; default = true; description = "Enable NetworkManager for network connection management"; diff --git a/modules/pwrMgmt/default.nix b/modules/pwrMgmt/default.nix index 8a9f2b9..f460b20 100644 --- a/modules/pwrMgmt/default.nix +++ b/modules/pwrMgmt/default.nix @@ -1,15 +1,13 @@ { config, lib, + pkgs, ... }: let - # Define a more flexible power management module - cfg = config.pwrMgnt; + cfg = config.pwrMgmt; in { - # Define options for customizable power management - options.pwrMgnt = { + options.pwrMgmt = { enable = lib.mkEnableOption "Custom power management configuration"; - cpuFreqGovernor = lib.mkOption { type = lib.types.enum [ "performance" @@ -21,7 +19,6 @@ in { description = "CPU frequency scaling governor to use"; }; - # PowerTop Configuration powertop = { enable = lib.mkEnableOption "PowerTop power management tool"; @@ -32,7 +29,6 @@ in { }; }; - # Battery-specific settings (for laptops) battery = { enable = lib.mkEnableOption "Battery-specific power management"; @@ -56,7 +52,7 @@ in { cpuFreqGovernor = cfg.cpuFreqGovernor; }; - services.powertop.enable = cfg.powertop.enable; + environment.systemPackages = lib.mkIf cfg.powertop.enable [pkgs.powertop]; systemd.services.battery-charge-threshold = lib.mkIf cfg.battery.enable { description = "Set battery charge thresholds"; wantedBy = ["multi-user.target"]; diff --git a/modules/sound/shairport.nix b/modules/sound/shairport.nix index a81d82f..58843cd 100644 --- a/modules/sound/shairport.nix +++ b/modules/sound/shairport.nix @@ -1,4 +1,4 @@ -{pkgs}: { +{pkgs, ...}: { services.shairport-sync = { enable = pkgs.stdenv.isLinux; openFirewall = pkgs.stdenv.isLinux; diff --git a/modules/virtualization/podman.nix b/modules/virtualization/podman.nix index 44ee576..9dc8589 100644 --- a/modules/virtualization/podman.nix +++ b/modules/virtualization/podman.nix @@ -4,9 +4,9 @@ pkgs, ... }: let - cfg = config.containers.podman; + cfg = config.podman; in { - options.containers = { + options = { podman = { enable = lib.mkEnableOption "Podman container runtime";