diff --git a/.github/workflows/build-attiny85.yaml b/.github/workflows/build-attiny85.yaml index afbaec1..351bd99 100644 --- a/.github/workflows/build-attiny85.yaml +++ b/.github/workflows/build-attiny85.yaml @@ -39,7 +39,7 @@ jobs: - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - name: Build - run: nix build '.#pwm-fan-controller-attiny85' + run: nix build '.#attiny85' - name: Upload firmware uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/build-pico.yaml b/.github/workflows/build-pico.yaml index 7c84f0f..7e77953 100644 --- a/.github/workflows/build-pico.yaml +++ b/.github/workflows/build-pico.yaml @@ -41,7 +41,7 @@ jobs: - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - name: Build - run: nix build '.#pwm-fan-controller-pico' + run: nix build '.#pico' - name: Generate UF2 run: nix develop '.#pico' --command elf2uf2-rs result/bin/pwm-fan-controller-pico pwm-fan-controller-pico - name: Upload firmware diff --git a/.github/workflows/build-qt-py-ch32v203.yaml b/.github/workflows/build-qt-py-ch32v203.yaml index 9ae1bf2..e72f742 100644 --- a/.github/workflows/build-qt-py-ch32v203.yaml +++ b/.github/workflows/build-qt-py-ch32v203.yaml @@ -41,7 +41,7 @@ jobs: - uses: DeterminateSystems/nix-installer-action@v14 - uses: DeterminateSystems/magic-nix-cache-action@v8 - name: Build - run: nix build '.#pwm-fan-controller-qt-py-ch32v203' + run: nix build '.#qt-py-ch32v203' - name: Upload firmware uses: actions/upload-artifact@v4 with: diff --git a/.justfile b/.justfile index 66adbf7..152a22e 100644 --- a/.justfile +++ b/.justfile @@ -67,7 +67,7 @@ alias p := package alias pack := package package board="attiny85": - ^nix build ".#pwm-fan-controller-{{ board }}" + ^nix build ".#{{ board }}" alias u := update alias up := update diff --git a/boards/attiny85/.justfile b/boards/attiny85/.justfile index df480a9..3007d95 100644 --- a/boards/attiny85/.justfile +++ b/boards/attiny85/.justfile @@ -19,7 +19,7 @@ run profile="dev": (build profile) # alias pack := package # package: -# ^nix build ".#pwm-fan-controller-attiny85" +# ^nix build ".#attiny85" alias u := update alias up := update diff --git a/boards/pico/.justfile b/boards/pico/.justfile index 5e4bf94..13434bd 100644 --- a/boards/pico/.justfile +++ b/boards/pico/.justfile @@ -32,7 +32,7 @@ alias p := package alias pack := package package: - ^nix build ".#pwm-fan-controller-pico" + ^nix build ".#pico" uf2 profile="dev": #!/usr/bin/env nu diff --git a/boards/qt-py-ch32v203/.justfile b/boards/qt-py-ch32v203/.justfile index 00951a4..07f1ab1 100644 --- a/boards/qt-py-ch32v203/.justfile +++ b/boards/qt-py-ch32v203/.justfile @@ -30,7 +30,7 @@ alias p := package alias pack := package package: - ^nix build ".#pwm-fan-controller-qt-py-ch32v203" + ^nix build ".#qt-py-ch32v203" alias u := update alias up := package diff --git a/flake.nix b/flake.nix index e107745..378a673 100644 --- a/flake.nix +++ b/flake.nix @@ -38,6 +38,7 @@ flake-utils.lib.eachDefaultSystem ( system: let + defaultBoard = "attiny85"; overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit overlays system; @@ -124,7 +125,7 @@ }; }; boards = { - attiny85 = { + attiny85 = rec { # The development shell requires the GCC AVR toolchain to be available. # Thus, this cross-compilation configuration here does the trick. avrCrossPkgs = import nixpkgs { @@ -151,16 +152,16 @@ # The AVR toolchain is unstable and does not include std. targets = [ p.stdenv.hostPlatform.rust.rustcTarget ]; }; - rustToolchain = boards.attiny85.rustToolchainFor pkgs; + rustToolchain = rustToolchainFor pkgs; - craneLib = (crane.mkLib pkgs).overrideToolchain boards.attiny85.rustToolchainFor; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor; nativeBuildInputs = with pkgs; [ avrdude - boards.attiny85.avrCrossPkgs.avrlibc - boards.attiny85.avrCrossPkgs.buildPackages.binutils - boards.attiny85.avrCrossPkgs.buildPackages.gcc + avrCrossPkgs.avrlibc + avrCrossPkgs.buildPackages.binutils + avrCrossPkgs.buildPackages.gcc cargo-binutils # ravedude ] @@ -177,12 +178,12 @@ # See https://github.com/ipetkov/crane/issues/444 filter = path: type: - (boards.attiny85.craneLib.filterCargoSources path type) + (craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "avr-unknown-none-attiny85.json"); }; - cargoVendorDir = boards.attiny85.craneLib.vendorMultipleCargoDeps { - inherit (boards.attiny85.craneLib.findCargoFiles boards.attiny85.commonArgs.src) cargoConfigs; + cargoVendorDir = craneLib.vendorMultipleCargoDeps { + inherit (craneLib.findCargoFiles commonArgs.src) cargoConfigs; cargoLockList = [ ./boards/attiny85/Cargo.lock @@ -194,11 +195,11 @@ # to the repo and import it with `./path/to/rustlib/Cargo.lock` which # will avoid IFD entirely but will require manually keeping the file # up to date! - "${boards.attiny85.rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock" + "${rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock" ]; }; cargoExtraArgs = "--target avr-unknown-none-attiny85.json -Z build-std=core"; - inherit (boards.attiny85) nativeBuildInputs; + inherit nativeBuildInputs; extraDummyScript = '' cp --archive ${./boards/attiny85/avr-unknown-none-attiny85.json} $out/avr-unknown-none-attiny85.json @@ -206,62 +207,45 @@ ''; }; - cargoArtifacts = boards.attiny85.craneLib.buildDepsOnly boards.attiny85.commonArgs; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; - pwm-fan-controller = pkgs.callPackage ./boards/attiny85/default.nix { - inherit (boards.attiny85) cargoArtifacts; - inherit (boards.attiny85) commonArgs; - inherit (boards.attiny85) craneLib; - inherit (boards.attiny85.avrCrossPkgs) stdenv; + packages.pwm-fan-controller = pkgs.callPackage ./boards/attiny85/default.nix { + inherit cargoArtifacts commonArgs craneLib; + inherit (avrCrossPkgs) stdenv; }; - devShell = - with boards.attiny85; - craneLib.devShell { - env = { - # Required by rust-analyzer - # todo Check if I actually need this. - RUST_SRC_PATH = "${boards.attiny85.rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library"; + apps.flash = + let + script = pkgs.writeShellApplication { + name = "flash-avrdude"; + text = '' + ${pkgs.avrdude}/bin/avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:${ + self.packages.${system}.pwm-fan-controller-attiny85 + }/bin/pwm-fan-controller-attiny85.hex:i + ''; }; - packages = - boards.attiny85.nativeBuildInputs - ++ [ - treefmtEval.config.build.wrapper - # Make formatters available for IDE's. - (pkgs.lib.attrValues treefmtEval.config.build.programs) - ] - ++ pre-commit.enabledPackages; - inherit (pre-commit) shellHook; + in + { + type = "app"; + program = "${script}/bin/flash-avrdude"; }; - apps = { - flash = { - avrdude = - let - script = pkgs.writeShellApplication { - name = "flash-avrdude"; - runtimeInputs = with pkgs; [ avrdude ]; - text = '' - ${pkgs.avrdude}/bin/avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:${ - self.packages.${system}.pwm-fan-controller-attiny85 - }/bin/pwm-fan-controller-attiny85.hex:i - ''; - }; - in - { - type = "app"; - program = "${script}/bin/flash-avrdude"; - }; + devShell = craneLib.devShell { + env = { + # Required by rust-analyzer + # todo Check if I actually need this. + RUST_SRC_PATH = "${rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library"; }; + packages = + nativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; }; }; - pico = { - nativeBuildInputs = - with pkgs; - [ - elf2uf2-rs - flip-link - probe-rs - ] - ++ commonNativeBuildInputs; + pico = rec { craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/pico/rust-toolchain.toml ); @@ -275,8 +259,7 @@ src = ./boards/pico; # Don't remove the memory.x linker script file from the sources. filter = - path: type: - (boards.pico.craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); + path: type: (craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); }; # Need to make the memory.x linker script available to the dummy crate. @@ -296,71 +279,61 @@ ]; }; - cargoArtifacts = boards.pico.craneLib.buildDepsOnly boards.pico.commonArgs; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; - pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { - inherit (boards.pico) commonArgs; - inherit (boards.pico) cargoArtifacts; - inherit (boards.pico) craneLib; + apps = { + flash = + let + script = pkgs.writeShellApplication { + name = "flash-elf2uf2-rs"; + text = '' + ${pkgs.elf2uf2-rs}/bin/elf2uf2-rs --deploy ${ + self.packages.${system}.pwm-fan-controller-pico + }/bin/pwm-fan-controller-pico + ''; + }; + in + { + type = "app"; + program = "${script}/bin/flash-elf2uf2-rs"; + }; + run = + let + script = pkgs.writeShellApplication { + name = "run-probe-rs"; + text = '' + ${pkgs.probe-rs}/bin/probe-rs run --chip RP2040 --protocol swd ${ + self.packages.${system}.pwm-fan-controller-pico + }/bin/pwm-fan-controller-pico + ''; + }; + in + { + type = "app"; + program = "${script}/bin/run-probe-rs"; + }; }; - devShell = boards.pico.craneLib.devShell { + devShell = craneLib.devShell { packages = - boards.pico.nativeBuildInputs - ++ [ + with pkgs; + [ + elf2uf2-rs + flip-link + probe-rs treefmtEval.config.build.wrapper # Make formatters available for IDE's. (pkgs.lib.attrValues treefmtEval.config.build.programs) ] + ++ commonArgs.nativeBuildInputs + ++ commonNativeBuildInputs ++ pre-commit.enabledPackages; inherit (pre-commit) shellHook; }; - apps = { - flash = { - elf2uf2-rs = - let - script = pkgs.writeShellApplication { - name = "flash-elf2uf2-rs"; - runtimeInputs = with pkgs; [ elf2uf2-rs ]; - text = '' - ${pkgs.elf2uf2-rs}/bin/elf2uf2-rs --deploy ${ - self.packages.${system}.pwm-fan-controller-pico - }/bin/pwm-fan-controller-pico - ''; - }; - in - { - type = "app"; - program = "${script}/bin/flash-elf2uf2-rs"; - }; - }; - run = { - probe-rs = - let - script = pkgs.writeShellApplication { - name = "run-probe-rs"; - runtimeInputs = with pkgs; [ probe-rs ]; - text = '' - ${pkgs.probe-rs}/bin/probe-rs run --chip RP2040 --protocol swd ${ - self.packages.${system}.pwm-fan-controller-pico - }/bin/pwm-fan-controller-pico - ''; - }; - in - { - type = "app"; - program = "${script}/bin/run-probe-rs"; - }; - }; + packages.pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { + inherit commonArgs cargoArtifacts craneLib; }; }; - qt-py-ch32v203 = { - nativeBuildInputs = - with pkgs; - [ - wchisp - # probe-rs - ] - ++ commonNativeBuildInputs; + qt-py-ch32v203 = rec { craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/qt-py-ch32v203/rust-toolchain.toml ); @@ -374,9 +347,7 @@ src = ./boards/qt-py-ch32v203; # Don't remove the memory.x linker script file from the sources. filter = - path: type: - (boards.qt-py-ch32v203.craneLib.filterCargoSources path type) - || (builtins.baseNameOf path == "memory.x"); + path: type: (craneLib.filterCargoSources path type) || (builtins.baseNameOf path == "memory.x"); }; # Need to make the memory.x linker script available to the dummy crate. @@ -392,60 +363,53 @@ cargoExtraArgs = "--target riscv32imac-unknown-none-elf"; }; - cargoArtifacts = boards.qt-py-ch32v203.craneLib.buildDepsOnly boards.qt-py-ch32v203.commonArgs; - - pwm-fan-controller = pkgs.callPackage ./boards/qt-py-ch32v203/default.nix { - inherit (boards.qt-py-ch32v203) cargoArtifacts; - inherit (boards.qt-py-ch32v203) commonArgs; - inherit (boards.qt-py-ch32v203) craneLib; - }; - devShell = boards.qt-py-ch32v203.craneLib.devShell { + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + apps.flash = + let + script = pkgs.writeShellApplication { + name = "flash-wchisp"; + text = '' + ${pkgs.wchisp}/bin/wchisp flash ${ + self.packages.${system}.pwm-fan-controller-qt-py-ch32v203 + }/bin/pwm-fan-controller-qt-py-ch32v203 + ''; + }; + in + { + type = "app"; + program = "${script}/bin/flash-wchisp"; + }; + devShell = craneLib.devShell { packages = - boards.qt-py-ch32v203.nativeBuildInputs - ++ [ + with pkgs; + [ + wchisp + # probe-rs treefmtEval.config.build.wrapper # Make formatters available for IDE's. (pkgs.lib.attrValues treefmtEval.config.build.programs) ] + ++ commonNativeBuildInputs ++ pre-commit.enabledPackages; inherit (pre-commit) shellHook; }; - apps = { - flash = { - wchisp = - let - script = pkgs.writeShellApplication { - name = "flash-wchisp"; - runtimeInputs = with pkgs; [ wchisp ]; - text = '' - ${pkgs.wchisp}/bin/wchisp flash ${ - self.packages.${system}.pwm-fan-controller-qt-py-ch32v203 - }/bin/pwm-fan-controller-qt-py-ch32v203 - ''; - }; - in - { - type = "app"; - program = "${script}/bin/flash-wchisp"; - }; - }; + packages.pwm-fan-controller = pkgs.callPackage ./boards/qt-py-ch32v203/default.nix { + inherit (boards.qt-py-ch32v203) cargoArtifacts; + inherit (boards.qt-py-ch32v203) commonArgs; + inherit (boards.qt-py-ch32v203) craneLib; }; }; }; in { - apps = { + apps = pkgs.lib.attrsets.genAttrs (builtins.attrNames boards) (board: boards.${board}.apps) // { inherit (nix-update-scripts.apps.${system}) update-nix-direnv; - attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; - default = self.apps.${system}.attiny85.flash.avrdude; - pico.flash.elf2uf2-rs = boards.pico.apps.flash.elf2uf2-rs; - pico.run.probe-rs = boards.pico.apps.run.probe-rs; - qt-py-ch32v203.flash.wchisp = boards.qt-py-ch32v203.apps.flash.wchisp; + default = self.apps.${system}.${defaultBoard}.flash; }; checks = { - attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; - pico-pwm-fan-controller = boards.pico.pwm-fan-controller; - qt-py-ch32v203-pwm-fan-controller = boards.qt-py-ch32v203.pwm-fan-controller; + # attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; + # pico-pwm-fan-controller = boards.pico.pwm-fan-controller; + # qt-py-ch32v203-pwm-fan-controller = boards.qt-py-ch32v203.pwm-fan-controller; attiny85-clippy = boards.attiny85.craneLib.cargoClippy ( boards.attiny85.commonArgs @@ -529,34 +493,32 @@ # partitionType = "count"; # }); }; - devShells = { - attiny85 = boards.attiny85.devShell; - default = pkgs.mkShell { - nativeBuildInputs = - commonNativeBuildInputs - ++ [ - treefmtEval.config.build.wrapper - # Make formatters available for IDE's. - (pkgs.lib.attrValues treefmtEval.config.build.programs) - ] - ++ pre-commit.enabledPackages; - inherit (pre-commit) shellHook; + devShells = + pkgs.lib.attrsets.genAttrs (builtins.attrNames boards) (board: boards.${board}.devShell) + // { + default = pkgs.mkShell { + nativeBuildInputs = + commonNativeBuildInputs + ++ [ + treefmtEval.config.build.wrapper + # Make formatters available for IDE's. + (pkgs.lib.attrValues treefmtEval.config.build.programs) + ] + ++ pre-commit.enabledPackages; + inherit (pre-commit) shellHook; + }; }; - pico = boards.pico.devShell; - qt-py-ch32v203 = boards.qt-py-ch32v203.devShell; - }; formatter = treefmtEval.config.build.wrapper; - packages = { - default = self.packages.${system}.pwm-fan-controller-attiny85; - pwm-fan-controller-attiny85 = boards.attiny85.pwm-fan-controller; - # todo Why can't it be pwm-fan-controller.pico? - pwm-fan-controller-pico = boards.pico.pwm-fan-controller; - pwm-fan-controller-qt-py-ch32v203 = boards.qt-py-ch32v203.pwm-fan-controller; - - # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { - # cargoArtifacts = boards.attiny85.cargoArtifacts; - # }); - }; + packages = + pkgs.lib.attrsets.genAttrs (builtins.attrNames boards) ( + board: boards.${board}.packages.pwm-fan-controller + ) + // { + default = self.packages.${system}.${defaultBoard}; + # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { + # cargoArtifacts = boards.attiny85.cargoArtifacts; + # }); + }; } ); }