iamb: cleaning (#365160)
[NixPkgs.git] / pkgs / applications / blockchains / sparrow / default.nix
blobe0df2dc7bc6bbf38ff296d1083155f83361ed654
2   stdenv,
3   stdenvNoCC,
4   lib,
5   makeWrapper,
6   fetchurl,
7   makeDesktopItem,
8   copyDesktopItems,
9   autoPatchelfHook,
10   openjdk,
11   gtk3,
12   gsettings-desktop-schemas,
13   writeScript,
14   bash,
15   gnugrep,
16   tor,
17   zlib,
18   openimajgrabber,
19   hwi,
20   imagemagick,
21   gzip,
22   gnupg,
25 let
26   pname = "sparrow";
27   version = "2.0.0";
29   src = fetchurl {
30     url = "https://github.com/sparrowwallet/${pname}/releases/download/${version}/${pname}-${version}-x86_64.tar.gz";
31     sha256 = "sha256-Z4rA3KObPAOuJeI+TzyYaXDyptAxBAWzYJDTplUvw50=";
33     # nativeBuildInputs, downloadToTemp, and postFetch are used to verify the signed upstream package.
34     # The signature is not a self-contained file. Instead the SHA256 of the package is added to a manifest file.
35     # The manifest file is signed by the owner of the public key, Craig Raw.
36     # Thus to verify the signed package, the manifest is verified with the public key,
37     # and then the package is verified against the manifest.
38     # The public key is obtained from https://keybase.io/craigraw/pgp_keys.asc
39     # and is included in this repo to provide reproducibility.
40     nativeBuildInputs = [ gnupg ];
41     downloadToTemp = true;
43     postFetch = ''
44       pushd $(mktemp -d)
45       export GNUPGHOME=$PWD/gnupg
46       mkdir -m 700 -p $GNUPGHOME
47       ln -s ${manifest} ./manifest.txt
48       ln -s ${manifestSignature} ./manifest.txt.asc
49       ln -s $downloadedFile ./${pname}-${version}-x86_64.tar.gz
50       gpg --import ${publicKey}
51       gpg --verify manifest.txt.asc manifest.txt
52       sha256sum -c --ignore-missing manifest.txt
53       popd
54       mv $downloadedFile $out
55     '';
56   };
58   manifest = fetchurl {
59     url = "https://github.com/sparrowwallet/${pname}/releases/download/${version}/${pname}-${version}-manifest.txt";
60     sha256 = "sha256-qjkKw3WmbRBf+yqcSIYVWmYz8M3u2JxnBriR0Ec/C7A=";
61   };
63   manifestSignature = fetchurl {
64     url = "https://github.com/sparrowwallet/${pname}/releases/download/${version}/${pname}-${version}-manifest.txt.asc";
65     sha256 = "sha256-CRrEzWqFVFQGWsh2+rjSuGHuFmf+y6SetCi2G89jZ/0=";
66   };
68   publicKey = ./publickey.asc;
70   launcher = writeScript "sparrow" ''
71     #! ${bash}/bin/bash
72     params=(
73       --module-path @out@/lib:@jdkModules@/modules
74       --add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls
75       --add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls
76       --add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls
77       --add-opens=javafx.controls/com.sun.javafx.scene.control.inputmap=org.controlsfx.controls
78       --add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls
79       --add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls
80       --add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow
81       --add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow
82       --add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=javafx.fxml
83       --add-opens=javafx.graphics/com.sun.javafx.tk=centerdevice.nsmenufx
84       --add-opens=javafx.graphics/com.sun.javafx.tk.quantum=centerdevice.nsmenufx
85       --add-opens=javafx.graphics/com.sun.glass.ui=centerdevice.nsmenufx
86       --add-opens=javafx.controls/com.sun.javafx.scene.control=centerdevice.nsmenufx
87       --add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx
88       --add-opens=javafx.graphics/com.sun.glass.ui=com.sparrowwallet.sparrow
89       --add-opens=javafx.graphics/javafx.scene.input=com.sparrowwallet.sparrow
90       --add-opens=javafx.graphics/com.sun.javafx.application=com.sparrowwallet.sparrow
91       --add-opens=java.base/java.net=com.sparrowwallet.sparrow
92       --add-opens=java.base/java.io=com.google.gson
93       --add-opens=java.smartcardio/sun.security.smartcardio=com.sparrowwallet.sparrow
94       --add-reads=com.sparrowwallet.merged.module=java.desktop
95       --add-reads=com.sparrowwallet.merged.module=java.sql
96       --add-reads=com.sparrowwallet.merged.module=com.sparrowwallet.sparrow
97       --add-reads=com.sparrowwallet.merged.module=ch.qos.logback.classic
98       --add-reads=com.sparrowwallet.merged.module=org.slf4j
99       --add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.databind
100       --add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.annotation
101       --add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.core
102       --add-reads=com.sparrowwallet.merged.module=co.nstant.in.cbor
103       --add-reads=kotlin.stdlib=kotlinx.coroutines.core
104       -m com.sparrowwallet.sparrow
105     )
107     XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}:${gtk3}/share/gsettings-schemas/${gtk3.name}:$XDG_DATA_DIRS ${openjdk}/bin/java ''${params[@]} $@
108   '';
110   torWrapper = writeScript "tor-wrapper" ''
111     #! ${bash}/bin/bash
113     exec ${tor}/bin/tor "$@"
114   '';
116   jdk-modules = stdenvNoCC.mkDerivation {
117     name = "jdk-modules";
118     nativeBuildInputs = [ openjdk ];
119     dontUnpack = true;
121     buildPhase = ''
122       # Extract the JDK's JIMAGE and generate a list of modules.
123       mkdir modules
124       pushd modules
125       jimage extract ${openjdk}/lib/openjdk/lib/modules
126       ls | xargs -d " " -- echo > ../manifest.txt
127       popd
128     '';
130     installPhase = ''
131       mkdir -p $out
132       cp manifest.txt $out/
133       cp -r modules/ $out/
134     '';
135   };
137   sparrow-modules = stdenvNoCC.mkDerivation {
138     pname = "sparrow-modules";
139     inherit version src;
140     nativeBuildInputs = [
141       makeWrapper
142       gzip
143       gnugrep
144       openjdk
145       autoPatchelfHook
146       (lib.getLib stdenv.cc.cc)
147       zlib
148     ];
150     buildPhase = ''
151       # Extract Sparrow's JIMAGE and generate a list of them.
152       mkdir modules
153       pushd modules
154       jimage extract ../lib/runtime/lib/modules
156       # Delete JDK modules
157       cat ${jdk-modules}/manifest.txt | xargs -I {} -- rm -fR {}
159       # Delete unneeded native libs.
161       rm -fR com.sparrowwallet.merged.module/com/sun/jna/freebsd-x86-64
162       rm -fR com.sparrowwallet.merged.module/com/sun/jna/freebsd-x86
163       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-aarch64
164       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-arm
165       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-armel
166       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-mips64el
167       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-ppc
168       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-ppc64le
169       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-s390x
170       rm -fR com.sparrowwallet.merged.module/com/sun/jna/linux-x86
171       rm -fR com.sparrowwallet.merged.module/com/sun/jna/openbsd-x86-64
172       rm -fR com.sparrowwallet.merged.module/com/sun/jna/openbsd-x86
173       rm -fR com.sparrowwallet.merged.module/com/sun/jna/sunos-sparc
174       rm -fR com.sparrowwallet.merged.module/com/sun/jna/sunos-sparcv9
175       rm -fR com.sparrowwallet.merged.module/com/sun/jna/sunos-x86-64
176       rm -fR com.sparrowwallet.merged.module/com/sun/jna/sunos-x86
177       rm -fR com.github.sarxos.webcam.capture/com/github/sarxos/webcam/ds/buildin/lib/linux_armel
178       rm -fR com.github.sarxos.webcam.capture/com/github/sarxos/webcam/ds/buildin/lib/linux_armhf
179       rm -fR com.github.sarxos.webcam.capture/com/github/sarxos/webcam/ds/buildin/lib/linux_x86
180       rm com.github.sarxos.webcam.capture/com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so
181       rm -fR com.nativelibs4java.bridj/org/bridj/lib/linux_arm32_armel
182       rm -fR com.nativelibs4java.bridj/org/bridj/lib/linux_armel
183       rm -fR com.nativelibs4java.bridj/org/bridj/lib/linux_armhf
184       rm -fR com.nativelibs4java.bridj/org/bridj/lib/linux_x86
185       rm -fR com.nativelibs4java.bridj/org/bridj/lib/sunos_x64
186       rm -fR com.nativelibs4java.bridj/org/bridj/lib/sunos_x86
187       rm -fR com.sparrowwallet.merged.module/linux-aarch64
188       rm -fR com.sparrowwallet.merged.module/linux-arm
189       rm -fR com.sparrowwallet.merged.module/linux-x86
190       rm com.sparrowwallet.sparrow/native/linux/x64/hwi
192       ls | xargs -d " " -- echo > ../manifest.txt
193       find . | grep "\.so$" | xargs -- chmod ugo+x
194       popd
196       # Replace the embedded Tor binary (which is in a Tar archive)
197       # with one from Nixpkgs.
198       gzip -c ${torWrapper}  > tor.gz
199       cp tor.gz modules/kmp.tor.binary.linuxx64/kmptor/linux/x64/tor.gz
200     '';
202     installPhase = ''
203       mkdir -p $out
204       cp manifest.txt $out/
205       cp -r modules/ $out/
206       ln -s ${openimajgrabber}/lib/OpenIMAJGrabber.so $out/modules/com.github.sarxos.webcam.capture/com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so
207       ln -s ${hwi}/bin/hwi $out/modules/com.sparrowwallet.sparrow/native/linux/x64/hwi
208     '';
209   };
211 stdenvNoCC.mkDerivation rec {
212   inherit version src;
213   pname = "sparrow-unwrapped";
214   nativeBuildInputs = [
215     makeWrapper
216     copyDesktopItems
217   ];
219   desktopItems = [
220     (makeDesktopItem {
221       name = "sparrow-desktop";
222       exec = "sparrow-desktop";
223       icon = "sparrow-desktop";
224       desktopName = "Sparrow Bitcoin Wallet";
225       genericName = "Bitcoin Wallet";
226       categories = [
227         "Finance"
228         "Network"
229       ];
230       mimeTypes = [
231         "application/psbt"
232         "application/bitcoin-transaction"
233         "x-scheme-handler/bitcoin"
234         "x-scheme-handler/auth47"
235         "x-scheme-handler/lightning"
236       ];
237       startupWMClass = "Sparrow";
238     })
239   ];
241   sparrow-icons = stdenvNoCC.mkDerivation {
242     inherit version src;
243     pname = "sparrow-icons";
244     nativeBuildInputs = [ imagemagick ];
246     installPhase = ''
247       for n in 16 24 32 48 64 96 128 256; do
248         size=$n"x"$n
249         mkdir -p $out/hicolor/$size/apps
250         convert lib/Sparrow.png -resize $size $out/hicolor/$size/apps/sparrow-desktop.png
251         done;
252     '';
253   };
255   installPhase = ''
256     runHook preInstall
258     mkdir -p $out/bin $out
259     ln -s ${sparrow-modules}/modules $out/lib
260     install -D -m 777 ${launcher} $out/bin/sparrow-desktop
261     substituteAllInPlace $out/bin/sparrow-desktop
262     substituteInPlace $out/bin/sparrow-desktop --subst-var-by jdkModules ${jdk-modules}
264     mkdir -p $out/share/icons
265     ln -s ${sparrow-icons}/hicolor $out/share/icons
267     mkdir -p $out/etc/udev/rules.d
268     cp ${hwi}/lib/python*/site-packages/hwilib/udev/*.rules $out/etc/udev/rules.d
270     runHook postInstall
271   '';
273   meta = with lib; {
274     description = "Modern desktop Bitcoin wallet application supporting most hardware wallets and built on common standards such as PSBT, with an emphasis on transparency and usability";
275     homepage = "https://sparrowwallet.com";
276     sourceProvenance = with sourceTypes; [
277       binaryBytecode
278       binaryNativeCode
279     ];
280     license = licenses.asl20;
281     maintainers = with maintainers; [
282       emmanuelrosa
283       _1000101
284     ];
285     platforms = [ "x86_64-linux" ];
286     mainProgram = "sparrow-desktop";
287   };