Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 replaceVars,
6 makeBinaryWrapper,
7 makeWrapper,
8 makeDesktopItem,
9 copyDesktopItems,
10 vencord,
11 electron,
12 libicns,
13 pipewire,
14 libpulseaudio,
15 autoPatchelfHook,
16 pnpm_10,
17 nodejs,
18 nix-update-script,
19 withTTS ? true,
20 withMiddleClickScroll ? false,
21 # Enables the use of vencord from nixpkgs instead of
22 # letting vesktop manage it's own version
23 withSystemVencord ? false,
24}:
25stdenv.mkDerivation (finalAttrs: {
26 pname = "vesktop";
27 version = "1.5.8";
28
29 src = fetchFromGitHub {
30 owner = "Vencord";
31 repo = "Vesktop";
32 rev = "v${finalAttrs.version}";
33 hash = "sha256-9wYIg1TGcntUMMp6SqYrgDRl3P41eeOqt76OMjSAi5M=";
34 };
35
36 pnpmDeps = pnpm_10.fetchDeps {
37 inherit (finalAttrs)
38 pname
39 version
40 src
41 patches
42 ;
43 fetcherVersion = 2;
44 hash = "sha256-rJzXbIQUxCImTqeH8EsGiyGNGoHYUqoekoa+VXpob5Y=";
45 };
46
47 nativeBuildInputs = [
48 nodejs
49 pnpm_10.configHook
50 ]
51 ++ lib.optionals stdenv.hostPlatform.isLinux [
52 # vesktop uses venmic, which is a shipped as a prebuilt node module
53 # and needs to be patched
54 autoPatchelfHook
55 copyDesktopItems
56 # we use a script wrapper here for environment variable expansion at runtime
57 # https://github.com/NixOS/nixpkgs/issues/172583
58 makeWrapper
59 ]
60 ++ lib.optionals stdenv.hostPlatform.isDarwin [
61 # on macos we don't need to expand variables, so we can use the faster binary wrapper
62 makeBinaryWrapper
63 ];
64
65 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
66 libpulseaudio
67 pipewire
68 (lib.getLib stdenv.cc.cc)
69 ];
70
71 patches = [
72 ./disable_update_checking.patch
73 ./fix_read_only_settings.patch
74 ]
75 ++ lib.optional withSystemVencord (
76 replaceVars ./use_system_vencord.patch {
77 inherit vencord;
78 }
79 );
80
81 env = {
82 ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
83 };
84
85 # disable code signing on macos
86 # https://github.com/electron-userland/electron-builder/blob/77f977435c99247d5db395895618b150f5006e8f/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos
87 postConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
88 export CSC_IDENTITY_AUTO_DISCOVERY=false
89 '';
90
91 # electron builds must be writable on darwin
92 preBuild = lib.optionalString stdenv.hostPlatform.isDarwin ''
93 cp -r ${electron.dist}/Electron.app .
94 chmod -R u+w Electron.app
95 '';
96
97 buildPhase = ''
98 runHook preBuild
99
100 pnpm build
101 pnpm exec electron-builder \
102 --dir \
103 -c.asarUnpack="**/*.node" \
104 -c.electronDist=${if stdenv.hostPlatform.isDarwin then "." else electron.dist} \
105 -c.electronVersion=${electron.version}
106
107 runHook postBuild
108 '';
109
110 postBuild = lib.optionalString stdenv.hostPlatform.isLinux ''
111 pushd build
112 ${libicns}/bin/icns2png -x icon.icns
113 popd
114 '';
115
116 installPhase = ''
117 runHook preInstall
118 ''
119 + lib.optionalString stdenv.hostPlatform.isLinux ''
120 mkdir -p $out/opt/Vesktop
121 cp -r dist/*unpacked/resources $out/opt/Vesktop/
122
123 for file in build/icon_*x32.png; do
124 file_suffix=''${file//build\/icon_}
125 install -Dm0644 $file $out/share/icons/hicolor/''${file_suffix//x32.png}/apps/vesktop.png
126 done
127 ''
128 + lib.optionalString stdenv.hostPlatform.isDarwin ''
129 mkdir -p $out/{Applications,bin}
130 mv dist/mac*/Vesktop.app $out/Applications/Vesktop.app
131 ''
132 + ''
133 runHook postInstall
134 '';
135
136 postFixup =
137 lib.optionalString stdenv.hostPlatform.isLinux ''
138 makeWrapper ${electron}/bin/electron $out/bin/vesktop \
139 --add-flags $out/opt/Vesktop/resources/app.asar \
140 ${lib.strings.optionalString withTTS ''
141 --run 'if [[ "''${NIXOS_SPEECH:-default}" != "False" ]]; then NIXOS_SPEECH=True; else unset NIXOS_SPEECH; fi' \
142 --add-flags "\''${NIXOS_SPEECH:+--enable-speech-dispatcher}" \
143 ''} \
144 ${lib.optionalString withMiddleClickScroll "--add-flags \"--enable-blink-features=MiddleClickAutoscroll\""} \
145 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
146 ''
147 + lib.optionalString stdenv.hostPlatform.isDarwin ''
148 makeWrapper $out/Applications/Vesktop.app/Contents/MacOS/Vesktop $out/bin/vesktop
149 '';
150
151 desktopItems = lib.optional stdenv.hostPlatform.isLinux (makeDesktopItem {
152 name = "vesktop";
153 desktopName = "Vesktop";
154 exec = "vesktop %U";
155 icon = "vesktop";
156 startupWMClass = "Vesktop";
157 genericName = "Internet Messenger";
158 keywords = [
159 "discord"
160 "vencord"
161 "electron"
162 "chat"
163 ];
164 categories = [
165 "Network"
166 "InstantMessaging"
167 "Chat"
168 ];
169 });
170
171 passthru = {
172 inherit (finalAttrs) pnpmDeps;
173 updateScript = nix-update-script { };
174 };
175
176 meta = {
177 description = "Alternate client for Discord with Vencord built-in";
178 homepage = "https://github.com/Vencord/Vesktop";
179 changelog = "https://github.com/Vencord/Vesktop/releases/tag/${finalAttrs.src.rev}";
180 license = lib.licenses.gpl3Only;
181 maintainers = with lib.maintainers; [
182 getchoo
183 Scrumplex
184 vgskye
185 pluiedev
186 ];
187 mainProgram = "vesktop";
188 platforms = [
189 "x86_64-linux"
190 "aarch64-linux"
191 "x86_64-darwin"
192 "aarch64-darwin"
193 ];
194 };
195})