nixpkgs/pkgs/development/arduino/arduino-core/default.nix

254 lines
9.0 KiB
Nix
Raw Normal View History

2020-05-10 10:05:49 +00:00
{ stdenv
, lib
, fetchFromGitHub
, fetchurl
, jdk
, ant
, libusb-compat-0_1
, libusb1
, unzip
, zlib
, ncurses
, readline
, withGui ? false
, gtk2 ? null
, withTeensyduino ? false
2016-12-02 10:31:01 +00:00
/* Packages needed for Teensyduino */
2020-05-10 10:05:49 +00:00
, upx
, fontconfig
, xorg
, gcc
, atk
, glib
, pango
, gdk-pixbuf
, libpng12
, expat
, freetype
, cairo
, udev
}:
assert withGui -> gtk2 != null;
2016-12-02 10:31:01 +00:00
assert withTeensyduino -> withGui;
let
externalDownloads = import ./downloads.nix {
inherit fetchurl;
inherit (lib) optionalAttrs;
inherit (stdenv.hostPlatform) system;
};
# Some .so-files are later copied from .jar-s to $HOME, so patch them beforehand
patchelfInJars =
2020-05-10 10:05:49 +00:00
lib.optional (stdenv.hostPlatform.system == "aarch64-linux") { jar = "share/arduino/lib/jssc-2.8.0-arduino4.jar"; file = "libs/linux/libjSSC-2.8_aarch64.so"; }
++ lib.optional (builtins.match "armv[67]l-linux" stdenv.hostPlatform.system != null) { jar = "share/arduino/lib/jssc-2.8.0-arduino4.jar"; file = "libs/linux/libjSSC-2.8_armhf.so"; }
++ lib.optional (stdenv.hostPlatform.system == "x86_64-linux") { jar = "share/arduino/lib/jssc-2.8.0-arduino4.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-arduino4.jar"; file = "libs/linux/libjSSC-2.8_x86.so"; }
;
# 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
cairo
2016-12-02 10:31:01 +00:00
expat
fontconfig
freetype
gcc.cc.lib
2019-05-22 11:03:39 +00:00
gdk-pixbuf
2016-12-02 10:31:01 +00:00
glib
gtk2
libpng12
2020-04-28 03:29:39 +00:00
libusb-compat-0_1
2016-12-02 10:31:01 +00:00
pango
udev
2016-12-02 10:31:01 +00:00
xorg.libSM
xorg.libX11
xorg.libXext
xorg.libXft
xorg.libXinerama
xorg.libXxf86vm
2016-12-02 10:31:01 +00:00
zlib
];
teensy_architecture =
2020-05-10 10:05:49 +00:00
lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") "linux64"
+ lib.optionalString (stdenv.hostPlatform.system == "i686-linux") "linux32"
+ lib.optionalString (stdenv.hostPlatform.system == "aarch64-linux") "linuxaarch64"
+ lib.optionalString (builtins.match "armv[67]l-linux" stdenv.hostPlatform.system != null) "linuxarm";
flavor = ( if withTeensyduino then "teensyduino" else "arduino")
+ stdenv.lib.optionalString (!withGui) "-core";
in
2012-11-28 01:55:24 +00:00
stdenv.mkDerivation rec {
2020-05-10 10:05:49 +00:00
version = "1.8.12";
2016-12-02 10:31:01 +00:00
name = "${flavor}-${version}";
2012-11-28 01:55:24 +00:00
src = fetchFromGitHub {
owner = "arduino";
repo = "Arduino";
2019-09-08 23:38:31 +00:00
rev = version;
2020-05-10 10:05:49 +00:00
sha256 = "0lxkyvsh55biz2q20ba4qabraind5cpxznl41zfq027vl22j6kd2";
2012-11-28 01:55:24 +00:00
};
2020-05-10 10:05:49 +00:00
teensyduino_version = "151";
2016-12-02 10:31:01 +00:00
teensyduino_src = fetchurl {
url = "https://www.pjrc.com/teensy/td_${teensyduino_version}/TeensyduinoInstall.${teensy_architecture}";
2016-12-02 10:31:01 +00:00
sha256 =
2019-09-08 23:38:31 +00:00
lib.optionalString (teensy_architecture == "linux64")
2020-05-10 10:05:49 +00:00
"0q8mw9bm2vb5vwa98gwcs6ad164i98hc1qqh2qw029yhwm599pn0"
2019-09-08 23:38:31 +00:00
+ lib.optionalString (teensy_architecture == "linux32")
2020-05-10 10:05:49 +00:00
"1rq6sx0048ab200jy0cz5vznwxi99avidngj42rjnh7kcfas5c4m"
+ lib.optionalString (teensy_architecture == "linuxaarch64")
"09k78dycn1vcpcx37c1dak8bgjv8gs34l89n9r9s0c3rqmv3pg4x"
2019-09-08 23:38:31 +00:00
+ lib.optionalString (teensy_architecture == "linuxarm")
2020-05-10 10:05:49 +00:00
"19j55bq36040rpdpfxcqimda76rkbx137q15bs8nvxj13wrbl4ip";
};
# 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 =
2019-09-08 23:38:31 +00:00
lib.optionalString (teensy_architecture == "linux64")
2020-05-10 10:05:49 +00:00
"128f34kkxz7ab6ir5mqyr8d1mgxig8f9jygwxy44pdnq2rk6gmh9"
2019-09-08 23:38:31 +00:00
+ lib.optionalString (teensy_architecture == "linux32")
2020-05-10 10:05:49 +00:00
"11n85lwsn1w4ysfacyw08v85s3f3zvl8j8ac7rld19yxgjslvisi"
+ lib.optionalString (teensy_architecture == "linuxaarch64")
"04v2nhyjhahml6nmz23bfb63c0an4a7zxgcgxqqq442i8vd304wa"
2019-09-08 23:38:31 +00:00
+ lib.optionalString (teensy_architecture == "linuxarm")
2020-05-10 10:05:49 +00:00
"1k8yjivaydm6y16mplrjyblgx7l0wjzm3mjxh5saxrjq7drswmxx";
2016-12-02 10:31:01 +00:00
};
2020-05-10 10:05:49 +00:00
buildInputs = [
jdk
ant
libusb-compat-0_1
libusb1
unzip
zlib
ncurses5
readline
] ++ stdenv.lib.optionals withTeensyduino [ upx ];
downloadSrcList = builtins.attrValues externalDownloads;
downloadDstList = builtins.attrNames externalDownloads;
2012-11-28 01:55:24 +00:00
buildPhase = ''
# 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-05-31 23:05:18 +00:00
# Deliberately break build.xml's download statement in order to cause
# an error if anything needed is missing from download.nix.
2020-05-10 10:05:49 +00:00
substituteInPlace build/build.xml \
--replace 'ignoreerrors="true"' 'ignoreerrors="false"'
2017-05-31 23:05:18 +00:00
cd ./arduino-core && ant
2019-05-22 11:03:39 +00:00
cd ../build && ant
2012-11-28 01:55:24 +00:00
cd ..
'';
# This will be patched into `arduino` wrapper script
# Java loads gtk dynamically, so we need to provide it using LD_LIBRARY_PATH
2020-05-10 10:05:49 +00:00
dynamicLibraryPath = lib.makeLibraryPath [ gtk2 ];
javaPath = lib.makeBinPath [ jdk ];
# Everything else will be patched into rpath
2020-05-10 10:05:49 +00:00
rpath = (lib.makeLibraryPath [ zlib libusb-compat-0_1 libusb1 readline ncurses5 stdenv.cc.cc ]);
2012-11-28 01:55:24 +00:00
installPhase = ''
mkdir -p $out/share/arduino
cp -r ./build/linux/work/* "$out/share/arduino/"
echo -n ${version} > $out/share/arduino/lib/version.txt
${stdenv.lib.optionalString withGui ''
mkdir -p $out/bin
substituteInPlace $out/share/arduino/arduino \
--replace "JAVA=java" "JAVA=$javaPath/java" \
--replace "LD_LIBRARY_PATH=" "LD_LIBRARY_PATH=$dynamicLibraryPath:"
ln -sr "$out/share/arduino/arduino" "$out/bin/arduino"
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"
''}
2016-12-02 10:31:01 +00:00
${stdenv.lib.optionalString withTeensyduino ''
# 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}
./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
# 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
''}
'';
# So we don't accidentally mess with firmware files
dontStrip = true;
dontPatchELF = true;
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
done
${lib.concatMapStringsSep "\n"
2020-05-10 10:05:49 +00:00
({ jar, file }:
''
2020-05-10 10:05:49 +00:00
jar xvf $out/${jar} ${file}
patchelf --set-rpath $rpath ${file}
jar uvf $out/${jar} ${file}
rm -f ${file}
''
)
2020-05-10 10:05:49 +00:00
patchelfInJars}
# avrdude_bin is linked against libtinfo.so.5
mkdir $out/lib/
2020-05-10 10:05:49 +00: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
'';
meta = with stdenv.lib; {
description = "Open-source electronics prototyping platform";
homepage = "http://arduino.cc/";
2017-05-31 23:05:18 +00:00
license = if withTeensyduino then licenses.unfreeRedistributable else licenses.gpl2;
2016-08-11 03:29:58 +00:00
platforms = platforms.linux;
2019-09-06 14:30:12 +00:00
maintainers = with maintainers; [ antono auntie robberer bjornfor bergey ];
};
2012-11-28 01:55:24 +00:00
}