summaryrefslogtreecommitdiff
path: root/build.nix
blob: c670866c216dbdb206320a5806abfcc472f75225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ pkgs, teensy-core, ... }:

{
  build = name: source: pkgs.stdenv.mkDerivation rec {
    inherit name;

    src = source;

    buildInputs = with pkgs; [
      gcc-arm-embedded
      teensy-core
    ];

    buildPhase = ''
      export CC=arm-none-eabi-gcc
      export CXX=arm-none-eabi-g++
      export OBJCOPY=arm-none-eabi-objcopy
      export SIZE=arm-none-eabi-size

      cp ${./Makefile.default} Makefile
      export TEENSY_PATH=${teensy-core}
      make
    '';

    installPhase = ''
      mkdir $out
      cp *.hex $out/
    '';
  };

  flash = let
    loader = name: path: pkgs.writeScript name ''
      #!/bin/sh
      ${pkgs.teensy-loader-cli}/bin/teensy-loader-cli --mcu=TEENSY40 -w ${path}
    '';

  in drv: file: {
    type = "app";
    program = ''${loader file "${drv}/${file}.hex"}'';
  };
}