@@ -0,0 +1,101 @@
1+{ stdenv, fetchFromGitHub, fetchurl, makeWrapper, unzip
2+, gnumake, gcc-arm-embedded, dfu-util-axoloti, jdk, ant, libfaketime }:
3+
4+stdenv.mkDerivation rec {
5+ version = "1.0.12-1";
6+ name = "axoloti-${version}";
7+
8+ src = fetchFromGitHub {
9+ owner = "axoloti";
10+ repo = "axoloti";
11+ rev = "${version}";
12+ sha256 = "13njmv8zac0kaaxgkv4y4zfjcclafn9cw0m8lj2k4926wnwjmf50";
13+ };
14+
15+ chibi_version = "2.6.9";
16+ chibi_name = "ChibiOS_${chibi_version}";
17+
18+ chibios = fetchurl {
19+ url = "mirror://sourceforge/project/chibios/ChibiOS_RT%20stable/Version%20${chibi_version}/${chibi_name}.zip";
20+ sha256 = "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj";
21+ };
22+
23+ buildInputs = [ makeWrapper unzip gcc-arm-embedded dfu-util-axoloti jdk ant libfaketime ];
24+
25+ patchPhase = ''
26+ unzip ${chibios}
27+ mv ${chibi_name} chibios
28+ (cd chibios/ext; unzip -q -o fatfs-0.9-patched.zip)
29+
30+ # Remove source of non-determinism in ChibiOS
31+ substituteInPlace "chibios/os/various/shell.c" \
32+ --replace "#ifdef __DATE__" "#if 0"
33+
34+ # Hardcode full path to compiler tools
35+ for f in "firmware/Makefile.patch" \
36+ "firmware/Makefile" \
37+ "firmware/flasher/Makefile" \
38+ "firmware/mounter/Makefile"; do
39+ substituteInPlace "$f" \
40+ --replace "arm-none-eabi-" "${gcc-arm-embedded}/bin/arm-none-eabi-"
41+ done
42+
43+ # Hardcode path to "make"
44+ for f in "firmware/compile_firmware_linux.sh" \
45+ "firmware/compile_patch_linux.sh"; do
46+ substituteInPlace "$f" \
47+ --replace "make" "${gnumake}/bin/make"
48+ done
49+
50+ # Hardcode dfu-util path
51+ substituteInPlace "platform_linux/upload_fw_dfu.sh" \
52+ --replace "/bin/dfu-util" ""
53+ substituteInPlace "platform_linux/upload_fw_dfu.sh" \
54+ --replace "./dfu-util" "${dfu-util-axoloti}/bin/dfu-util"
55+
56+ # Fix build version
57+ substituteInPlace "build.xml" \
58+ --replace "(git missing)" "${version}"
59+
60+ # Remove build time
61+ substituteInPlace "build.xml" \
62+ --replace "<tstamp>" ""
63+ substituteInPlace "build.xml" \
64+ --replace \
65+ '<format property="build.time" pattern="dd/MM/yyyy HH:mm:ss z"/>' \
66+ '<property name="build.time" value=""/>'
67+ substituteInPlace "build.xml" \
68+ --replace "</tstamp>" ""
69+ substituteInPlace "build.xml" \
70+ --replace \
71+ '{line.separator}</echo>' \
72+ '{line.separator}</echo> <touch file="src/main/java/axoloti/Version.java" millis="0" />'
73+ '';
74+
75+ buildPhase = ''
76+ find . -exec touch -d '1970-01-01 00:00' {} \;
77+ (cd platform_linux; sh compile_firmware.sh)
78+ faketime "1970-01-01 00:00:00" ant -Dbuild.runtime=true
79+ '';
80+
81+ installPhase = ''
82+ mkdir -p $out/bin $out/share/axoloti
83+
84+ cp -r doc firmware chibios platform_linux CMSIS *.txt $out/share/axoloti/
85+ install -vD dist/Axoloti.jar $out/share/axoloti/
86+
87+ makeWrapper ${jdk}/bin/java $out/bin/axoloti --add-flags "-Daxoloti_release=$out/share/axoloti -Daxoloti_runtime=$out/share/axoloti -jar $out/share/axoloti/Axoloti.jar"
88+ '';
89+
90+ meta = with stdenv.lib; {
91+ homepage = http://www.axoloti.com;
92+ description = ''
93+ Sketching embedded digital audio algorithms.
94+
95+ To fix permissions of the Axoloti USB device node, add a similar udev rule to <literal>services.udev.extraRules</literal>:
96+ <literal>SUBSYSTEM=="usb", ATTR{idVendor}=="16c0", ATTR{idProduct}=="0442", OWNER="someuser", GROUP="somegroup"</literal>
97+ '';
98+ license = licenses.gpl3;
99+ maintainers = with lib.maintainers; [ TealG ];
100+ };
101+}