diff --git a/flake.nix b/flake.nix index b803eb4..d3ca367 100644 --- a/flake.nix +++ b/flake.nix @@ -115,7 +115,6 @@ ./hosts/monolith.nix ./system/monolith-gitlab-runner.nix ./system/nix-serve.nix - ./system/amdgpu-kernel-patches.nix ] ++ common_modules; }; rainbow = lib.nixosSystem { diff --git a/hosts/monolith.nix b/hosts/monolith.nix index ec3ef6f..03fe339 100644 --- a/hosts/monolith.nix +++ b/hosts/monolith.nix @@ -29,7 +29,13 @@ in # hardware.opengl.extraPackages32 = with pkgs; [ driversi686Linux.amdvlk ]; # environment.variables = { AMD_VULKAN_ICD = "RADV"; }; - boot.extraModulePackages = [ ]; + boot.extraModulePackages = [ + ((pkgs.amdgpu-kernel-module.override { + kernel = config.boot.kernelPackages.kernel; + }).overrideAttrs (_: { + patches = [ ../patches/kernel/amdgpu-disable-shutdown-on-overheating.diff ]; + })) + ]; fileSystems."/" = { device = "/dev/disk/by-label/BTRFS_ROOT"; fsType = "btrfs"; diff --git a/patches/kernel/amdgpu-disable-shutdown-on-overtheating.diff b/patches/kernel/amdgpu-disable-shutdown-on-overheating.diff similarity index 100% rename from patches/kernel/amdgpu-disable-shutdown-on-overtheating.diff rename to patches/kernel/amdgpu-disable-shutdown-on-overheating.diff diff --git a/pkgs/amdgpu-kernel-module.nix b/pkgs/amdgpu-kernel-module.nix new file mode 100644 index 0000000..08d7dd4 --- /dev/null +++ b/pkgs/amdgpu-kernel-module.nix @@ -0,0 +1,38 @@ +{ pkgs +, lib +, kernel ? pkgs.linuxPackages_latest.kernel +}: + +pkgs.stdenv.mkDerivation { + pname = "amdgpu-kernel-module"; + inherit (kernel) src version postPatch nativeBuildInputs; + + kernel_dev = kernel.dev; + kernelVersion = kernel.modDirVersion; + + modulePath = "drivers/gpu/drm/amd/amdgpu"; + + buildPhase = '' + BUILT_KERNEL=$kernel_dev/lib/modules/$kernelVersion/build + + cp $BUILT_KERNEL/Module.symvers . + cp $BUILT_KERNEL/.config . + cp $kernel_dev/vmlinux . + + make "-j$NIX_BUILD_CORES" modules_prepare + make "-j$NIX_BUILD_CORES" M=$modulePath modules + ''; + + installPhase = '' + make \ + INSTALL_MOD_PATH="$out" \ + XZ="xz -T$NIX_BUILD_CORES" \ + M="$modulePath" \ + modules_install + ''; + + meta = { + description = "AMD GPU kernel module"; + license = lib.licenses.gpl3; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index ad777f6..1715cba 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,4 +5,5 @@ plymouth-theme-red = pkgs.callPackage ./plymouth-theme-red.nix { inherit inputs; }; cargo-checkmate = pkgs.callPackage ./cargo-checkmate.nix { }; lipsum = pkgs.callPackage ./lipsum.nix { inherit inputs; }; + amdgpu-kernel-module = pkgs.callPackage ./amdgpu-kernel-module.nix { }; } diff --git a/system/amdgpu-kernel-patches.nix b/system/amdgpu-kernel-patches.nix deleted file mode 100644 index 22e26a3..0000000 --- a/system/amdgpu-kernel-patches.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, pkgs, lib, inputs, ... }: { - # boot.kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; - boot.kernelPatches = [ - { - name = "amdgpu-disable-shutdown-on-overtheating"; - patch = - ../patches/kernel/amdgpu-disable-shutdown-on-overtheating.diff; - } - ]; -}