1{ stdenv, requireFile, p7zip, jre, libusb1, platform-tools, gtk2, glib, libXtst }:
2
3# TODO:
4#
5# The FlashTool and FlashToolConsole scripts are messy and should probably we
6# replaced entirely. All these scripts do is try to guess the environment in
7# which to run the Java binary (and they guess wrong on NixOS).
8#
9# The FlashTool scripts run 'chmod' on the binaries installed in the Nix
10# store. These commands fail, naturally, because the Nix story is (hopefully)
11# mounted read-only. This doesn't matter, though, because the build
12# instructions fix the executable bits already.
13
14stdenv.mkDerivation rec {
15 name = "flashtool-0.9.14.0";
16
17 src = requireFile {
18 url = "http://dfiles.eu/files/n8c1c3pgc";
19 name = "flashtool-0.9.14.0-linux.tar.7z";
20 sha256 = "0mfjdjj7clz2dhkg7lzy1m8hk8ngla7zgcryf51aki1gnpbb2zc1";
21 };
22
23 buildInputs = [ p7zip jre ];
24
25 unpackPhase = ''
26 7z e ${src}
27 tar xf ${name}-linux.tar
28 sourceRoot=FlashTool
29 '';
30
31 buildPhase = ''
32 ln -s ${platform-tools}/libexec/android-sdk/platform-tools/adb x10flasher_lib/adb.linux
33 ln -s ${platform-tools}/libexec/android-sdk/platform-tools/fastboot x10flasher_lib/fastboot.linux
34 ln -s ${libusb1.out}/lib/libusb-1.0.so.0 ./x10flasher_lib/linux/lib32/libusbx-1.0.so
35
36 chmod +x x10flasher_lib/unyaffs.linux.x86 x10flasher_lib/bin2elf x10flasher_lib/bin2sin
37 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" x10flasher_lib/unyaffs.linux.x86
38 ln -sf unyaffs.linux.x86 x10flasher_lib/unyaffs.linux
39
40 ln -s swt32.jar x10flasher_lib/swtlin/swt.jar
41
42 sed -i \
43 -e 's|$(uname -m)|i686|' \
44 -e 's|export JAVA_HOME=.*|export JAVA_HOME=${jre}|' \
45 -e 's|export LD_LIBRARY_PATH=.*|export LD_LIBRARY_PATH=${stdenv.lib.makeLibraryPath [ libXtst glib gtk2 ]}:./x10flasher_lib/linux/lib32|' \
46 FlashTool FlashToolConsole
47 '';
48
49 installPhase = ''
50 mkdir -p $out
51 mv * $out/
52 '';
53
54 meta = {
55 homepage = http://www.flashtool.net/;
56 description = "S1 flashing software for Sony phones from X10 to Xperia Z Ultra";
57 license = stdenv.lib.licenses.unfreeRedistributableFirmware;
58 platforms = [ "i686-linux" ];
59 hydraPlatforms = stdenv.lib.platforms.none;
60 broken = true;
61 };
62}