From 5521adb5ca16a7781f2873078ccf5efc1aee6ea9 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:53:20 +0530 Subject: [PATCH] add amdgpu module --- flake.lock | 12 +++++------ home-manager/cli-tools.nix | 4 +++- modules-overlays/amdgpu.nix | 42 ++++++++++++++++++++++++++++++++++++ modules-overlays/default.nix | 2 +- system/hardware/graphics.nix | 23 ++++++-------------- 5 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 modules-overlays/amdgpu.nix diff --git a/flake.lock b/flake.lock index 826adbe0..44ac3246 100644 --- a/flake.lock +++ b/flake.lock @@ -1186,11 +1186,11 @@ }, "nixpkgs-edge": { "locked": { - "lastModified": 1718430499, - "narHash": "sha256-QpXEMC49h+eo9d1BJKHZt7fzXvApez6GmifNUZRLyTg=", + "lastModified": 1718437601, + "narHash": "sha256-jUNo2eGoQnDIiYfaVRXMMKEGNi0IDrQwF0GoClClQ4k=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4d950563ff9e688764f0b3317e6cbe927b5325a4", + "rev": "da558f2fdc925d3de072e69f26874017556561ad", "type": "github" }, "original": { @@ -1328,11 +1328,11 @@ }, "nur": { "locked": { - "lastModified": 1718429921, - "narHash": "sha256-gWMq/lOBsdMENiH5Ogp5MiHFuXlGI66kcw2v3C/8N5s=", + "lastModified": 1718436390, + "narHash": "sha256-A+U0A8f3fkkv28ZyfaGeCEYPcDEmi82Cic147H6BCXg=", "owner": "nix-community", "repo": "NUR", - "rev": "2b6c40279d293d53714333949aa9dcd40f9acf9d", + "rev": "f9d8781e2581d70f85adb0e67177351c56b6afa8", "type": "github" }, "original": { diff --git a/home-manager/cli-tools.nix b/home-manager/cli-tools.nix index c177e993..577f6274 100644 --- a/home-manager/cli-tools.nix +++ b/home-manager/cli-tools.nix @@ -42,7 +42,9 @@ And scripts may not work the high customised setup programs.zoxide = { enable = true; options = [ - "--cmd cd" # Replace cd with zoxide + # don't enable cd alias, as conflicts may occur sometimes + # you might be redirected to a directory you didn't intend to + # "--cmd cd" # Replace cd with zoxide ]; enableBashIntegration = false; }; diff --git a/modules-overlays/amdgpu.nix b/modules-overlays/amdgpu.nix new file mode 100644 index 00000000..4483eb43 --- /dev/null +++ b/modules-overlays/amdgpu.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.hardware.amdgpu; +in { + options.hardware.amdgpu = { + legacySupport.enable = lib.mkEnableOption ''support for old AMD graphics cards, + this uses `amdgpu` instead of `radeonsi` driver for Southern Islands (Radeon HD 7000) + series and Sea Islands (Radeon HD 7000) series cards. + Note: this does NOT add support for analog video output graphics cards. + ''; + initrd.enable = lib.mkEnableOption ''loading `amdgpu` kernelModule in stage 1. + Enable this to fix lower resolution in boot screen during initramfs phase. + ''; + rocm.enable = lib.mkEnableOption ''ROCm/OpenCL support''; + # cfg.amdvlk option is defined in ./amdvlk.nix module + }; + + config = { + boot.kernelParams = lib.optionals cfg.legacySupport.enable [ + "amdgpu.si_support=1" + "amdgpu.cik_support=1" + "radeon.si_support=0" + "radeon.cik_support=0" + ]; + + boot.initrd.kernelModules = lib.optionals cfg.initrd.enable [ "amdgpu" ]; + + hardware.opengl = lib.mkIf cfg.rocm.enable { + enable = lib.mkDefault true; + driSupport = lib.mkDefault true; + extraPackages = [ + pkgs.rocmPackages.clr + pkgs.rocmPackages.clr.icd + ]; + }; + }; + + meta = { + maintainers = with lib.maintainers; [ johnrtitor ]; + }; +} diff --git a/modules-overlays/default.nix b/modules-overlays/default.nix index 791ebe37..2cccd7b0 100644 --- a/modules-overlays/default.nix +++ b/modules-overlays/default.nix @@ -5,7 +5,7 @@ ... }: { imports = [ - # ./amdvlk.nix - import modules here to test + ./amdgpu.nix # import modules here to test ]; nixpkgs.overlays = [ diff --git a/system/hardware/graphics.nix b/system/hardware/graphics.nix index 8f30f472..925f3d11 100644 --- a/system/hardware/graphics.nix +++ b/system/hardware/graphics.nix @@ -19,8 +19,6 @@ in { # Extra drivers extraPackages = (with pkgs; [ - rocmPackages.clr.icd - amdvlk # AMD Vulkan driver vaapiVdpau libvdpau-va-gl libva @@ -32,7 +30,6 @@ in { ]); # For 32 bit applications extraPackages32 = with pkgs.driversi686Linux; [ - amdvlk vaapiVdpau libvdpau-va-gl ]; @@ -44,6 +41,10 @@ in { vulkan-tools # vulkan graphics library tools ]; + hardware.amdgpu.initrd.enable = true; + hardware.amdgpu.legacySupport.enable = true; + hardware.amdgpu.rocm.enable = true; + hardware.amdgpu.amdvlk = { enable = true; support32Bit.enable = true; @@ -57,19 +58,9 @@ in { }; }; - # Also load amdgpu at stage 1 of boot, to get better resolution - boot.initrd.kernelModules = ["amdgpu"]; - - # AMDGPU graphics driver for Xorg - services.xserver.videoDrivers = ["amdgpu"]; - - # Enable AMDGPU and disable Radeonsi - boot.kernelParams = [ - "amdgpu.si_support=1" - "amdgpu.cik_support=1" - "radeon.si_support=0" - "radeon.cik_support=0" - ]; + # Use modesetting driver for Xorg, its better and updated + # AMDGPU graphics driver for Xorg is deprecated + services.xserver.videoDrivers = ["modesetting"]; # Graphics environment variables environment.sessionVariables = {