2016-07-20 13:57:59 +01:00
|
|
|
{ stdenv, lib, fetchFromGitHub, fetchurl, jdk, ant
|
2020-04-28 04:29:39 +01:00
|
|
|
, libusb-compat-0_1, libusb1, unzip, zlib, ncurses, readline
|
2016-12-02 10:31:01 +00:00
|
|
|
, withGui ? false, gtk2 ? null, withTeensyduino ? false
|
|
|
|
/* Packages needed for Teensyduino */
|
2019-03-06 07:40:09 +00:00
|
|
|
, upx, fontconfig, xorg, gcc
|
2020-02-27 00:44:03 +00:00
|
|
|
, atk, glib, pango, gdk-pixbuf, libpng12, expat, freetype
|
|
|
|
, cairo, udev
|
2016-05-11 20:01:29 +01:00
|
|
|
}:
|
2015-02-04 21:23:18 +00:00
|
|
|
|
|
|
|
assert withGui -> gtk2 != null;
|
2016-12-02 10:31:01 +00:00
|
|
|
assert withTeensyduino -> withGui;
|
|
|
|
|
|
|
|
# TODO: Teensyduino is disabled for i686-linux due to an indefinite hang in the
|
|
|
|
# xdotool script; the cause of this hang is not yet known.
|
|
|
|
# TODO: There is a fair chance that Teensyduino works with arm-linux, but it
|
|
|
|
# has not yet been tested.
|
2018-08-20 20:11:29 +01:00
|
|
|
if withTeensyduino && (stdenv.hostPlatform.system != "x86_64-linux") then throw
|
2016-12-02 10:31:01 +00:00
|
|
|
"Teensyduino is only supported on x86_64-linux at this time (patches welcome)."
|
|
|
|
else
|
2016-07-20 13:57:59 +01:00
|
|
|
let
|
2018-08-20 20:11:29 +01:00
|
|
|
externalDownloads = import ./downloads.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
inherit (lib) optionalAttrs;
|
|
|
|
inherit (stdenv.hostPlatform) system;
|
|
|
|
};
|
2016-07-20 13:57:59 +01:00
|
|
|
# Some .so-files are later copied from .jar-s to $HOME, so patch them beforehand
|
|
|
|
patchelfInJars =
|
2019-09-06 15:30:12 +01:00
|
|
|
lib.optional (stdenv.hostPlatform.system == "x86_64-linux") {jar = "share/arduino/lib/jssc-2.8.0-arduino3.jar"; file = "libs/linux/libjSSC-2.8_x86_64.so";}
|
|
|
|
++ lib.optional (stdenv.hostPlatform.system == "i686-linux") {jar = "share/arduino/lib/jssc-2.8.0-arduino3.jar"; file = "libs/linux/libjSSC-2.8_x86.so";}
|
2016-07-20 13:57:59 +01:00
|
|
|
;
|
|
|
|
# abiVersion 6 is default, but we need 5 for `avrdude_bin` executable
|
|
|
|
ncurses5 = ncurses.override { abiVersion = "5"; };
|
2016-12-02 10:31:01 +00:00
|
|
|
|
|
|
|
teensy_libpath = stdenv.lib.makeLibraryPath [
|
|
|
|
atk
|
2020-02-27 00:44:03 +00:00
|
|
|
cairo
|
2016-12-02 10:31:01 +00:00
|
|
|
expat
|
|
|
|
fontconfig
|
|
|
|
freetype
|
|
|
|
gcc.cc.lib
|
2019-05-22 12:03:39 +01:00
|
|
|
gdk-pixbuf
|
2016-12-02 10:31:01 +00:00
|
|
|
glib
|
|
|
|
gtk2
|
|
|
|
libpng12
|
2020-04-28 04:29:39 +01:00
|
|
|
libusb-compat-0_1
|
2016-12-02 10:31:01 +00:00
|
|
|
pango
|
2020-02-27 00:44:03 +00:00
|
|
|
udev
|
2016-12-02 10:31:01 +00:00
|
|
|
xorg.libSM
|
|
|
|
xorg.libX11
|
|
|
|
xorg.libXext
|
|
|
|
xorg.libXft
|
|
|
|
xorg.libXinerama
|
2020-02-27 00:44:03 +00:00
|
|
|
xorg.libXxf86vm
|
2016-12-02 10:31:01 +00:00
|
|
|
zlib
|
|
|
|
];
|
2020-06-09 16:38:39 +01:00
|
|
|
teensy_architecture = if stdenv.hostPlatform.isx86_32 then "linux32"
|
|
|
|
else if stdenv.hostPlatform.isx86_64 then "linux64"
|
|
|
|
else if stdenv.hostPlatform.isAarch32 then "linuxarm"
|
|
|
|
else throw "${stdenv.hostPlatform.system} is not supported in teensy";
|
2016-12-02 10:31:01 +00:00
|
|
|
|
|
|
|
flavor = (if withTeensyduino then "teensyduino" else "arduino")
|
|
|
|
+ stdenv.lib.optionalString (!withGui) "-core";
|
2016-07-20 13:57:59 +01:00
|
|
|
in
|
2012-11-28 01:55:24 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2019-09-06 15:30:12 +01:00
|
|
|
version = "1.8.9";
|
2016-12-02 10:31:01 +00:00
|
|
|
name = "${flavor}-${version}";
|
2012-11-28 01:55:24 +00:00
|
|
|
|
2014-10-10 07:03:02 +01:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "arduino";
|
|
|
|
repo = "Arduino";
|
2019-09-09 00:38:31 +01:00
|
|
|
rev = version;
|
2019-09-06 15:30:12 +01:00
|
|
|
sha256 = "0kblq0bqap2zzkflrj6rmdi8dvqxa28fcwwrc3lfmbz2893ni3w4";
|
2012-11-28 01:55:24 +00:00
|
|
|
};
|
|
|
|
|
2019-09-06 19:27:59 +01:00
|
|
|
teensyduino_version = "147";
|
2016-12-02 10:31:01 +00:00
|
|
|
teensyduino_src = fetchurl {
|
2019-03-06 07:40:09 +00:00
|
|
|
url = "https://www.pjrc.com/teensy/td_${teensyduino_version}/TeensyduinoInstall.${teensy_architecture}";
|
2020-06-09 16:38:39 +01:00
|
|
|
sha256 = {
|
|
|
|
linux64 = "09ysanip5d2f5axzd81z2l74ayng60zqhjxmxs7xa5098fff46il";
|
|
|
|
linux32 = "1zw3cfv2p62dwg8838vh0gd1934b18cyx7c13azvwmrpj601l0xx";
|
|
|
|
linuxarm = "12421z26ksx84aldw1pq0cakh8jhs33mwafgvfij0zfgn9x0i877";
|
|
|
|
}.${teensy_architecture} or (throw "No arduino binaries for ${teensy_architecture}");
|
|
|
|
};
|
2019-03-06 07:40:09 +00:00
|
|
|
# Used because teensyduino requires jars be a specific size
|
|
|
|
arduino_dist_src = fetchurl {
|
|
|
|
url = "http://downloads.arduino.cc/arduino-${version}-${teensy_architecture}.tar.xz";
|
|
|
|
sha256 =
|
2020-06-09 16:38:39 +01:00
|
|
|
{
|
|
|
|
linux64 = "1lv4in9j0r8s0cis4zdvbk2637vlj12w69wdxgcxcrwvkcdahkpa";
|
|
|
|
linux32 = "0zla3a6gd9prclgrbbgsmhf8ds8zb221m65x21pvz0y1cwsdvjpm";
|
|
|
|
linuxarm = "1w5m49wfd68zazli0lf3w4zykab8n7mzp3wnbjqfpx2vip80bqnz";
|
|
|
|
}.${teensy_architecture} or (throw "No arduino binaries for ${teensy_architecture}");
|
2016-12-02 10:31:01 +00:00
|
|
|
};
|
|
|
|
|
2019-03-06 07:40:09 +00:00
|
|
|
|
2020-04-28 04:29:39 +01:00
|
|
|
buildInputs = [ jdk ant libusb-compat-0_1 libusb1 unzip zlib ncurses5 readline
|
2019-03-06 07:40:09 +00:00
|
|
|
] ++ stdenv.lib.optionals withTeensyduino [ upx ];
|
2016-07-20 13:57:59 +01:00
|
|
|
downloadSrcList = builtins.attrValues externalDownloads;
|
|
|
|
downloadDstList = builtins.attrNames externalDownloads;
|
2012-11-28 01:55:24 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
2016-07-20 13:57:59 +01:00
|
|
|
# Copy pre-downloaded files to proper locations
|
|
|
|
download_src=($downloadSrcList)
|
|
|
|
download_dst=($downloadDstList)
|
|
|
|
while [[ "''${#download_src[@]}" -ne 0 ]]; do
|
|
|
|
file_src=''${download_src[0]}
|
|
|
|
file_dst=''${download_dst[0]}
|
|
|
|
mkdir -p $(dirname $file_dst)
|
|
|
|
download_src=(''${download_src[@]:1})
|
|
|
|
download_dst=(''${download_dst[@]:1})
|
|
|
|
cp -v $file_src $file_dst
|
|
|
|
done
|
|
|
|
|
2017-06-01 00:05:18 +01:00
|
|
|
# Deliberately break build.xml's download statement in order to cause
|
|
|
|
# an error if anything needed is missing from download.nix.
|
|
|
|
substituteInPlace build/build.xml --replace "get src" "get error"
|
|
|
|
|
2016-07-20 13:57:59 +01:00
|
|
|
cd ./arduino-core && ant
|
2019-05-22 12:03:39 +01:00
|
|
|
cd ../build && ant
|
2012-11-28 01:55:24 +00:00
|
|
|
cd ..
|
|
|
|
'';
|
|
|
|
|
2016-07-20 13:57:59 +01:00
|
|
|
# This will be patched into `arduino` wrapper script
|
|
|
|
# Java loads gtk dynamically, so we need to provide it using LD_LIBRARY_PATH
|
|
|
|
dynamicLibraryPath = lib.makeLibraryPath [gtk2];
|
|
|
|
javaPath = lib.makeBinPath [jdk];
|
|
|
|
|
|
|
|
# Everything else will be patched into rpath
|
2020-04-28 04:29:39 +01:00
|
|
|
rpath = (lib.makeLibraryPath [zlib libusb-compat-0_1 libusb1 readline ncurses5 stdenv.cc.cc]);
|
2016-07-20 13:57:59 +01:00
|
|
|
|
2012-11-28 01:55:24 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share/arduino
|
2019-03-06 07:40:09 +00:00
|
|
|
cp -r ./build/linux/work/* "$out/share/arduino/"
|
|
|
|
echo -n ${version} > $out/share/arduino/lib/version.txt
|
2014-10-27 21:02:23 +00:00
|
|
|
|
2015-02-04 21:23:18 +00:00
|
|
|
${stdenv.lib.optionalString withGui ''
|
2016-07-20 13:57:59 +01:00
|
|
|
mkdir -p $out/bin
|
|
|
|
substituteInPlace $out/share/arduino/arduino \
|
|
|
|
--replace "JAVA=java" "JAVA=$javaPath/java" \
|
|
|
|
--replace "LD_LIBRARY_PATH=" "LD_LIBRARY_PATH=$dynamicLibraryPath:"
|
2015-02-04 21:23:18 +00:00
|
|
|
ln -sr "$out/share/arduino/arduino" "$out/bin/arduino"
|
2016-07-20 13:57:59 +01:00
|
|
|
|
|
|
|
cp -r build/shared/icons $out/share/arduino
|
|
|
|
mkdir -p $out/share/applications
|
|
|
|
cp build/linux/dist/desktop.template $out/share/applications/arduino.desktop
|
|
|
|
substituteInPlace $out/share/applications/arduino.desktop \
|
|
|
|
--replace '<BINARY_LOCATION>' "$out/bin/arduino" \
|
|
|
|
--replace '<ICON_NAME>' "$out/share/arduino/icons/128x128/apps/arduino.png"
|
2015-02-04 21:23:18 +00:00
|
|
|
''}
|
2016-12-02 10:31:01 +00:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString withTeensyduino ''
|
2019-03-06 07:40:09 +00:00
|
|
|
# Back up the original jars
|
|
|
|
mv $out/share/arduino/lib/arduino-core.jar $out/share/arduino/lib/arduino-core.jar.bak
|
|
|
|
mv $out/share/arduino/lib/pde.jar $out/share/arduino/lib/pde.jar.bak
|
|
|
|
# Extract jars from the arduino distributable package
|
|
|
|
mkdir arduino_dist
|
|
|
|
cd arduino_dist
|
|
|
|
tar xfJ ${arduino_dist_src} arduino-${version}/lib/arduino-core.jar arduino-${version}/lib/pde.jar
|
|
|
|
cd ..
|
|
|
|
# Replace the built jars with the official arduino jars
|
|
|
|
mv arduino_dist/arduino-${version}/lib/{arduino-core,pde}.jar $out/share/arduino/lib/
|
|
|
|
# Delete the directory now that the jars are copied out
|
|
|
|
rm -r arduino_dist
|
2016-12-02 10:31:01 +00:00
|
|
|
# Extract and patch the Teensyduino installer
|
|
|
|
cp ${teensyduino_src} ./TeensyduinoInstall.${teensy_architecture}
|
|
|
|
chmod +w ./TeensyduinoInstall.${teensy_architecture}
|
|
|
|
upx -d ./TeensyduinoInstall.${teensy_architecture}
|
|
|
|
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
--set-rpath "${teensy_libpath}" \
|
|
|
|
./TeensyduinoInstall.${teensy_architecture}
|
|
|
|
chmod +x ./TeensyduinoInstall.${teensy_architecture}
|
2019-03-06 07:40:09 +00:00
|
|
|
./TeensyduinoInstall.${teensy_architecture} --dir=$out/share/arduino
|
2016-12-02 10:31:01 +00:00
|
|
|
# Check for successful installation
|
|
|
|
[ -d $out/share/arduino/hardware/teensy ] || exit 1
|
2019-03-06 07:40:09 +00:00
|
|
|
# After the install, copy the built jars back
|
|
|
|
mv $out/share/arduino/lib/arduino-core.jar.bak $out/share/arduino/lib/arduino-core.jar
|
|
|
|
mv $out/share/arduino/lib/pde.jar.bak $out/share/arduino/lib/pde.jar
|
2016-12-02 10:31:01 +00:00
|
|
|
''}
|
2016-07-20 13:57:59 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# So we don't accidentally mess with firmware files
|
|
|
|
dontStrip = true;
|
|
|
|
dontPatchELF = true;
|
2015-02-04 21:23:18 +00:00
|
|
|
|
2016-07-20 13:57:59 +01:00
|
|
|
preFixup = ''
|
|
|
|
for file in $(find $out -type f \( -perm /0111 -o -name \*.so\* \) ); do
|
|
|
|
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$file" || true
|
|
|
|
patchelf --set-rpath ${rpath}:$out/lib $file || true
|
2014-10-27 21:02:23 +00:00
|
|
|
done
|
2015-02-04 21:23:18 +00:00
|
|
|
|
2016-07-20 13:57:59 +01:00
|
|
|
${lib.concatMapStringsSep "\n"
|
|
|
|
({jar, file}:
|
|
|
|
''
|
|
|
|
jar xvf $out/${jar} ${file}
|
|
|
|
patchelf --set-rpath $rpath ${file}
|
|
|
|
jar uvf $out/${jar} ${file}
|
|
|
|
rm -f ${file}
|
|
|
|
''
|
|
|
|
)
|
|
|
|
patchelfInJars}
|
|
|
|
|
|
|
|
# avrdude_bin is linked against libtinfo.so.5
|
|
|
|
mkdir $out/lib/
|
2019-09-18 18:57:20 +01:00
|
|
|
ln -s ${lib.makeLibraryPath [ncurses5]}/libtinfo.so.5 $out/lib/libtinfo.so.5
|
2016-12-02 10:31:01 +00:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString withTeensyduino ''
|
|
|
|
# Patch the Teensy loader binary
|
|
|
|
patchelf --debug \
|
|
|
|
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
|
|
--set-rpath "${teensy_libpath}" \
|
|
|
|
$out/share/arduino/hardware/tools/teensy
|
|
|
|
''}
|
2012-11-28 01:55:24 +00:00
|
|
|
'';
|
|
|
|
|
2015-02-07 09:29:31 +00:00
|
|
|
meta = with stdenv.lib; {
|
2015-02-04 21:23:18 +00:00
|
|
|
description = "Open-source electronics prototyping platform";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "http://arduino.cc/";
|
2017-06-01 00:05:18 +01:00
|
|
|
license = if withTeensyduino then licenses.unfreeRedistributable else licenses.gpl2;
|
2016-08-11 04:29:58 +01:00
|
|
|
platforms = platforms.linux;
|
2019-09-06 15:30:12 +01:00
|
|
|
maintainers = with maintainers; [ antono auntie robberer bjornfor bergey ];
|
2016-07-20 13:57:59 +01:00
|
|
|
};
|
2012-11-28 01:55:24 +00:00
|
|
|
}
|