{ description = "AVR"; inputs = { nixpkgs.url = "nixpkgs/nixos-21.11"; }; outputs = { self, nixpkgs }: let version = builtins.string 0 8 self.lastModifiedDate; supportedSystems = [ "x86_64-linux" "avr-none" ]; cflags = { mcu, chip_select, f_cpu }: ''-O -finline-functions -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Werror -Wstrict-prototypes -DF_CPU=${f_cpu} -std=gnu99 -D__${chip_select}__=1 -mmcu=${mcu}''; attiny85 = { mcu = "attiny85"; chip_select = "AVR_ATtiny85"; f_cpu = "8000000"; }; atmega32u4 = { mcu = "atmega32u4"; chip_select = "AVR_ATmega32u4"; f_cpu = "8000000"; }; processor = atmega32u4; in rec { defaultPackage."x86_64-linux" = let pkgs = import nixpkgs { system = "x86_64-linux"; }; in pkgs.symlinkJoin { name = "avr-monorepo"; paths = [ (packages."x86_64-linux"."flame" processor) (packages."x86_64-linux"."prime-tx" processor) (packages."x86_64-linux"."radio-rx" processor) ]; }; packages."x86_64-linux"."base-attiny85" = (packages."x86_64-linux"."base" attiny85); packages."x86_64-linux"."base" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "base"; src = ./.; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; installPhase = '' mkdir $out cp base/base.h $out/ ''; }; packages."x86_64-linux"."rng" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "rng"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o rng.o -c ${src}/rng/rng.c ''; installPhase = '' mkdir $out cp rng/rng.h rng.o $out/ ''; }; packages."x86_64-linux"."animation" = # { gcc, mcu, chip_select, f_cpu }: { gcc }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; in pkgs.stdenv.mkDerivation rec { name = "animation"; src = ./.; # CFLAGS = cflags { inherit mcu chip_select f_cpu; }; buildPhase = '' ${gcc} -o animation.o -c ${src}/animation/animation.c ''; installPhase = '' mkdir $out cp animation/animation.h animation.o $out/ ''; }; packages."x86_64-linux"."animation-test" = let pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = pkgs.lib; in pkgs.stdenv.mkDerivation rec { name = "animation-test"; src = ./.; buildInputs = [ (packages."x86_64-linux"."animation" { inherit gcc; }) ]; INCLUDE_DIRS = lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); gcc = "${pkgs.gcc}/bin/gcc"; buildPhase = '' ${gcc} ${INCLUDE_DIRS} -o main.o -c ${src}/animation/main.c ${gcc} ${INCLUDE_DIRS} -o animation-test main.o ${OBJECT_FILES} ''; installPhase = '' mkdir $out cp animation-test $out ''; }; packages."x86_64-linux"."sk9822" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "sk9822"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o sk9822.o -c ${src}/sk9822/sk9822.c ''; installPhase = '' mkdir $out cp sk9822/sk9822.h sk9822.o $out/ ''; }; packages."x86_64-linux"."shift-register" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "shift-register"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o shift_register.o -c ${src}/shift_register/shift_register.c ''; installPhase = '' mkdir $out cp shift_register/shift_register.h shift_register.o $out/ ''; }; packages."x86_64-linux"."spi" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "spi"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o spi.o -c ${src}/spi/spi.c ''; installPhase = '' mkdir $out cp spi/spi.h spi.o $out/ ''; }; packages."x86_64-linux"."rfm" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "rfm"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o rfm.o -c ${src}/rfm69hcw/rfm.c ''; installPhase = '' mkdir $out cp rfm69hcw/rfm.h rfm.o $out/ ''; }; packages."x86_64-linux"."display" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "display"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o display.o -c ${src}/display/display.c ''; installPhase = '' mkdir $out cp display/display.h display.o $out/ ''; }; packages."x86_64-linux"."flame" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = pkgs.lib; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "flame"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."sk9822" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."rng" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."animation" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/flame/main.c ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o flame.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex flame.elf flame.hex ''; installPhase = '' mkdir $out cp flame.elf flame.hex $out ''; }; packages."x86_64-linux"."prime-tx" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = pkgs.lib; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "prime-tx"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."rfm" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."display" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/prime-tx/main.c ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o prime-tx.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex prime-tx.elf prime-tx.hex ''; installPhase = '' mkdir $out cp prime-tx.elf prime-tx.hex $out ''; }; packages."x86_64-linux"."radio-rx" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = pkgs.lib; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "radio-rx"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."spi" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."rfm" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."display" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/radio-rx/main.c ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o radio-rx.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex radio-rx.elf radio-rx.hex ''; installPhase = '' mkdir $out cp radio-rx.elf radio-rx.hex $out ''; }; packages."x86_64-linux"."interrupts-standalone" = (packages."x86_64-linux"."interrupts" atmega32u4); packages."x86_64-linux"."interrupts" = { mcu, chip_select, f_cpu }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = pkgs.lib; avr = pkgs.pkgsCross.avr.buildPackages; in pkgs.stdenv.mkDerivation rec { name = "interrupts"; src = ./.; buildInputs = [ (packages."x86_64-linux"."base" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."shift-register" { inherit mcu chip_select f_cpu; }) (packages."x86_64-linux"."display" { inherit mcu chip_select f_cpu; }) ]; CFLAGS = cflags { inherit mcu chip_select f_cpu; }; INCLUDE_DIRS = pkgs.lib.concatStringsSep " " (map (dir: "-I${dir}") buildInputs); OBJECT_FILES = pkgs.lib.concatStringsSep " " (map (dir: "${dir}/*.o") buildInputs); buildPhase = '' ${avr.gcc}/bin/avr-gcc ${CFLAGS} ${INCLUDE_DIRS} -o main.o -c ${src}/interrupts/main.c ${avr.gcc}/bin/avr-gcc ${CFLAGS} -o interrupts.elf main.o ${OBJECT_FILES} $OBJCOPY -O ihex interrupts.elf interrupts.hex ''; installPhase = '' mkdir $out cp interrupts.elf interrupts.hex $out ''; }; devShell."x86_64-linux" = let pkgs = import nixpkgs { system = "x86_64-linux"; }; avr = with pkgs.pkgsCross.avr.buildPackages; [ binutils gcc gdb avrdude simavr gtkwave ]; in pkgs.mkShell { name = "avr-shell"; buildInputs = avr; GCC = pkgs.pkgsCross.avr.buildPackages.gcc; SIMAVR = pkgs.pkgsCross.avr.buildPackages.simavr; }; }; }