diff options
author | Adrian Kummerlaender | 2021-10-10 21:48:10 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2021-10-10 21:48:10 +0200 |
commit | bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516 (patch) | |
tree | dd1bafa866328ad6853f955200d78f8a6080a54b | |
parent | 59918fa4f925c063c8beec7142f786eda5746cc4 (diff) | |
download | teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar.gz teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar.bz2 teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar.lz teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar.xz teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.tar.zst teensy-env-bdd2cb7b9a1d9d1e34e1c838311a57a9ea552516.zip |
Extract basic Teensy image builder
-rw-r--r-- | Makefile.default (renamed from test/Makefile) | 0 | ||||
-rw-r--r-- | build.nix | 30 | ||||
-rw-r--r-- | flake.nix | 13 | ||||
-rw-r--r-- | test.nix | 2 | ||||
-rw-r--r-- | ulisp.nix | 71 |
5 files changed, 62 insertions, 54 deletions
diff --git a/test/Makefile b/Makefile.default index 3bf5a70..3bf5a70 100644 --- a/test/Makefile +++ b/Makefile.default diff --git a/build.nix b/build.nix new file mode 100644 index 0000000..3770d57 --- /dev/null +++ b/build.nix @@ -0,0 +1,30 @@ +{ 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/ + ''; + }; +} @@ -10,8 +10,17 @@ pkgs = import nixpkgs { inherit system; }; teensy-core = import ./core.nix { inherit pkgs; }; - teensy-test = import ./test.nix { inherit pkgs teensy-core; }; - teensy-ulisp = import ./ulisp.nix { inherit pkgs teensy-core; }; + + image = import ./build.nix { inherit pkgs teensy-core; }; + + teensy-test = image.build "teensy-test" ./test; + + teensy-ulisp = let + ulisp-source = import ./ulisp.nix { inherit pkgs; }; + in image.build + "teensy-ulisp" + (pkgs.linkFarmFromDrvs "ulisp" [ ulisp-source ]); + in { packages.${system} = { inherit teensy-core teensy-test teensy-ulisp; @@ -16,8 +16,8 @@ pkgs.stdenv.mkDerivation rec { export OBJCOPY=arm-none-eabi-objcopy export SIZE=arm-none-eabi-size + cp ${teensy-core}/include/Makefile.default Makefile export TEENSY_PATH=${teensy-core} - make ''; @@ -1,65 +1,34 @@ -{ pkgs, teensy-core, ... }: +{ pkgs, ... }: -let - # hacky usage of arduino-cli to preprocess ulisp "ino" source into compilable C++ code - preprocessed-ulisp-arm = pkgs.stdenv.mkDerivation rec { - name = "preprocessed-ulisp-arm.cpp"; +# hacky usage of arduino-cli to preprocess ulisp "ino" source into compilable C++ code +pkgs.stdenv.mkDerivation rec { + name = "ulisp-arm.cpp"; - src = pkgs.fetchFromGitHub { - owner = "technoblogy"; - repo = "ulisp-arm"; - rev = "a25fff3ef1072bdc2733d8064fcf0738579ab7ed"; - sha256 = "p6H9To9vccHrP46Cv5m+cAFDVPXDCORUWcqOz18c3kg="; - }; - - outputHashMode = "flat"; - outputHashAlgo = "sha256"; - outputHash = "mutVLBFSpTXgUzu594zZ3akR/Z7e9n5SytU6WoQ6rKA="; - - buildInputs = with pkgs; [ - cacert - arduino-cli - ]; - - buildPhase = '' - export HOME=/tmp/arduino - arduino-cli core install arduino:samd - mv ulisp-arm.ino source.ino - arduino-cli compile --fqbn arduino:samd:arduino_zero_native --preprocess > ulisp-arm.cpp - echo 'extern "C" int main(void) { setup(); while(true) { loop(); } }' >> ulisp-arm.cpp - ''; - - installPhase = '' - cp ulisp-arm.cpp $out - ''; + src = pkgs.fetchFromGitHub { + owner = "technoblogy"; + repo = "ulisp-arm"; + rev = "a25fff3ef1072bdc2733d8064fcf0738579ab7ed"; + sha256 = "p6H9To9vccHrP46Cv5m+cAFDVPXDCORUWcqOz18c3kg="; }; -in pkgs.stdenv.mkDerivation rec { - name = "teensy-ulisp"; + outputHashMode = "flat"; + outputHashAlgo = "sha256"; + outputHash = "mutVLBFSpTXgUzu594zZ3akR/Z7e9n5SytU6WoQ6rKA="; buildInputs = with pkgs; [ - gcc-arm-embedded - teensy-core + cacert + arduino-cli ]; - phases = [ "buildPhase" "installPhase" ]; - buildPhase = '' - cp ${./test/Makefile} Makefile - cp ${preprocessed-ulisp-arm} ulisp-arm.cpp - - export CC=arm-none-eabi-gcc - export CXX=arm-none-eabi-g++ - export OBJCOPY=arm-none-eabi-objcopy - export SIZE=arm-none-eabi-size - - export TEENSY_PATH=${teensy-core} - - make + export HOME=/tmp/arduino + arduino-cli core install arduino:samd + mv ulisp-arm.ino source.ino + arduino-cli compile --fqbn arduino:samd:arduino_zero_native --preprocess > ulisp-arm.cpp + echo 'extern "C" int main(void) { setup(); while(true) { loop(); } }' >> ulisp-arm.cpp ''; installPhase = '' - mkdir $out - cp *.hex $out/ + cp ulisp-arm.cpp $out ''; } |