hibernation works now

This commit is contained in:
Andreas Schaafsma 2024-11-26 14:37:36 +01:00
parent 7645da455e
commit 83db3ded50
10 changed files with 328 additions and 35 deletions

View File

@ -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" ];
};
};
}

View File

@ -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" ];
};
};
}

View File

@ -7,7 +7,7 @@
{ {
imports = imports =
[ [
./hardware-configuration.nix ./hardware/hardware-configuration.nix
]; ];
# Bootloader. # Bootloader.

View File

@ -43,12 +43,12 @@ in
users.users.andreas = { users.users.andreas = {
isNormalUser = true; isNormalUser = true;
description = "Andreas Schaafsma"; description = "Andreas Schaafsma";
extraGroups = [ "networkmanager" "wheel" ]; extraGroups = [ "networkmanager" "wheel" ] ;
packages = with pkgs; [ packages = with pkgs; [
flatpak flatpak
gnome-software gnome-software
soundwireserver soundwireserver
vscode vscode
spotify spotify
appimage-run appimage-run
inputs.game-of-life.packages.x86_64-linux.default inputs.game-of-life.packages.x86_64-linux.default
@ -73,6 +73,7 @@ in
# Or disable the firewall altogether. # Or disable the firewall altogether.
# networking.firewall.enable = false; # networking.firewall.enable = false;
# Install firefox. # Install firefox.
programs.firefox.enable = true; programs.firefox.enable = true;
nixpkgs.config.allowBroken = true; nixpkgs.config.allowBroken = true;
@ -87,8 +88,6 @@ in
pkgs.my-namespace.udev-steelseries pkgs.my-namespace.udev-steelseries
pkgs.my-namespace.hello 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. # stuff I installed to try to get gamescope to work to no avail Gamescope is just broken it seems.
# pkgs.mesa # pkgs.mesa
# pkgs.vulkan-loader # pkgs.vulkan-loader
@ -130,9 +129,9 @@ in
# Disable the GNOME3/GDM auto-suspend feature that cannot be disabled in GUI! # 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. # If no user is logged in, the machine will power down after 20 minutes.
systemd.targets.sleep.enable = false; systemd.targets.sleep.enable = true;
systemd.targets.suspend.enable = false; systemd.targets.suspend.enable = true;
systemd.targets.hibernate.enable = false; systemd.targets.hibernate.enable = true;
systemd.targets.hybrid-sleep.enable = false; systemd.targets.hybrid-sleep.enable = true;
}; };
} }

View File

@ -1,6 +1,6 @@
{ config, lib, pkgs, ... }: { 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 = [ hardware.firmware = [
( (

View File

@ -0,0 +1,10 @@
{ config, lib, pkgs, ... }:
let
inherit (lib.my-namespace) enabled;
in
{
lib.my-namespace.hardware = {
novidia = enabled;
#nvidia-stable.enabled = enabled;
};
}

View File

@ -3,14 +3,14 @@
# Enable OpenGL # Enable OpenGL
hardware.graphics = { hardware.graphics = {
enable = true; enable = true;
extraPackages = with pkgs; [ nvidia-vaapi-driver ]; extraPackages = with pkgs; [ nvidia-vaapi-driver ];
}; };
# Load nvidia driver for Xorg and Wayland # Load nvidia driver for Xorg and Wayland
# boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
# boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ]; boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11_production ];
boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ]; # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
boot.loader.systemd-boot.consoleMode = "max"; boot.loader.systemd-boot.consoleMode = "max";
@ -18,40 +18,72 @@
boot.kernelParams = [ boot.kernelParams = [
"nvidia-drm.fbdev=1" "nvidia-drm.fbdev=1"
"nvidia-drm.modeset=1" "nvidia-drm.modeset=1"
"nvidia.NVreg_PreserveVideoMemoryAllocations=1" # "nvidia.NVreg_PreserveVideoMemoryAllocations=0"
"nomodeset" "amd_iommu=on"
"amdgpu.modeset=1"
# "vfio-pci.ids=\"10de:2489,10de:228b\""
# "nomodeset"
# "nvidia_drm.modeset=1" # "nvidia_drm.modeset=1"
]; ];
boot.blacklistedKernelModules = [ boot.blacklistedKernelModules = [
"i915" "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 = '' boot.extraModprobeConfig = ''
blacklist nouveau blacklist nouveau
options nouveau modeset=0 options nouveau modeset=0
''; '';
services.xserver.videoDrivers = [ "nvidia" ]; # services.xserver.videoDrivers = [ "nvidia" ];
boot.initrd.kernelModules = [ services.xserver.videoDrivers = [ "amdgpu" ];
"nvidia"
"nvidia-drm"
# "nvidiafb"
# "nvidia-modeset"
# "nvidia-uvm"
# "i2c-nvidia_gpu"
];
#boot.initrd.kernelModules = [ "nvidia" ];
# 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 = { hardware.nvidia = {
# Modesetting is required. # Modesetting is required.
modesetting.enable = true; modesetting.enable = false;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail. # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking # 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 # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials. # of just the bare essentials.
powerManagement.enable = false; powerManagement.enable = true;
# Fine-grained power management. Turns off GPU when not in use. # Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer). # Experimental and only works on modern Nvidia GPUs (Turing or newer).
@ -71,8 +103,10 @@
nvidiaSettings = true; nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU. # 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.stable;
# package = config.boot.kernelPackages.nvidiaPackages.production; # package = config.boot.kernelPackages.nvidiaPackages.none;
package = config.boot.kernelPackages.nvidiaPackages.production;
}; };
users.users.andreas = { users.users.andreas = {

View File

@ -4,10 +4,11 @@
{ config, lib, pkgs, modulesPath, ... }: { config, lib, pkgs, modulesPath, ... }:
{ {
imports = imports =
[ [
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
./nvidia.nix ./graphics/nvidia-stable.nix
./graphics/nvidia.nix
./acer-monitor-edid.nix ./acer-monitor-edid.nix
]; ];
#boot.kernelPackages = pkgs.linuxPackages_latest; #boot.kernelPackages = pkgs.linuxPackages_latest;
@ -30,11 +31,21 @@
options = [ "fmask=0077" "dmask=0077" ]; options = [ "fmask=0077" "dmask=0077" ];
}; };
# Try to fix hibernation
# swapDevices = [ ]; # swapDevices = [ ];
swapDevices = [ { swapDevices = [ {
device = "/var/lib/swapfile"; device = "/var/lib/swapfile";
size = 32*1024; 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 # 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 # (the default) this is the recommended approach. When using systemd-networkd it's