nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 clangStdenv,
4 cargo,
5 copyDesktopItems,
6 fetchFromGitHub,
7 flutter329,
8 ffmpeg_7,
9 gst_all_1,
10 fuse3,
11 libXtst,
12 libaom,
13 libopus,
14 libpulseaudio,
15 libva,
16 libvdpau,
17 libvpx,
18 libxkbcommon,
19 libyuv,
20 pam,
21 makeDesktopItem,
22 rustPlatform,
23 libayatana-appindicator,
24 rustc,
25 rustfmt,
26 xdotool,
27 xdg-user-dirs,
28 pipewire,
29 cargo-expand,
30 yq,
31 callPackage,
32 addDriverRunpath,
33 perl,
34 openssl,
35}:
36let
37 flutterRustBridge = rustPlatform.buildRustPackage rec {
38 pname = "flutter_rust_bridge_codegen";
39 version = "1.80.1"; # https://github.com/rustdesk/rustdesk/blob/1.4.4/.github/workflows/bridge.yml#L10
40
41 src = fetchFromGitHub {
42 owner = "fzyzcjy";
43 repo = "flutter_rust_bridge";
44 rev = "v${version}";
45 hash = "sha256-SbwqWapJbt6+RoqRKi+wkSH1D+Wz7JmnVbfcfKkjt8Q=";
46 };
47
48 patches = [
49 ./update-flutter-dev-path.patch
50 ];
51
52 cargoHash = "sha256-4khuq/DK4sP98AMHyr/lEo1OJdqLujOIi8IgbKBY60Y=";
53 cargoBuildFlags = [
54 "--package"
55 "flutter_rust_bridge_codegen"
56 ];
57 doCheck = false;
58 };
59
60 ffigen = callPackage ./ffigen {
61 flutter = flutter329;
62 };
63
64 sharedLibraryExt = rustc.stdenv.hostPlatform.extensions.sharedLibrary;
65
66in
67flutter329.buildFlutterApplication rec {
68 pname = "rustdesk";
69 version = "1.4.4";
70
71 src = fetchFromGitHub {
72 owner = "rustdesk";
73 repo = "rustdesk";
74 tag = version;
75 fetchSubmodules = true;
76 hash = "sha256-o7jsVWiCkHaKFpAu27r/Lr1Q9g7uR/OYJdwsiQeDJUA=";
77 };
78
79 strictDeps = true;
80 env.VCPKG_ROOT = "/homeless-shelter"; # idk man, makes the build go since https://github.com/21pages/hwcodec/commit/1873c34e3da070a462540f61c0b782b7ab15dc84
81 env.OPENSSL_NO_VENDOR = true;
82
83 # Configure the Flutter/Dart build
84 sourceRoot = "${src.name}/flutter";
85 # curl https://raw.githubusercontent.com/rustdesk/rustdesk/1.4.1/flutter/pubspec.lock | yq > pubspec.lock.json
86 pubspecLock = lib.importJSON ./pubspec.lock.json;
87 gitHashes = lib.importJSON ./git-hashes.json;
88
89 # Configure the Rust build
90 cargoRoot = "..";
91 cargoDeps = rustPlatform.fetchCargoVendor {
92 inherit
93 pname
94 version
95 src
96 patches
97 ;
98 hash = "sha256-gd2vS+p+1QtOWZcRWJWahFGo5rFG+soqxx3vJYSYJUo=";
99 };
100
101 dontCargoBuild = true;
102 cargoBuildFlags = "--lib";
103 cargoBuildType = "release";
104 cargoBuildFeatures = [
105 "flutter"
106 "hwcodec"
107 "linux-pkg-config"
108 ];
109
110 nativeBuildInputs = [
111 # flutter_rust_bridge_codegen
112 cargo
113 copyDesktopItems
114 rustfmt
115 # Rust
116 rustPlatform.cargoSetupHook
117 rustPlatform.cargoBuildHook
118 cargo-expand
119 rustPlatform.bindgenHook
120 ffigen
121 yq
122 perl
123 ];
124
125 buildInputs = [
126 ffmpeg_7
127 fuse3
128 gst_all_1.gst-plugins-base
129 gst_all_1.gstreamer
130 libXtst
131 libaom
132 libopus
133 libpulseaudio
134 libva
135 libvdpau
136 libvpx
137 pipewire
138 libxkbcommon
139 libyuv
140 pam
141 xdotool
142 openssl
143 ];
144
145 prePatch = ''
146 chmod -R +w ..
147 cd ..
148 '';
149
150 patches = [
151 ./make-build-reproducible.patch
152 ];
153
154 prepareBuildRunner = ''
155 cp ${./build-runner.sh} build_runner
156 substituteInPlace build_runner \
157 --replace-fail "@bash@" "$SHELL"
158 chmod +x build_runner
159 export PATH=$PATH:$PWD
160 '';
161
162 postPatch = ''
163 cd flutter
164 if [ $cargoDepsCopy ]; then # That will be inherited to buildDartPackage and it doesn't have cargoDepsCopy
165 substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
166 --replace-fail "libayatana-appindicator3.so.1" "${lib.getLib libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
167 # Disable static linking of ffmpeg since https://github.com/21pages/hwcodec/commit/1873c34e3da070a462540f61c0b782b7ab15dc84
168 sed -i 's/static=//g' $cargoDepsCopy/hwcodec-*/build.rs
169 sed -e '1i #include <cstdint>' -i $cargoDepsCopy/webm-1.1.0/src/sys/libwebm/mkvparser/mkvparser.cc
170 sed -e '1i #include <cstdint>' -i $cargoDepsCopy/webm-sys-1.0.4/libwebm/mkvparser/mkvparser.cc
171 fi
172
173 substituteInPlace ../Cargo.toml --replace-fail ", \"staticlib\", \"rlib\"" ""
174 '';
175
176 preBuild = ''
177 # Build the Flutter/Rust bridge bindings
178 cat <<EOF > bridge.yml
179 rust_input:
180 - "../src/flutter_ffi.rs"
181 dart_output:
182 - "./lib/generated_bridge.dart"
183 llvm_path:
184 - "${lib.getLib clangStdenv.cc.cc}"
185 dart_format_line_length: 80
186 llvm_compiler_opts: "-I ${lib.getLib clangStdenv.cc.cc}/lib/clang/${lib.versions.major clangStdenv.cc.version}/include -I ${clangStdenv.cc.libc_dev}/include"
187 EOF
188 runHook prepareBuildRunner
189 RUST_LOG=info ${flutterRustBridge}/bin/flutter_rust_bridge_codegen bridge.yml
190
191 # Build the Rust shared library
192 cd ..
193 preBuild=() # prevent loops
194 cargoBuildHook
195 mv ./target/*/release/liblibrustdesk${sharedLibraryExt} ./target/release/liblibrustdesk${sharedLibraryExt}
196 cd flutter
197 '';
198
199 postInstall = ''
200 mkdir -p $out/share/polkit-1/actions $out/share/icons/hicolor/{256x256,scalable}/apps
201 cp ../res/128x128@2x.png $out/share/icons/hicolor/256x256/apps/rustdesk.png
202 cp ../res/scalable.svg $out/share/icons/hicolor/scalable/apps/rustdesk.svg
203 '';
204
205 extraWrapProgramArgs = ''
206 --prefix LD_LIBRARY_PATH : ${addDriverRunpath.driverLink}/lib \
207 --prefix PATH : ${lib.makeBinPath [ xdg-user-dirs ]}
208 '';
209
210 desktopItems = [
211 (makeDesktopItem {
212 name = "rustdesk";
213 desktopName = "RustDesk";
214 genericName = "Remote Desktop";
215 comment = "Remote Desktop";
216 exec = "rustdesk %u";
217 icon = "rustdesk";
218 terminal = false;
219 type = "Application";
220 startupNotify = true;
221 categories = [
222 "Network"
223 "RemoteAccess"
224 "GTK"
225 ];
226 keywords = [ "internet" ];
227 actions.new-window = {
228 name = "Open a New Window";
229 exec = "rustdesk %u";
230 };
231 })
232 (makeDesktopItem {
233 name = "rustdesk-link";
234 desktopName = "RustDeskURL Scheme Handler";
235 noDisplay = true;
236 mimeTypes = [ "x-scheme-handler/rustdesk" ];
237 tryExec = "rustdesk";
238 exec = "rustdesk %u";
239 icon = "rustdesk";
240 terminal = false;
241 type = "Application";
242 startupNotify = false;
243 })
244 ];
245
246 meta = {
247 description = "Virtual / remote desktop infrastructure for everyone! Open source TeamViewer / Citrix alternative";
248 homepage = "https://rustdesk.com";
249 changelog = "https://github.com/rustdesk/rustdesk/releases/${version}";
250 license = lib.licenses.agpl3Only;
251 maintainers = with lib.maintainers; [
252 das_j
253 helsinki-Jo
254 ];
255 mainProgram = "rustdesk";
256 platforms = lib.platforms.linux; # should work on darwin as well but I have no machine to test with
257 };
258}