nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 69 lines 1.9 kB view raw
1{ lib, stdenv, fetchFromGitHub, fetchpatch, kernel, runtimeShell }: 2 3let 4 baseName = "bbswitch"; 5 version = "0.8"; 6 name = "${baseName}-${version}-${kernel.version}"; 7 8in 9 10stdenv.mkDerivation { 11 inherit name; 12 13 src = fetchFromGitHub { 14 owner = "Bumblebee-Project"; 15 repo = "bbswitch"; 16 rev = "v${version}"; 17 hash = "sha256-FHC8myKnouNDERVds2QCJj1ZstjHrOzFpb+FDiSBjL4="; 18 }; 19 20 patches = [ 21 (fetchpatch { 22 url = "https://github.com/Bumblebee-Project/bbswitch/pull/102.patch"; 23 sha256 = "1lbr6pyyby4k9rn2ry5qc38kc738d0442jhhq57vmdjb6hxjya7m"; 24 }) 25 (fetchpatch { 26 url = "https://github.com/Bumblebee-Project/bbswitch/pull/196.patch"; 27 sha256 = "02ihy3piws7783qbm9q0mb9s18ipn5ckdy1iar74xn31qjrsn99n"; 28 }) 29 ]; 30 31 nativeBuildInputs = kernel.moduleBuildDependencies; 32 33 hardeningDisable = [ "pic" ]; 34 35 preBuild = '' 36 substituteInPlace Makefile \ 37 --replace "\$(shell uname -r)" "${kernel.modDirVersion}" \ 38 --replace "/lib/modules" "${kernel.dev}/lib/modules" 39 ''; 40 41 makeFlags = kernel.makeFlags; 42 43 installPhase = '' 44 mkdir -p $out/lib/modules/${kernel.modDirVersion}/misc 45 cp bbswitch.ko $out/lib/modules/${kernel.modDirVersion}/misc 46 47 mkdir -p $out/bin 48 tee $out/bin/discrete_vga_poweroff << EOF 49 #!${runtimeShell} 50 51 echo -n OFF > /proc/acpi/bbswitch 52 EOF 53 tee $out/bin/discrete_vga_poweron << EOF 54 #!${runtimeShell} 55 56 echo -n ON > /proc/acpi/bbswitch 57 EOF 58 chmod +x $out/bin/discrete_vga_poweroff $out/bin/discrete_vga_poweron 59 ''; 60 61 meta = with lib; { 62 description = "A module for powering off hybrid GPUs"; 63 platforms = [ "x86_64-linux" "i686-linux" ]; 64 homepage = "https://github.com/Bumblebee-Project/bbswitch"; 65 maintainers = with maintainers; [ abbradar ]; 66 license = licenses.gpl2Plus; 67 broken = kernel.kernelAtLeast "5.18"; 68 }; 69}