git.iko.soy/typeable/nixpkgs
on master help sign in
teensyduino: init at 1.31 (#20807)
commit538ec0cc929684058a0dda7587446afd2ab351dc authorJonathan Glines <auntieNeo@gmail.com> dateFri 2 Dec 2016, 03:31 (10 years ago) parentda3d8d0
2 files changed+109−5
pkgs/development/arduino/arduino-core/default.nix+107−5 pkgs/top-level/all-packages.nix+2
pkgs/development/arduino/arduino-core/default.nix+107−5
@@ -1,10 +1,21 @@
11{ stdenv, lib, fetchFromGitHub, fetchurl, jdk, ant
22, libusb, libusb1, unzip, zlib, ncurses, readline
3−, withGui ? false, gtk2 ? null
3+, withGui ? false, gtk2 ? null, withTeensyduino ? false
4+ /* Packages needed for Teensyduino */
5+, upx, fontconfig, xorg, gcc, xdotool, xvfb_run
6+, atk, glib, pango, gdk_pixbuf, libpng12, expat, freetype
47}:
58
69assert withGui -> gtk2 != null;
7−
10+assert withTeensyduino -> withGui;
11+
12+# TODO: Teensyduino is disabled for i686-linux due to an indefinite hang in the
13+# xdotool script; the cause of this hang is not yet known.
14+# TODO: There is a fair chance that Teensyduino works with arm-linux, but it
15+# has not yet been tested.
16+if withTeensyduino && (stdenv.system != "x86_64-linux") then throw
17+ "Teensyduino is only supported on x86_64-linux at this time (patches welcome)."
18+else
819let
920 externalDownloads = import ./downloads.nix {inherit fetchurl; inherit (lib) optionalAttrs; inherit (stdenv) system;};
1021 # Some .so-files are later copied from .jar-s to $HOME, so patch them beforehand
@@ -14,10 +25,37 @@ let
1425 ;
1526 # abiVersion 6 is default, but we need 5 for `avrdude_bin` executable
1627 ncurses5 = ncurses.override { abiVersion = "5"; };
28+
29+ teensy_libpath = stdenv.lib.makeLibraryPath [
30+ atk
31+ expat
32+ fontconfig
33+ freetype
34+ gcc.cc.lib
35+ gdk_pixbuf
36+ glib
37+ gtk2
38+ libpng12
39+ libusb
40+ pango
41+ xorg.libSM
42+ xorg.libX11
43+ xorg.libXext
44+ xorg.libXft
45+ xorg.libXinerama
46+ zlib
47+ ];
48+ teensy_architecture =
49+ lib.optionalString (stdenv.system == "x86_64-linux") "linux64"
50+ + lib.optionalString (stdenv.system == "i686-linux") "linux32"
51+ + lib.optionalString (stdenv.system == "arm-linux") "linuxarm";
52+
53+ flavor = (if withTeensyduino then "teensyduino" else "arduino")
54+ + stdenv.lib.optionalString (!withGui) "-core";
1755in
1856stdenv.mkDerivation rec {
1957 version = "1.6.12";
20− name = "arduino${stdenv.lib.optionalString (withGui == false) "-core"}-${version}";
58+ name = "${flavor}-${version}";
2159
2260 src = fetchFromGitHub {
2361 owner = "arduino";
@@ -26,7 +64,19 @@ stdenv.mkDerivation rec {
2664 sha256 = "0rz8dv1mncwx2wkafakxqdi2y0rq3f72fr57cg0z5hgdgdm89lkh";
2765 };
2866
29− buildInputs = [ jdk ant libusb libusb1 unzip zlib ncurses5 readline ];
67+ teensyduino_src = fetchurl {
68+ url = "http://www.pjrc.com/teensy/td_131/TeensyduinoInstall.${teensy_architecture}";
69+ sha256 =
70+ lib.optionalString ("${teensy_architecture}" == "linux64")
71+ "1q4wv6s0900hyv9z1mjq33fr2isscps4q3bsy0h12wi3l7ir94g9"
72+ + lib.optionalString ("${teensy_architecture}" == "linux32")
73+ "06fl951f44avqyqim5qmy73siylbqcnsmz55zmj2dzhgf4sflkvc"
74+ + lib.optionalString ("${teensy_architecture}" == "linuxarm")
75+ "0ldf33w8wkqwklcj8fn4p22f23ibpwpf7873dc6i2jfmmbx0yvxn";
76+ };
77+
78+ buildInputs = [ jdk ant libusb libusb1 unzip zlib ncurses5 readline
79+ ] ++ stdenv.lib.optionals withTeensyduino [ upx xvfb_run xdotool ];
3080 downloadSrcList = builtins.attrValues externalDownloads;
3181 downloadDstList = builtins.attrNames externalDownloads;
3282
@@ -75,6 +125,50 @@ stdenv.mkDerivation rec {
75125 --replace '<BINARY_LOCATION>' "$out/bin/arduino" \
76126 --replace '<ICON_NAME>' "$out/share/arduino/icons/128x128/apps/arduino.png"
77127 ''}
128+
129+ ${stdenv.lib.optionalString withTeensyduino ''
130+ # Extract and patch the Teensyduino installer
131+ cp ${teensyduino_src} ./TeensyduinoInstall.${teensy_architecture}
132+ chmod +w ./TeensyduinoInstall.${teensy_architecture}
133+ upx -d ./TeensyduinoInstall.${teensy_architecture}
134+ patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
135+ --set-rpath "${teensy_libpath}" \
136+ ./TeensyduinoInstall.${teensy_architecture}
137+ chmod +x ./TeensyduinoInstall.${teensy_architecture}
138+
139+ # Run the GUI-only installer in a virtual X server
140+ # Script thanks to AUR package. See:
141+ # <https://aur.archlinux.org/packages/teensyduino/>
142+ echo "Running Teensyduino installer..."
143+ # Trick the GUI into using HOME as the install directory.
144+ export HOME=$out/share/arduino
145+ # Run the installer in a virtual X server in memory.
146+ xvfb-run -n 99 ./TeensyduinoInstall.${teensy_architecture} &
147+ sleep 4
148+ echo "Waiting for Teensyduino to install (about 1 minute)..."
149+ # Control the installer GUI with xdotool.
150+ DISPLAY=:99 xdotool search --class "teensyduino" \
151+ windowfocus \
152+ key space sleep 1 \
153+ key Tab sleep 0.4 \
154+ key Tab sleep 0.4 \
155+ key Tab sleep 0.4 \
156+ key Tab sleep 0.4 \
157+ key space sleep 1 \
158+ key Tab sleep 0.4 \
159+ key Tab sleep 0.4 \
160+ key Tab sleep 0.4 \
161+ key Tab sleep 0.4 \
162+ key space sleep 1 \
163+ key Tab sleep 0.4 \
164+ key space sleep 35 \
165+ key space sleep 2 &
166+ # Wait for xdotool to terminate and swallow the inevitable XIO error
167+ wait $! || true
168+
169+ # Check for successful installation
170+ [ -d $out/share/arduino/hardware/teensy ] || exit 1
171+ ''}
78172 '';
79173
80174 # So we don't accidentally mess with firmware files
@@ -101,6 +195,14 @@ stdenv.mkDerivation rec {
101195 # avrdude_bin is linked against libtinfo.so.5
102196 mkdir $out/lib/
103197 ln -s ${lib.makeLibraryPath [ncurses5]}/libncursesw.so.5 $out/lib/libtinfo.so.5
198+
199+ ${stdenv.lib.optionalString withTeensyduino ''
200+ # Patch the Teensy loader binary
201+ patchelf --debug \
202+ --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
203+ --set-rpath "${teensy_libpath}" \
204+ $out/share/arduino/hardware/tools/teensy
205+ ''}
104206 '';
105207
106208 meta = with stdenv.lib; {
@@ -108,6 +210,6 @@ stdenv.mkDerivation rec {
108210 homepage = http://arduino.cc/;
109211 license = stdenv.lib.licenses.gpl2;
110212 platforms = platforms.linux;
111− maintainers = with maintainers; [ antono robberer bjornfor ];
213+ maintainers = with maintainers; [ antono auntie robberer bjornfor ];
112214 };
113215}
pkgs/top-level/all-packages.nix+2
@@ -6502,6 +6502,8 @@ in
65026502
65036503 tcptrack = callPackage ../development/tools/misc/tcptrack { };
65046504
6505+ teensyduino = arduino-core.override { withGui = true; withTeensyduino = true; };
6506+
65056507 teensy-loader-cli = callPackage ../development/tools/misc/teensy-loader-cli { };
65066508
65076509 texinfo413 = callPackage ../development/tools/misc/texinfo/4.13a.nix { };