about summary refs log tree commit diff
path: root/pkgs/os-specific/linux/nvidia-x11/settings.nix
blob: a26acd144125cd22aa7bfcd7115b4962b9f2dd30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
nvidia_x11: sha256:

{ stdenv
, lib
, fetchFromGitHub
, fetchpatch
, pkg-config
, m4
, jansson
, gtk2
, dbus
, gtk3
, libXv
, libXrandr
, libXext
, libXxf86vm
, libvdpau
, librsvg
, wrapGAppsHook3
, addOpenGLRunpath
, withGtk2 ? false
, withGtk3 ? true
}:

let
  src = fetchFromGitHub {
    owner = "NVIDIA";
    repo = "nvidia-settings";
    rev = nvidia_x11.settingsVersion;
    inherit sha256;
  };

  meta = with lib; {
    homepage = "https://www.nvidia.com/object/unix.html";
    platforms = nvidia_x11.meta.platforms;
    maintainers = with maintainers; [ abbradar aidalgol ];
  };

  libXNVCtrl = stdenv.mkDerivation {
    pname = "libXNVCtrl";
    version = nvidia_x11.settingsVersion;
    inherit src;

    buildInputs = [ libXrandr libXext ];

    preBuild = ''
      cd src/libXNVCtrl
    '';

    makeFlags = [
      "OUTPUTDIR=." # src/libXNVCtrl
      "libXNVCtrl.a"
      "libXNVCtrl.so"
    ];

    patches = [
      # Patch the Makefile to also produce a shared library.
      (if lib.versionOlder nvidia_x11.settingsVersion "400" then ./libxnvctrl-build-shared-3xx.patch
      else ./libxnvctrl-build-shared.patch)
    ];

    installPhase = ''
      mkdir -p $out/lib
      mkdir -p $out/include/NVCtrl

      cp libXNVCtrl.a $out/lib
      cp NVCtrl.h     $out/include/NVCtrl
      cp NVCtrlLib.h  $out/include/NVCtrl
      cp -P libXNVCtrl.so* $out/lib
    '';

    meta = meta // {
      description = "NVIDIA NV-CONTROL X extension";
      # https://github.com/NVIDIA/nvidia-settings/commit/edcf9edad9f52f9b10e63d4480bbe88b22dde884
      license = lib.licenses.mit;
    };
  };

in

stdenv.mkDerivation {
  pname = "nvidia-settings";
  version = nvidia_x11.settingsVersion;

  inherit src;

  patches = lib.optional (lib.versionOlder nvidia_x11.settingsVersion "440")
    (fetchpatch {
      # fixes "multiple definition of `VDPAUDeviceFunctions'" linking errors
      url = "https://github.com/NVIDIA/nvidia-settings/commit/a7c1f5fce6303a643fadff7d85d59934bd0cf6b6.patch";
      hash = "sha256-ZwF3dRTYt/hO8ELg9weoz1U/XcU93qiJL2d1aq1Jlak=";
    })
  ++ lib.optional
    ((lib.versionAtLeast nvidia_x11.settingsVersion "515.43.04")
      && (lib.versionOlder nvidia_x11.settingsVersion "545.29"))
    (fetchpatch {
      # fix wayland support for compositors that use wl_output version 4
      url = "https://github.com/NVIDIA/nvidia-settings/pull/99/commits/2e0575197e2b3247deafd2a48f45afc038939a06.patch";
      hash = "sha256-wKuO5CUTUuwYvsP46Pz+6fI0yxLNpZv8qlbL0TFkEFE=";
    });

  postPatch = lib.optionalString nvidia_x11.useProfiles ''
    sed -i 's,/usr/share/nvidia/,${nvidia_x11.bin}/share/nvidia/,g' src/gtk+-2.x/ctkappprofile.c
  '';

  enableParallelBuilding = true;
  makeFlags = [ "NV_USE_BUNDLED_LIBJANSSON=0" ];

  preBuild = ''
    if [ -e src/libXNVCtrl/libXNVCtrl.a ]; then
      ( cd src/libXNVCtrl
        make $makeFlags
      )
    fi
  '';

  nativeBuildInputs = [ pkg-config m4 addOpenGLRunpath ]
    ++ lib.optionals withGtk3 [ wrapGAppsHook3 ];

  buildInputs = [ jansson libXv libXrandr libXext libXxf86vm libvdpau nvidia_x11 dbus ]
    ++ lib.optionals (withGtk2 || lib.versionOlder nvidia_x11.settingsVersion "525.53") [ gtk2 ]
    ++ lib.optionals withGtk3 [ gtk3 librsvg ];

  installFlags = [ "PREFIX=$(out)" ];

  postInstall = lib.optionalString (!withGtk2) ''
    rm -f $out/lib/libnvidia-gtk2.so.*
  '' + lib.optionalString (!withGtk3) ''
    rm -f $out/lib/libnvidia-gtk3.so.*
  '' + ''
    # Install the desktop file and icon.
    # The template has substitution variables intended to be replaced resulting
    # in absolute paths. Because absolute paths break after the desktop file is
    # copied by a desktop environment, make Exec and Icon be just a name.
    sed -i doc/nvidia-settings.desktop \
      -e "s|^Exec=.*$|Exec=nvidia-settings|" \
      -e "s|^Icon=.*$|Icon=nvidia-settings|" \
      -e "s|__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__|Settings|g"
    install doc/nvidia-settings.desktop -D -t $out/share/applications/
    install doc/nvidia-settings.png -D -t $out/share/icons/hicolor/128x128/apps/
  '';

  binaryName = if withGtk3 then ".nvidia-settings-wrapped" else "nvidia-settings";
  postFixup = ''
    patchelf --set-rpath "$(patchelf --print-rpath $out/bin/$binaryName):$out/lib:${libXv}/lib" \
      $out/bin/$binaryName

    addOpenGLRunpath $out/bin/$binaryName
  '';

  passthru = {
    inherit libXNVCtrl;
  };

  meta = meta // {
    description = "Settings application for NVIDIA graphics cards";
    # nvml.h is licensed as part of the cuda developer license.
    license = lib.licenses.unfreeRedistributable;
    mainProgram = "nvidia-settings";
  };
}