├── .github └── workflows │ └── main.yml ├── .gitignore ├── LICENSE ├── README.md ├── arduino.nix └── examples ├── blink ├── blink.ino └── default.nix └── servo ├── default.nix └── servo.ino /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Demonstration 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: cachix/install-nix-action@v12 12 | with: 13 | nix_path: nixpkgs=channel:nixos-unstable 14 | - run: nix-build examples/blink/default.nix --argstr board "uno" 15 | - run: nix-build examples/blink/default.nix --argstr board "leonardo" 16 | - run: nix-build examples/blink/default.nix --argstr board "uno" 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | result -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 boredom101 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nixduino 2 | Build arduino sketches like any other nix derivation. 3 | Look at `examples/` for how to use it. 4 | 5 | ## How to use: 6 | Create a nix file that looks something like this: 7 | ```nix 8 | { board, pkgs ? import {} }: 9 | 10 | pkgs.callPackage ../../arduino.nix { } { # path to arduino.nix from this repository 11 | name = "blink"; # name you want for the derivation 12 | board = board; # board name, added to the name 13 | # in this case it is from the command line, but you can also set it here 14 | libraries = []; # libraries from arduino-core, valid names below 15 | src = pkgs.lib.cleanSource ./.; # path to the arduino files, passed to the derivation 16 | } 17 | ``` 18 | 19 | Then run this: `nix-build path/to/file.nix --argstr board "uno"` 20 | Or whatever the board is, valid options below. Note that we can do this because the nix file accepts it as an argument. 21 | 22 | ## Supported Board Values: 23 | - `uno` 24 | - `leonardo` 25 | - `mega` 26 | 27 | ## Supported Library Values: 28 | - `Ethernet` 29 | - `EEPROM` 30 | - `Firmata` 31 | - `GSM` 32 | - `LiquidCrystal` 33 | - `SD` 34 | - `Servo` 35 | - `SPI` 36 | - `SoftwareSerial` 37 | - `Stepper` 38 | - `TFT` 39 | - `WiFi` 40 | - `Wire` 41 | 42 | ## Notes: 43 | This is a work in progress 44 | -------------------------------------------------------------------------------- /arduino.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, writeScript, arduino-mk, arduino-core-unwrapped }: 2 | 3 | { name, board, libraries, ... }@args: 4 | 5 | let 6 | extraArgs = removeAttrs args [ "name" "board" "libraries" ]; 7 | in stdenv.mkDerivation({ 8 | buildInputs = [ arduino-mk arduino-core-unwrapped ]; 9 | makefile = (writeScript "makefile" '' 10 | ARDUINO_DIR = ${arduino-core-unwrapped}/share/arduino 11 | BOARD_TAG = ${board} 12 | ${ 13 | if (board == "mega") then 14 | "BOARD_SUB=atmega2560" 15 | else 16 | "" 17 | } 18 | ARDUINO_LIBS = ${lib.concatStringsSep " " libraries} 19 | include ${arduino-mk}/Arduino.mk 20 | '').outPath; 21 | installPhase = '' 22 | runHook preInstall 23 | mkdir -p $out 24 | mv build-*/*_.hex $out/build.hex 25 | runHook postInstall 26 | ''; 27 | name = "${name}-${board}"; 28 | } // extraArgs) 29 | -------------------------------------------------------------------------------- /examples/blink/blink.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | pinMode(13, OUTPUT); 3 | } 4 | 5 | void loop() { 6 | digitalWrite(13, HIGH); 7 | delay(1000); 8 | digitalWrite(13, LOW); 9 | delay(1000); 10 | } 11 | -------------------------------------------------------------------------------- /examples/blink/default.nix: -------------------------------------------------------------------------------- 1 | { board, pkgs ? import {} }: 2 | 3 | pkgs.callPackage ../../arduino.nix { } { 4 | name = "blink"; 5 | board = board; 6 | libraries = []; 7 | src = pkgs.lib.cleanSource ./.; 8 | } 9 | -------------------------------------------------------------------------------- /examples/servo/default.nix: -------------------------------------------------------------------------------- 1 | { board, pkgs ? import {} }: 2 | 3 | pkgs.callPackage ../../arduino.nix { } { 4 | name = "sweep"; 5 | board = board; 6 | libraries = ["Servo"]; 7 | src = pkgs.lib.cleanSource ./.; 8 | } 9 | -------------------------------------------------------------------------------- /examples/servo/servo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Servo servo; 4 | 5 | int pos = 0; 6 | 7 | void setup() { 8 | servo.attach(9); 9 | } 10 | 11 | void loop() { 12 | for (pos = 0; pos <= 180; pos += 1) { 13 | servo.write(pos); 14 | delay(15); 15 | } 16 | for (pos = 180; pos >= 0; pos -= 1) { 17 | servo.write(pos); 18 | delay(15); 19 | } 20 | } 21 | --------------------------------------------------------------------------------