anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / networking / instant-messengers / discord / linux.nix
blob8d745b0bd81e9161835288f4c69edf65fd31658b
2   pname,
3   version,
4   src,
5   meta,
6   binaryName,
7   desktopName,
8   autoPatchelfHook,
9   makeDesktopItem,
10   lib,
11   stdenv,
12   wrapGAppsHook3,
13   makeShellWrapper,
14   alsa-lib,
15   at-spi2-atk,
16   at-spi2-core,
17   atk,
18   cairo,
19   cups,
20   dbus,
21   expat,
22   fontconfig,
23   freetype,
24   gdk-pixbuf,
25   glib,
26   gtk3,
27   libcxx,
28   libdrm,
29   libglvnd,
30   libnotify,
31   libpulseaudio,
32   libuuid,
33   libX11,
34   libXScrnSaver,
35   libXcomposite,
36   libXcursor,
37   libXdamage,
38   libXext,
39   libXfixes,
40   libXi,
41   libXrandr,
42   libXrender,
43   libXtst,
44   libxcb,
45   libxshmfence,
46   mesa,
47   nspr,
48   nss,
49   pango,
50   systemd,
51   libappindicator-gtk3,
52   libdbusmenu,
53   writeScript,
54   python3,
55   runCommand,
56   libunity,
57   speechd-minimal,
58   wayland,
59   branch,
60   withOpenASAR ? false,
61   openasar,
62   withVencord ? false,
63   vencord,
64   withTTS ? true,
67 let
68   disableBreakingUpdates =
69     runCommand "disable-breaking-updates.py"
70       {
71         pythonInterpreter = "${python3.interpreter}";
72         configDirName = lib.toLower binaryName;
73         meta.mainProgram = "disable-breaking-updates.py";
74       }
75       ''
76         mkdir -p $out/bin
77         cp ${./disable-breaking-updates.py} $out/bin/disable-breaking-updates.py
78         substituteAllInPlace $out/bin/disable-breaking-updates.py
79         chmod +x $out/bin/disable-breaking-updates.py
80       '';
83 stdenv.mkDerivation rec {
84   inherit
85     pname
86     version
87     src
88     meta
89     ;
91   nativeBuildInputs = [
92     alsa-lib
93     autoPatchelfHook
94     cups
95     libdrm
96     libuuid
97     libXdamage
98     libX11
99     libXScrnSaver
100     libXtst
101     libxcb
102     libxshmfence
103     mesa
104     nss
105     wrapGAppsHook3
106     makeShellWrapper
107   ];
109   dontWrapGApps = true;
111   libPath = lib.makeLibraryPath (
112     [
113       libcxx
114       systemd
115       libpulseaudio
116       libdrm
117       mesa
118       stdenv.cc.cc
119       alsa-lib
120       atk
121       at-spi2-atk
122       at-spi2-core
123       cairo
124       cups
125       dbus
126       expat
127       fontconfig
128       freetype
129       gdk-pixbuf
130       glib
131       gtk3
132       libglvnd
133       libnotify
134       libX11
135       libXcomposite
136       libunity
137       libuuid
138       libXcursor
139       libXdamage
140       libXext
141       libXfixes
142       libXi
143       libXrandr
144       libXrender
145       libXtst
146       nspr
147       libxcb
148       pango
149       libXScrnSaver
150       libappindicator-gtk3
151       libdbusmenu
152       wayland
153     ]
154     ++ lib.optional withTTS speechd-minimal
155   );
157   installPhase = ''
158     runHook preInstall
160     mkdir -p $out/{bin,opt/${binaryName},share/pixmaps,share/icons/hicolor/256x256/apps}
161     mv * $out/opt/${binaryName}
163     chmod +x $out/opt/${binaryName}/${binaryName}
164     patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
165         $out/opt/${binaryName}/${binaryName}
167     wrapProgramShell $out/opt/${binaryName}/${binaryName} \
168         "''${gappsWrapperArgs[@]}" \
169         --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform=wayland --enable-features=WaylandWindowDecorations}}" \
170         ${lib.strings.optionalString withTTS "--add-flags \"--enable-speech-dispatcher\""} \
171         --prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
172         --prefix LD_LIBRARY_PATH : ${libPath}:$out/opt/${binaryName} \
173         --run "${lib.getExe disableBreakingUpdates}"
175     ln -s $out/opt/${binaryName}/${binaryName} $out/bin/
176     # Without || true the install would fail on case-insensitive filesystems
177     ln -s $out/opt/${binaryName}/${binaryName} $out/bin/${lib.strings.toLower binaryName} || true
179     ln -s $out/opt/${binaryName}/discord.png $out/share/pixmaps/${pname}.png
180     ln -s $out/opt/${binaryName}/discord.png $out/share/icons/hicolor/256x256/apps/${pname}.png
182     ln -s "$desktopItem/share/applications" $out/share/
184     runHook postInstall
185   '';
187   postInstall =
188     lib.strings.optionalString withOpenASAR ''
189       cp -f ${openasar} $out/opt/${binaryName}/resources/app.asar
190     ''
191     + lib.strings.optionalString withVencord ''
192       mv $out/opt/${binaryName}/resources/app.asar $out/opt/${binaryName}/resources/_app.asar
193       mkdir $out/opt/${binaryName}/resources/app.asar
194       echo '{"name":"discord","main":"index.js"}' > $out/opt/${binaryName}/resources/app.asar/package.json
195       echo 'require("${vencord}/patcher.js")' > $out/opt/${binaryName}/resources/app.asar/index.js
196     '';
198   desktopItem = makeDesktopItem {
199     name = pname;
200     exec = binaryName;
201     icon = pname;
202     inherit desktopName;
203     genericName = meta.description;
204     categories = [
205       "Network"
206       "InstantMessaging"
207     ];
208     mimeTypes = [ "x-scheme-handler/discord" ];
209   };
211   passthru = {
212     # make it possible to run disableBreakingUpdates standalone
213     inherit disableBreakingUpdates;
214     updateScript = writeScript "discord-update-script" ''
215       #!/usr/bin/env nix-shell
216       #!nix-shell -i bash -p curl gnugrep common-updater-scripts
217       set -eou pipefail;
218       url=$(curl -sI -o /dev/null -w '%header{location}' "https://discord.com/api/download/${branch}?platform=linux&format=tar.gz")
219       version=$(echo $url | grep -oP '/\K(\d+\.){2}\d+')
220       update-source-version ${pname} "$version" --file=./pkgs/applications/networking/instant-messengers/discord/default.nix --version-key=${branch}
221     '';
222   };