diff --git a/modules/hardware/novidia.nix b/modules/hardware/novidia.nix new file mode 100644 index 0000000..d4219e6 --- /dev/null +++ b/modules/hardware/novidia.nix @@ -0,0 +1,121 @@ +{ pkgs +, config +, lib +, ... +}: +let + inherit (lib) mkEnableOption mkIf; + cfg = config.my-namespace.hardware.novidia; +in +{ + options.my-namespace.hardware.novidia = { + enable = mkEnableOption "Bypass nvidia driver"; + }; + hardware.graphics = mkIf cfg.enable{ + enable = false; + extraPackages = with pkgs; [ nvidia-vaapi-driver ]; + }; + config = mkIf cfg.enable { + # Enable OpenGL + hardware.graphics = { + enable = false; + extraPackages = with pkgs; [ nvidia-vaapi-driver ]; + }; + # Load nvidia driver for Xorg and Wayland + # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; + # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ]; + boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; + + boot.loader.systemd-boot.consoleMode = "max"; + + boot.kernelParams = [ + # "nvidia-drm.fbdev=1" + # "nvidia-drm.modeset=1" + # "nvidia.NVreg_PreserveVideoMemoryAllocations=1" + # "nomodeset" + # "nvidia_drm.modeset=1" + ]; + boot.blacklistedKernelModules = [ + "i915" + "nouveau" + ]; + boot.extraModprobeConfig = '' + blacklist nouveau + options nouveau modeset=0 + ''; + # boot.extraModprobeConfig = "options nvidia " + lib.concatStringsSep " " [ + # # nvidia assume that by default your CPU does not support PAT, + # # but this is effectively never the case in 2023 + # "NVreg_UsePageAttributeTable=1" + # # This may be a noop, but it's somewhat uncertain + # "NVreg_EnablePCIeGen3=1" + # # This is sometimes needed for ddc/ci support, see + # # https://www.ddcutil.com/nvidia/ + # # + # # Current monitor does not support it, but this is useful for + # # the future + # "NVreg_RegistryDwords=RMUseSwI2c=0x01;RMI2cSpeed=100" + # # When (if!) I get another nvidia GPU, check for resizeable bar + # # settings + # ]; + services.xserver.videoDrivers = [ "nvidia" ]; + boot.initrd.kernelModules = [ + # "nvidia" + # "nvidia-drm" + # "nvidiafb" + # "nvidia-modeset" + # "nvidia-uvm" + # "i2c-nvidia_gpu" + ]; + #boot.initrd.kernelModules = [ "nvidia" ]; + + hardware.enableAllFirmware = true; + hardware.nvidia = { + nvidiaPersistenced = true; + # Modesetting is required. + modesetting.enable = true; + + # Nvidia power management. Experimental, and can cause sleep/suspend to fail. + # Enable this if you have graphical corruption issues or application crashes after waking + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # of just the bare essentials. + powerManagement.enable = true; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = false; + + # Use the NVidia open source kernel module (not to be confused with the + # independent third-party "nouveau" open source driver). + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Only available from driver 515.43.04+ + # Currently alpha-quality/buggy, so false is currently the recommended setting. + open = false; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + + # Optionally, you may need to select the appropriate driver version for your specific GPU. + package = config.boot.kernelPackages.nvidiaPackages.stable; + # package = config.boot.kernelPackages.nvidiaPackages.production; + + }; + hardware.nvidia.prime = { + offload = { + enable = true; + enableOffloadCmd = true; + }; + # Make sure to use the correct Bus ID values for your system! + # intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:01:0:0"; + amdgpuBusId = "PCI:50:0:0"; #For AMD GPU + }; + + users.users.andreas = { + extraGroups = [ "video" "render" ]; + }; + }; +} diff --git a/modules/hardware/nvidia-stable.nix b/modules/hardware/nvidia-stable.nix new file mode 100644 index 0000000..5e092b6 --- /dev/null +++ b/modules/hardware/nvidia-stable.nix @@ -0,0 +1,118 @@ +{ pkgs +, config +, lib +, ... +}: +let + inherit (lib) mkEnableOption mkIf; + cfg = config.my-namespace.hardware.nvidia-stable; +in +{ + options.my-namespace.hardware.nvidia-stable = { + enable = mkEnableOption "Enable stable NVIDIA drivers"; + }; + config = mkIf cfg.enable { + # Enable OpenGL + hardware.graphics = { + enable = true; + extraPackages = with pkgs; [ nvidia-vaapi-driver ]; + }; + # Load nvidia driver for Xorg and Wayland + # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; + # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ]; + boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; + + + boot.loader.systemd-boot.consoleMode = "max"; + + boot.kernelParams = [ + "nvidia-drm.fbdev=1" + "nvidia-drm.modeset=1" + "nvidia.NVreg_PreserveVideoMemoryAllocations=1" + "nomodeset" + # "nvidia_drm.modeset=1" + ]; + boot.blacklistedKernelModules = [ + "i915" + "nouveau" + ]; + # boot.extraModprobeConfig = "options nvidia " + lib.concatStringsSep " " [ + # # nvidia assume that by default your CPU does not support PAT, + # # but this is effectively never the case in 2023 + # "NVreg_UsePageAttributeTable=1" + # # This may be a noop, but it's somewhat uncertain + # "NVreg_EnablePCIeGen3=1" + # # This is sometimes needed for ddc/ci support, see + # # https://www.ddcutil.com/nvidia/ + # # + # # Current monitor does not support it, but this is useful for + # # the future + # "NVreg_RegistryDwords=RMUseSwI2c=0x01;RMI2cSpeed=100" + # # When (if!) I get another nvidia GPU, check for resizeable bar + # # settings + # ]; + services.xserver.videoDrivers = [ "nvidia" ]; + boot.initrd.kernelModules = [ + "nvidia" + "nvidia-drm" + # "nvidiafb" + # "nvidia-modeset" + # "nvidia-uvm" + # "i2c-nvidia_gpu" + ]; + #boot.initrd.kernelModules = [ "nvidia" ]; + + hardware.enableAllFirmware = true; + hardware.nvidia = { + nvidiaPersistenced = true; + # Modesetting is required. + modesetting.enable = true; + + # Nvidia power management. Experimental, and can cause sleep/suspend to fail. + # Enable this if you have graphical corruption issues or application crashes after waking + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # of just the bare essentials. + powerManagement.enable = true; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = false; + + # Use the NVidia open source kernel module (not to be confused with the + # independent third-party "nouveau" open source driver). + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Only available from driver 515.43.04+ + # Currently alpha-quality/buggy, so false is currently the recommended setting. + open = false; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + + # Optionally, you may need to select the appropriate driver version for your specific GPU. + package = config.boot.kernelPackages.nvidiaPackages.stable; + # package = config.boot.kernelPackages.nvidiaPackages.production; + + }; + hardware.nvidia.prime = { + offload = { + enable = true; + enableOffloadCmd = true; + }; + # Make sure to use the correct Bus ID values for your system! + # intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:01:0:0"; + amdgpuBusId = "PCI:50:0:0"; #For AMD GPU + }; + + environment.systemPackages = with pkgs [ + pkgs.nvtopPackages.nvidia + ]; + + users.users.andreas = { + extraGroups = [ "video" "render" ]; + }; + }; +} diff --git a/systems/x86_64-linux/drivebystation-nix/configuration.nix b/systems/x86_64-linux/drivebystation-nix/configuration.nix index 8242def..95c55c1 100644 --- a/systems/x86_64-linux/drivebystation-nix/configuration.nix +++ b/systems/x86_64-linux/drivebystation-nix/configuration.nix @@ -7,7 +7,7 @@ { imports = [ - ./hardware-configuration.nix + ./hardware/hardware-configuration.nix ]; # Bootloader. diff --git a/systems/x86_64-linux/drivebystation-nix/default.nix b/systems/x86_64-linux/drivebystation-nix/default.nix index 94f6375..9783edc 100644 --- a/systems/x86_64-linux/drivebystation-nix/default.nix +++ b/systems/x86_64-linux/drivebystation-nix/default.nix @@ -43,12 +43,12 @@ in users.users.andreas = { isNormalUser = true; description = "Andreas Schaafsma"; - extraGroups = [ "networkmanager" "wheel" ]; + extraGroups = [ "networkmanager" "wheel" ] ; packages = with pkgs; [ flatpak gnome-software soundwireserver - vscode + vscode spotify appimage-run inputs.game-of-life.packages.x86_64-linux.default @@ -73,6 +73,7 @@ in # Or disable the firewall altogether. # networking.firewall.enable = false; + # Install firefox. programs.firefox.enable = true; nixpkgs.config.allowBroken = true; @@ -87,8 +88,6 @@ in pkgs.my-namespace.udev-steelseries pkgs.my-namespace.hello - pkgs.nvtopPackages.nvidia - # stuff I installed to try to get gamescope to work to no avail Gamescope is just broken it seems. # pkgs.mesa # pkgs.vulkan-loader @@ -130,9 +129,9 @@ in # Disable the GNOME3/GDM auto-suspend feature that cannot be disabled in GUI! # If no user is logged in, the machine will power down after 20 minutes. - systemd.targets.sleep.enable = false; - systemd.targets.suspend.enable = false; - systemd.targets.hibernate.enable = false; - systemd.targets.hybrid-sleep.enable = false; + systemd.targets.sleep.enable = true; + systemd.targets.suspend.enable = true; + systemd.targets.hibernate.enable = true; + systemd.targets.hybrid-sleep.enable = true; }; } \ No newline at end of file diff --git a/systems/x86_64-linux/drivebystation-nix/acer-monitor-edid.nix b/systems/x86_64-linux/drivebystation-nix/hardware/acer-monitor-edid.nix similarity index 77% rename from systems/x86_64-linux/drivebystation-nix/acer-monitor-edid.nix rename to systems/x86_64-linux/drivebystation-nix/hardware/acer-monitor-edid.nix index 9aa9c5d..abb354d 100644 --- a/systems/x86_64-linux/drivebystation-nix/acer-monitor-edid.nix +++ b/systems/x86_64-linux/drivebystation-nix/hardware/acer-monitor-edid.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, ... }: { - boot.kernelParams = [ "drm.edid_firmware=DP-3:edid/edid.bin" ]; + boot.kernelParams = [ "drm.edid_firmware=DP-6:edid/edid.bin" ]; hardware.firmware = [ ( diff --git a/systems/x86_64-linux/drivebystation-nix/firmware/KG271-edid.bin b/systems/x86_64-linux/drivebystation-nix/hardware/firmware/KG271-edid.bin similarity index 100% rename from systems/x86_64-linux/drivebystation-nix/firmware/KG271-edid.bin rename to systems/x86_64-linux/drivebystation-nix/hardware/firmware/KG271-edid.bin diff --git a/homes/x86_64-linux/andreas@drivebystation-nix/.gitkeep b/systems/x86_64-linux/drivebystation-nix/hardware/graphics/graphics.nix similarity index 100% rename from homes/x86_64-linux/andreas@drivebystation-nix/.gitkeep rename to systems/x86_64-linux/drivebystation-nix/hardware/graphics/graphics.nix diff --git a/systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia-stable.nix b/systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia-stable.nix new file mode 100644 index 0000000..29354e7 --- /dev/null +++ b/systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia-stable.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: +let + inherit (lib.my-namespace) enabled; +in +{ + lib.my-namespace.hardware = { + novidia = enabled; + #nvidia-stable.enabled = enabled; + }; +} diff --git a/systems/x86_64-linux/drivebystation-nix/nvidia.nix b/systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia.nix similarity index 52% rename from systems/x86_64-linux/drivebystation-nix/nvidia.nix rename to systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia.nix index b95a9e0..b851325 100644 --- a/systems/x86_64-linux/drivebystation-nix/nvidia.nix +++ b/systems/x86_64-linux/drivebystation-nix/hardware/graphics/nvidia.nix @@ -3,14 +3,14 @@ # Enable OpenGL hardware.graphics = { - enable = true; + enable = true; extraPackages = with pkgs; [ nvidia-vaapi-driver ]; }; # Load nvidia driver for Xorg and Wayland # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; - # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ]; - boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; + boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ]; + # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; boot.loader.systemd-boot.consoleMode = "max"; @@ -18,40 +18,72 @@ boot.kernelParams = [ "nvidia-drm.fbdev=1" "nvidia-drm.modeset=1" - "nvidia.NVreg_PreserveVideoMemoryAllocations=1" - "nomodeset" + # "nvidia.NVreg_PreserveVideoMemoryAllocations=0" + "amd_iommu=on" + "amdgpu.modeset=1" + # "vfio-pci.ids=\"10de:2489,10de:228b\"" + # "nomodeset" # "nvidia_drm.modeset=1" ]; boot.blacklistedKernelModules = [ "i915" - "amdgpu" - "nouveau" + "nouveau" + # "nvidia" + # "nvidia-drm" + # "nvidia-uvm" + # "nvidiafb" + # "nvidia_drm" + # "nvidia_modeset" ]; + # boot.extraModprobeConfig = '' + # blacklist nvidia + # blacklist nvidia-drm + # blacklist nvidia_drm + # blacklist nvidia-uvm + # blacklist nvidia_uvm + # blacklist nvidia_modeset + # blacklist nvidiafb + # blacklist nouveau + # options nouveau modeset=0 + # ''; boot.extraModprobeConfig = '' blacklist nouveau options nouveau modeset=0 ''; - services.xserver.videoDrivers = [ "nvidia" ]; - boot.initrd.kernelModules = [ - "nvidia" - "nvidia-drm" - # "nvidiafb" - # "nvidia-modeset" - # "nvidia-uvm" - # "i2c-nvidia_gpu" - ]; - #boot.initrd.kernelModules = [ "nvidia" ]; - + # services.xserver.videoDrivers = [ "nvidia" ]; + services.xserver.videoDrivers = [ "amdgpu" ]; + # services.udev.extraRules = '' + # # Remove NVIDIA USB xHCI Host Controller devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{power/control}="auto", ATTR{remove}="1" + # # Remove NVIDIA USB Type-C UCSI devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{power/control}="auto", ATTR{remove}="1" + # # Remove NVIDIA Audio devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{power/control}="auto", ATTR{remove}="1" + # # Remove NVIDIA VGA/3D controller devices + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", ATTR{power/control}="auto", ATTR{remove}="1" + # ''; + + boot.initrd.kernelModules = [ + "amdgpu" + "nvidia_uvm" + "nvidia_drm" + "nvidia" + "nvidia-drm" + "nvidiafb" + "nvidia-modeset" + "nvidia-uvm" + # "i2c-nvidia_gpu" + ]; hardware.nvidia = { # Modesetting is required. - modesetting.enable = true; + modesetting.enable = false; # Nvidia power management. Experimental, and can cause sleep/suspend to fail. # Enable this if you have graphical corruption issues or application crashes after waking # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead # of just the bare essentials. - powerManagement.enable = false; + powerManagement.enable = true; # Fine-grained power management. Turns off GPU when not in use. # Experimental and only works on modern Nvidia GPUs (Turing or newer). @@ -71,8 +103,10 @@ nvidiaSettings = true; # Optionally, you may need to select the appropriate driver version for your specific GPU. - package = config.boot.kernelPackages.nvidiaPackages.stable; - # package = config.boot.kernelPackages.nvidiaPackages.production; + # package = config.boot.kernelPackages.nvidiaPackages.stable; + # package = config.boot.kernelPackages.nvidiaPackages.none; + package = config.boot.kernelPackages.nvidiaPackages.production; + }; users.users.andreas = { diff --git a/systems/x86_64-linux/drivebystation-nix/hardware-configuration.nix b/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix similarity index 80% rename from systems/x86_64-linux/drivebystation-nix/hardware-configuration.nix rename to systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix index 46a23c4..2668ebb 100644 --- a/systems/x86_64-linux/drivebystation-nix/hardware-configuration.nix +++ b/systems/x86_64-linux/drivebystation-nix/hardware/hardware-configuration.nix @@ -4,10 +4,11 @@ { config, lib, pkgs, modulesPath, ... }: { - imports = + imports = [ (modulesPath + "/installer/scan/not-detected.nix") - ./nvidia.nix + ./graphics/nvidia-stable.nix + ./graphics/nvidia.nix ./acer-monitor-edid.nix ]; #boot.kernelPackages = pkgs.linuxPackages_latest; @@ -30,11 +31,21 @@ options = [ "fmask=0077" "dmask=0077" ]; }; + + + # Try to fix hibernation + # swapDevices = [ ]; swapDevices = [ { device = "/var/lib/swapfile"; size = 32*1024; - } ]; + } ]; #resume-offset = 78399488 + boot.resumeDevice = "/dev/disk/by-uuid/563805a1-5277-4488-bbdd-c1a7ed37be76"; # the unlocked drive mapping + boot.kernelParams = [ + "resume_offset=78399488" #sudo filefrag -v /var/lib/swapfile|awk 'NR==4{gsub(/\./,"");print $4;}' + ]; + security.protectKernelImage = false; + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's