2024-09-23 15:02:59 +08:00
{
lib ,
clangStdenv ,
cargo ,
copyDesktopItems ,
fetchFromGitHub ,
2025-02-08 07:39:55 +08:00
flutter ,
2024-09-23 15:02:59 +08:00
ffmpeg ,
gst_all_1 ,
fuse3 ,
libXtst ,
libaom ,
libopus ,
libpulseaudio ,
libva ,
libvdpau ,
libvpx ,
libxkbcommon ,
libyuv ,
pam ,
makeDesktopItem ,
rustPlatform ,
libayatana-appindicator ,
rustc ,
rustfmt ,
xdotool ,
2025-03-13 21:51:07 +01:00
xdg-user-dirs ,
2025-02-05 20:13:51 +08:00
pipewire ,
2025-02-08 07:39:55 +08:00
cargo-expand ,
yq ,
callPackage ,
2024-09-23 15:02:59 +08:00
} :
let
2024-02-03 20:00:12 +01:00
flutterRustBridge = rustPlatform . buildRustPackage rec {
pname = " f l u t t e r _ r u s t _ b r i d g e _ c o d e g e n " ;
2025-08-05 15:00:40 +02:00
version = " 1 . 8 0 . 1 " ; # https://github.com/rustdesk/rustdesk/blob/1.4.1/.github/workflows/bridge.yml#L10
2024-02-03 20:00:12 +01:00
src = fetchFromGitHub {
owner = " f z y z c j y " ;
repo = " f l u t t e r _ r u s t _ b r i d g e " ;
2025-04-08 02:51:45 -04:00
rev = " v ${ version } " ;
2024-02-03 20:00:12 +01:00
hash = " s h a 2 5 6 - S b w q W a p J b t 6 + R o q R K i + w k S H 1 D + W z 7 J m n V b f c f K k j t 8 Q = " ;
} ;
2025-02-08 07:39:55 +08:00
patches = [
./update-flutter-dev-path.patch
] ;
2025-01-24 22:25:42 +01:00
cargoHash = " s h a 2 5 6 - 4 k h u q / D K 4 s P 9 8 A M H y r / l E o 1 O J d q L u j O I i 8 I g b K B Y 6 0 Y = " ;
2024-09-23 15:02:59 +08:00
cargoBuildFlags = [
" - - p a c k a g e "
" f l u t t e r _ r u s t _ b r i d g e _ c o d e g e n "
] ;
2024-02-03 20:00:12 +01:00
doCheck = false ;
} ;
2025-02-08 07:39:55 +08:00
ffigen = callPackage ./ffigen {
inherit flutter ;
} ;
2024-02-11 17:47:26 +01:00
sharedLibraryExt = rustc . stdenv . hostPlatform . extensions . sharedLibrary ;
2024-09-23 15:02:59 +08:00
in
2025-02-08 07:39:55 +08:00
flutter . buildFlutterApplication rec {
2024-02-03 20:00:12 +01:00
pname = " r u s t d e s k " ;
2025-08-05 15:00:40 +02:00
version = " 1 . 4 . 1 " ;
2025-02-23 18:05:34 +08:00
2024-02-03 20:00:12 +01:00
src = fetchFromGitHub {
owner = " r u s t d e s k " ;
repo = " r u s t d e s k " ;
2025-02-08 07:39:55 +08:00
tag = version ;
fetchSubmodules = true ;
2025-08-05 15:00:40 +02:00
hash = " s h a 2 5 6 - n S 8 K j L z g d z g v n 5 m M 1 l J L 2 v F k 0 g / Z U Z B v d k j y C + M d H D E = " ;
2024-02-03 20:00:12 +01:00
} ;
strictDeps = true ;
2024-08-21 14:02:45 +02:00
env . VCPKG_ROOT = " / h o m e l e s s - s h e l t e r " ; # idk man, makes the build go since https://github.com/21pages/hwcodec/commit/1873c34e3da070a462540f61c0b782b7ab15dc84
2024-02-03 20:00:12 +01:00
# Configure the Flutter/Dart build
2024-03-09 01:04:40 +08:00
sourceRoot = " ${ src . name } / f l u t t e r " ;
2025-08-05 15:00:40 +02:00
# curl https://raw.githubusercontent.com/rustdesk/rustdesk/1.4.1/flutter/pubspec.lock | yq > pubspec.lock.json
2024-02-03 20:00:12 +01:00
pubspecLock = lib . importJSON ./pubspec.lock.json ;
gitHashes = {
dash_chat_2 = " s h a 2 5 6 - J 5 B c 6 C e C o R G N 8 7 0 a N E V J 2 d k Q N b + L O I Z e t f G 2 D s f z 5 O w = " ;
2025-02-08 07:39:55 +08:00
desktop_multi_window = " s h a 2 5 6 - N O e 0 j M c H 0 2 c 0 T D T t v 6 2 O M T R / q D P n R Q r R e 7 3 v X D u E q 8 Q = " ;
2024-02-03 20:00:12 +01:00
dynamic_layouts = " s h a 2 5 6 - e F p 1 Y V I 6 v I 2 H R g t E 5 n T q G Z I y l B 2 2 6 H 0 O 8 k u x y 9 y p u f 8 = " ;
2025-04-23 21:02:43 +08:00
flutter_gpu_texture_renderer = " s h a 2 5 6 - E Z a 1 F O M b c w d V s / m 0 v s U v l H v + M i f P b y 4 I 9 7 Z F e 1 b q m w Q = " ;
2025-02-08 07:39:55 +08:00
window_manager = " s h a 2 5 6 - 4 0 m w j 4 D 8 W 2 x W 8 C 7 R s h T j O h e l O i L P M 7 u U 9 r s F 4 N v Q n 8 c = " ;
window_size = " s h a 2 5 6 - X e l N t p 7 t p Z 9 1 Q C E c v e w V p h N U t g Q X 7 x r p 5 Q P 0 o F o 6 D g M = " ;
texture_rgba_renderer = " s h a 2 5 6 - V / b m T / 5 x + B t 7 k d j L T k g k o X d B c F V X x P y p 9 k I U h f + R n t 4 = " ;
uni_links = " s h a 2 5 6 - O 2 B g N w u 5 H F R Q y a N k s k W H O R x 8 p Z h d w E j t l j v w 1 + z F z f o = " ;
2024-02-03 20:00:12 +01:00
} ;
# Configure the Rust build
cargoRoot = " . . " ;
2025-02-08 07:39:55 +08:00
cargoDeps = rustPlatform . fetchCargoVendor {
inherit
pname
version
src
patches
;
2025-08-05 15:00:40 +02:00
hash = " s h a 2 5 6 - e c L R 6 c M V D r T K e o T E 5 Y x k w 5 d N 4 c e A m + R D 7 B V X w I Q 1 f n k = " ;
2024-02-03 20:00:12 +01:00
} ;
2025-02-08 07:39:55 +08:00
2024-02-03 20:00:12 +01:00
dontCargoBuild = true ;
cargoBuildFlags = " - - l i b " ;
cargoBuildType = " r e l e a s e " ;
cargoBuildFeatures = [
" f l u t t e r "
2024-06-24 16:04:15 +02:00
" h w c o d e c "
" l i n u x - p k g - c o n f i g "
2024-02-03 20:00:12 +01:00
] ;
nativeBuildInputs = [
# flutter_rust_bridge_codegen
cargo
copyDesktopItems
rustfmt
# Rust
rustPlatform . cargoSetupHook
rustPlatform . cargoBuildHook
2025-02-08 07:39:55 +08:00
cargo-expand
2024-02-03 20:00:12 +01:00
rustPlatform . bindgenHook
2025-02-08 07:39:55 +08:00
ffigen
yq
2024-02-03 20:00:12 +01:00
] ;
buildInputs = [
2024-08-21 14:02:45 +02:00
ffmpeg
2024-07-08 04:04:28 -04:00
fuse3
2024-02-03 20:00:12 +01:00
gst_all_1 . gst-plugins-base
gst_all_1 . gstreamer
libXtst
libaom
libopus
libpulseaudio
libva
libvdpau
libvpx
2025-02-05 20:13:51 +08:00
pipewire
2024-02-03 20:00:12 +01:00
libxkbcommon
libyuv
2024-06-24 16:04:15 +02:00
pam
2024-02-03 20:00:12 +01:00
xdotool
] ;
2024-02-11 17:47:26 +01:00
prePatch = ''
2024-02-03 20:00:12 +01:00
chmod - R + w . .
2025-02-08 07:39:55 +08:00
cd . .
2024-02-11 17:47:26 +01:00
'' ;
2025-02-08 07:39:55 +08:00
patches = [
./make-build-reproducible.patch
2024-09-23 15:02:59 +08:00
] ;
2024-02-11 17:47:26 +01:00
2025-02-08 07:39:55 +08:00
prepareBuildRunner = ''
cp $ { ./build-runner.sh } build_runner
substituteInPlace build_runner \
- - replace-fail " @ b a s h @ " " $ S H E L L "
chmod + x build_runner
export PATH = $ PATH:$PWD
'' ;
2024-08-21 14:21:23 +02:00
2024-02-11 17:47:26 +01:00
postPatch = ''
2025-02-08 07:39:55 +08:00
cd flutter
2024-11-17 19:20:21 +08:00
if [ $ cargoDepsCopy ] ; then # That will be inherited to buildDartPackage and it doesn't have cargoDepsCopy
substituteInPlace $ cargoDepsCopy/libappindicator-sys- * /src/lib.rs \
- - replace-fail " l i b a y a t a n a - a p p i n d i c a t o r 3 . s o . 1 " " ${ lib . getLib libayatana-appindicator } / l i b / l i b a y a t a n a - a p p i n d i c a t o r 3 . s o . 1 "
2025-02-08 07:39:55 +08:00
# Disable static linking of ffmpeg since https://github.com/21pages/hwcodec/commit/1873c34e3da070a462540f61c0b782b7ab15dc84
sed - i ' s/static = // g' $ cargoDepsCopy/hwcodec- * /build.rs
2024-11-17 19:20:21 +08:00
fi
2024-08-11 10:53:35 +02:00
substituteInPlace ../Cargo.toml - - replace-fail " , \" s t a t i c l i b \" , \" r l i b \" " " "
2024-02-03 20:00:12 +01:00
'' ;
preBuild = ''
# Build the Flutter/Rust bridge bindings
cat < < EOF > bridge . yml
rust_input :
- " . . / s r c / f l u t t e r _ f f i . r s "
dart_output :
- " . / l i b / g e n e r a t e d _ b r i d g e . d a r t "
llvm_path :
2024-02-11 17:47:26 +01:00
- " ${ lib . getLib clangStdenv . cc . cc } "
2024-02-03 20:00:12 +01:00
dart_format_line_length : 80
2024-02-11 17:47:26 +01:00
llvm_compiler_opts : " - I ${ lib . getLib clangStdenv . cc . cc } / l i b / c l a n g / ${ lib . versions . major clangStdenv . cc . version } / i n c l u d e - I ${ clangStdenv . cc . libc_dev } / i n c l u d e "
2024-02-03 20:00:12 +01:00
EOF
2025-02-08 07:39:55 +08:00
runHook prepareBuildRunner
2024-02-03 20:00:12 +01:00
RUST_LOG = info $ { flutterRustBridge } /bin/flutter_rust_bridge_codegen bridge . yml
# Build the Rust shared library
cd . .
preBuild = ( ) # prevent loops
2024-02-11 17:47:26 +01:00
cargoBuildHook
mv ./target /* / r e l e a s e / l i b l i b r u s t d e s k $ { s h a r e d L i b r a r y E x t } . / t a r g e t / r e l e a s e / l i b l i b r u s t d e s k $ { s h a r e d L i b r a r y E x t }
2024-02-03 20:00:12 +01:00
cd flutter
'' ;
postInstall = ''
mkdir - p $ out/share/polkit-1/actions $ out/share/icons/hicolor / { 2 5 6 x256 , scalable } /apps
cp ../res/128x128 @ 2 x . png $ out/share/icons/hicolor/256x256/apps/rustdesk.png
cp ../res/scalable.svg $ out/share/icons/hicolor/scalable/apps/rustdesk.svg
'' ;
2025-03-13 21:51:07 +01:00
extraWrapProgramArgs = ''
- - prefix PATH : $ { lib . makeBinPath [ xdg-user-dirs ] }
'' ;
2024-02-03 20:00:12 +01:00
desktopItems = [
( makeDesktopItem {
name = " r u s t d e s k " ;
desktopName = " R u s t D e s k " ;
genericName = " R e m o t e D e s k t o p " ;
2024-02-11 17:47:26 +01:00
comment = " R e m o t e D e s k t o p " ;
exec = " r u s t d e s k % u " ;
2024-02-03 20:00:12 +01:00
icon = " r u s t d e s k " ;
terminal = false ;
type = " A p p l i c a t i o n " ;
startupNotify = true ;
2024-09-23 15:02:59 +08:00
categories = [
" N e t w o r k "
" R e m o t e A c c e s s "
" G T K "
] ;
2024-02-03 20:00:12 +01:00
keywords = [ " i n t e r n e t " ] ;
actions . new-window = {
name = " O p e n a N e w W i n d o w " ;
2024-02-11 17:47:26 +01:00
exec = " r u s t d e s k % u " ;
2024-02-03 20:00:12 +01:00
} ;
} )
( makeDesktopItem {
name = " r u s t d e s k - l i n k " ;
desktopName = " R u s t D e s k U R L S c h e m e H a n d l e r " ;
noDisplay = true ;
mimeTypes = [ " x - s c h e m e - h a n d l e r / r u s t d e s k " ] ;
tryExec = " r u s t d e s k " ;
2024-02-11 17:47:26 +01:00
exec = " r u s t d e s k % u " ;
2024-02-03 20:00:12 +01:00
icon = " r u s t d e s k " ;
terminal = false ;
type = " A p p l i c a t i o n " ;
startupNotify = false ;
} )
] ;
2025-02-08 07:39:55 +08:00
meta = {
2024-02-03 20:00:12 +01:00
description = " V i r t u a l / r e m o t e d e s k t o p i n f r a s t r u c t u r e f o r e v e r y o n e ! O p e n s o u r c e T e a m V i e w e r / C i t r i x a l t e r n a t i v e " ;
homepage = " h t t p s : / / r u s t d e s k . c o m " ;
2025-02-08 07:39:55 +08:00
changelog = " h t t p s : / / g i t h u b . c o m / r u s t d e s k / r u s t d e s k / r e l e a s e s / ${ version } " ;
license = lib . licenses . agpl3Only ;
teams = [ lib . teams . helsinki-systems ] ;
2024-02-03 20:00:12 +01:00
mainProgram = " r u s t d e s k " ;
2025-02-08 07:39:55 +08:00
platforms = lib . platforms . linux ; # should work on darwin as well but I have no machine to test with
2024-02-03 20:00:12 +01:00
} ;
}