vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / pkgs / os-specific / linux / bbswitch / default.nix
bloba65bcab50ee25f80d0d39c1c8a3994ea44dc3938
1 { lib, stdenv, fetchFromGitHub, fetchpatch, kernel, runtimeShell }:
3 let
4   baseName = "bbswitch";
5   version = "unstable-2021-11-29";
6   name = "${baseName}-${version}-${kernel.version}";
8 in
10 stdenv.mkDerivation {
11   inherit name;
13   src = fetchFromGitHub {
14     owner = "Bumblebee-Project";
15     repo = "bbswitch";
16     # https://github.com/Bumblebee-Project/bbswitch/tree/develop
17     rev = "23891174a80ea79c7720bcc7048a5c2bfcde5cd9";
18     hash = "sha256-50v1Jxem5kaI1dHOKmgBbPLxI82QeYxiaRHhrHpWRzU=";
19   };
21   patches = [
22     (fetchpatch {
23       url = "https://raw.githubusercontent.com/archlinux/svntogit-community/0bd986055ba52887b81048de5c61e618eec06eb0/trunk/0003-kernel-5.18.patch";
24       sha256 = "sha256-va62/bR1qyBBMPg0lUwCH7slGG0XijxVCsFa4FCoHEQ=";
25     })
26   ];
28   nativeBuildInputs = kernel.moduleBuildDependencies;
30   hardeningDisable = [ "pic" ];
32   preBuild = ''
33     substituteInPlace Makefile \
34       --replace "/lib/modules" "${kernel.dev}/lib/modules"
35   '';
37   makeFlags = kernel.makeFlags;
39   installPhase = ''
40     mkdir -p $out/lib/modules/${kernel.modDirVersion}/misc
41     cp bbswitch.ko $out/lib/modules/${kernel.modDirVersion}/misc
43     mkdir -p $out/bin
44     tee $out/bin/discrete_vga_poweroff << EOF
45     #!${runtimeShell}
47     echo -n OFF > /proc/acpi/bbswitch
48     EOF
49     tee $out/bin/discrete_vga_poweron << EOF
50     #!${runtimeShell}
52     echo -n ON > /proc/acpi/bbswitch
53     EOF
54     chmod +x $out/bin/discrete_vga_poweroff $out/bin/discrete_vga_poweron
55   '';
57   meta = with lib; {
58     description = "Module for powering off hybrid GPUs";
59     platforms = [ "x86_64-linux" "i686-linux" ];
60     homepage = "https://github.com/Bumblebee-Project/bbswitch";
61     maintainers = with maintainers; [ abbradar ];
62     license = licenses.gpl2Plus;
63   };