btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / hi / hiddify-app / package.nix
blob172c4d65bc34084b130e0a8596e9a5bf9ada59e6
2   lib,
3   fetchFromGitHub,
4   pkg-config,
5   flutter,
6   buildGoModule,
7   libayatana-appindicator,
8   stdenv,
9   fetchurl,
10   makeDesktopItem,
11   copyDesktopItems,
12   wrapGAppsHook3,
13   autoPatchelfHook,
15 let
16   pname = "hiddify-app";
17   version = "2.5.7-unstable-2024-10-30";
18   src = fetchFromGitHub {
19     owner = "hiddify";
20     repo = "hiddify-app";
21     rev = "0144cddf670df11d1586a0dc76483f4c4f5b4230";
22     hash = "sha256-bjZkc0H0409YxM6AGrhm6gPaKNj/9SiVs0AUPoLJX+o=";
23     fetchSubmodules = true;
24   };
25   libcore = buildGoModule rec {
26     inherit pname version src;
28     modRoot = "./libcore";
30     vendorHash = "sha256-a7NFZt4/w2+oaZG3ncaOrrhASxUptcWS/TeaIQrgLe4=";
32     GO_PUBLIC_FLAGS = ''
33       -tags "with_gvisor,with_quic,with_wireguard,with_ech,with_utls,with_clash_api,with_grpc" \
34       -trimpath \
35       -ldflags "-s -w" \
36     '';
38     postPatch = ''
39       sed -i '/import (/a\ \t"os"\n\t"path/filepath"' ./libcore/v2/db/hiddify_db.go
40       substituteInPlace ./libcore/v2/db/hiddify_db.go \
41         --replace-fail 'NewGoLevelDBWithOpts(name, "./data", ' 'NewGoLevelDBWithOpts(name, filepath.Join(os.Getenv("HOME"), ".local", "share", "app.hiddify.com", "data"), '
42     '';
44     buildPhase = ''
45       runHook preBuild
47       go build ${GO_PUBLIC_FLAGS} -buildmode=c-shared -o bin/lib/libcore.so ./custom
48       mkdir lib
49       cp bin/lib/libcore.so ./lib/libcore.so
50       CGO_LDFLAGS="./lib/libcore.so" go build ${GO_PUBLIC_FLAGS} -o bin/HiddifyCli ./cli/bydll
52       runHook postBuild
53     '';
55     installPhase = ''
56       runHook preInstall
58       mkdir -p $out/bin $out/lib
59       cp ./bin/HiddifyCli $out/bin/HiddifyCli
60       cp ./lib/libcore.so $out/lib/libcore.so
62       runHook postInstall
63     '';
65     meta = {
66       description = "Multi-platform auto-proxy client, supporting Sing-box, X-ray, TUIC, Hysteria, Reality, Trojan, SSH etc";
67       homepage = "https://hiddify.com";
68       mainProgram = "HiddifyCli";
69       license = lib.licenses.cc-by-nc-sa-40;
70       platforms = lib.platforms.linux;
71       maintainers = with lib.maintainers; [ aucub ];
72     };
73   };
74   sqlite-autoconf = fetchurl {
75     url = "https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz";
76     hash = "sha256-b45qezNSc3SIFvmztiu9w3Koid6HgtfwSMZTpEdBen0=";
77   };
79 flutter.buildFlutterApplication {
80   inherit pname version src;
82   pubspecLock = lib.importJSON ./pubspec.lock.json;
84   buildInputs = [
85     libayatana-appindicator
86   ];
88   nativeBuildInputs = [
89     pkg-config
90     autoPatchelfHook
91     wrapGAppsHook3
92     copyDesktopItems
93   ];
95   customSourceBuilders = {
96     sqlite3_flutter_libs =
97       { version, src, ... }:
98       stdenv.mkDerivation rec {
99         pname = "sqlite3_flutter_libs";
100         inherit version src;
101         inherit (src) passthru;
102         postPatch = ''
103           substituteInPlace linux/CMakeLists.txt \
104             --replace-fail "https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz" "file://${sqlite-autoconf}"
105         '';
106         installPhase = ''
107           runHook preInstall
108           mkdir $out
109           cp -a ./* $out/
110           runHook postInstall
111         '';
112       };
113   };
115   postPatch = ''
116     substituteInPlace ./linux/my_application.cc \
117       --replace-fail "./hiddify.png" "${placeholder "out"}/share/pixmaps/hiddify.png"
118   '';
120   preBuild = ''
121     cp -r ${libcore}/lib libcore/bin/lib
122     cp ${libcore}/bin/HiddifyCli libcore/bin/HiddifyCli
123     packageRun build_runner build --delete-conflicting-outputs
124     packageRun slang
125   '';
127   postInstall = ''
128     mkdir -p $out/share/pixmaps/
129     cp ./assets/images/source/ic_launcher_border.png $out/share/pixmaps/hiddify.png
130   '';
132   desktopItems = [
133     (makeDesktopItem {
134       name = "hiddify";
135       exec = "hiddify";
136       icon = "hiddify";
137       genericName = "Hiddify";
138       desktopName = "Hiddify";
139       categories = [
140         "Network"
141       ];
142       keywords = [
143         "Hiddify"
144         "Proxy"
145         "VPN"
146         "V2ray"
147         "Nekoray"
148         "Xray"
149         "Psiphon"
150         "OpenVPN"
151       ];
152     })
153   ];
155   flutterBuildFlags = [
156     "--target lib/main_prod.dart"
157   ];
159   gitHashes = {
160     circle_flags = "sha256-dqORH4yj0jU8r9hP9NTjrlEO0ReHt4wds7BhgRPq57g=";
161     flutter_easy_permission = "sha256-fs2dIwFLmeDrlFIIocGw6emOW1whGi9W7nQ7mHqp8R0=";
162     humanizer = "sha256-zsDeol5l6maT8L8R6RRtHyd7CJn5908nvRXIytxiPqc=";
163   };
165   extraWrapProgramArgs = ''
166     --prefix LD_LIBRARY_PATH : "$out/app/${pname}/lib"
167   '';
169   preFixup = ''
170     patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/app/${pname}/lib/lib*.so
171   '';
173   meta = {
174     description = "Multi-platform auto-proxy client, supporting Sing-box, X-ray, TUIC, Hysteria, Reality, Trojan, SSH etc";
175     homepage = "https://hiddify.com";
176     mainProgram = "hiddify";
177     license = lib.licenses.cc-by-nc-sa-40;
178     platforms = lib.platforms.linux;
179     maintainers = with lib.maintainers; [ aucub ];
180   };