From 1a295b9d9f4f27269eb984cadcbec652e18349e1 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Mon, 21 Oct 2024 06:47:47 -0500 Subject: [PATCH 1/9] Organize Nix code a bit --- flake.nix | 132 +++++++++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 70 deletions(-) diff --git a/flake.nix b/flake.nix index e107745..8fa432e 100644 --- a/flake.nix +++ b/flake.nix @@ -208,30 +208,12 @@ cargoArtifacts = boards.attiny85.craneLib.buildDepsOnly boards.attiny85.commonArgs; - pwm-fan-controller = pkgs.callPackage ./boards/attiny85/default.nix { + packages.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; }; - 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"; - }; - 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; - }; apps = { flash = { avrdude = @@ -252,16 +234,26 @@ }; }; }; + 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"; + }; + 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; + }; }; pico = { - nativeBuildInputs = - with pkgs; - [ - elf2uf2-rs - flip-link - probe-rs - ] - ++ commonNativeBuildInputs; craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/pico/rust-toolchain.toml ); @@ -298,22 +290,6 @@ cargoArtifacts = boards.pico.craneLib.buildDepsOnly boards.pico.commonArgs; - pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { - inherit (boards.pico) commonArgs; - inherit (boards.pico) cargoArtifacts; - inherit (boards.pico) craneLib; - }; - devShell = boards.pico.craneLib.devShell { - packages = - boards.pico.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; - }; apps = { flash = { elf2uf2-rs = @@ -352,15 +328,29 @@ }; }; }; + devShell = boards.pico.craneLib.devShell { + packages = + 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; + }; + packages.pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { + inherit (boards.pico) commonArgs; + inherit (boards.pico) cargoArtifacts; + inherit (boards.pico) craneLib; + }; }; qt-py-ch32v203 = { - nativeBuildInputs = - with pkgs; - [ - wchisp - # probe-rs - ] - ++ commonNativeBuildInputs; craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/qt-py-ch32v203/rust-toolchain.toml ); @@ -393,23 +383,6 @@ }; 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 { - packages = - boards.qt-py-ch32v203.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; - }; apps = { flash = { wchisp = @@ -430,6 +403,25 @@ }; }; }; + devShell = boards.qt-py-ch32v203.craneLib.devShell { + packages = + 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; + }; + 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 @@ -548,10 +540,10 @@ formatter = treefmtEval.config.build.wrapper; packages = { default = self.packages.${system}.pwm-fan-controller-attiny85; - pwm-fan-controller-attiny85 = boards.attiny85.pwm-fan-controller; + pwm-fan-controller-attiny85 = boards.attiny85.packages.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; + pwm-fan-controller-pico = boards.pico.packages.pwm-fan-controller; + pwm-fan-controller-qt-py-ch32v203 = boards.qt-py-ch32v203.packages.pwm-fan-controller; # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { # cargoArtifacts = boards.attiny85.cargoArtifacts; From e2d577d12e4aae43b92b70a15303e3c5acdbb5e1 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 11:59:41 -0500 Subject: [PATCH 2/9] Remove unnecessary runtime inputs --- flake.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/flake.nix b/flake.nix index 8fa432e..cb50a14 100644 --- a/flake.nix +++ b/flake.nix @@ -220,7 +220,6 @@ 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 @@ -296,7 +295,6 @@ 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 @@ -314,7 +312,6 @@ 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 @@ -389,7 +386,6 @@ 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 From fe9217eaca1e8921b06c2ab553bd4838dcdf4433 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 15:52:44 -0500 Subject: [PATCH 3/9] Use rec keyword to reduce verbosity --- flake.nix | 94 +++++++++++++++++++++++++------------------------------ 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/flake.nix b/flake.nix index cb50a14..1ad7477 100644 --- a/flake.nix +++ b/flake.nix @@ -124,7 +124,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 +151,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 +177,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 +194,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,13 +206,11 @@ ''; }; - cargoArtifacts = boards.attiny85.craneLib.buildDepsOnly boards.attiny85.commonArgs; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; packages.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; + inherit cargoArtifacts commonArgs craneLib; + inherit (avrCrossPkgs) stdenv; }; apps = { flash = { @@ -233,26 +231,24 @@ }; }; }; - 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"; - }; - 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; + 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 = { + pico = rec { craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/pico/rust-toolchain.toml ); @@ -266,8 +262,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. @@ -287,7 +282,7 @@ ]; }; - cargoArtifacts = boards.pico.craneLib.buildDepsOnly boards.pico.commonArgs; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; apps = { flash = { @@ -325,7 +320,7 @@ }; }; }; - devShell = boards.pico.craneLib.devShell { + devShell = craneLib.devShell { packages = with pkgs; [ @@ -342,12 +337,10 @@ inherit (pre-commit) shellHook; }; packages.pwm-fan-controller = pkgs.callPackage ./boards/pico/default.nix { - inherit (boards.pico) commonArgs; - inherit (boards.pico) cargoArtifacts; - inherit (boards.pico) craneLib; + inherit commonArgs cargoArtifacts craneLib; }; }; - qt-py-ch32v203 = { + qt-py-ch32v203 = rec { craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./boards/qt-py-ch32v203/rust-toolchain.toml ); @@ -361,9 +354,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. @@ -379,7 +370,7 @@ cargoExtraArgs = "--target riscv32imac-unknown-none-elf"; }; - cargoArtifacts = boards.qt-py-ch32v203.craneLib.buildDepsOnly boards.qt-py-ch32v203.commonArgs; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; apps = { flash = { wchisp = @@ -399,7 +390,7 @@ }; }; }; - devShell = boards.qt-py-ch32v203.craneLib.devShell { + devShell = craneLib.devShell { packages = with pkgs; [ @@ -424,16 +415,17 @@ { apps = { inherit (nix-update-scripts.apps.${system}) update-nix-direnv; - attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; + # attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; + attiny85 = boards.attiny85.apps; 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; }; 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 From 9b18bd294722f6e42ea9d12cc63bd47d9feb47e5 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 16:25:29 -0500 Subject: [PATCH 4/9] Generate the apps, devShells, and packages from each of the boards --- flake.nix | 57 ++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/flake.nix b/flake.nix index 1ad7477..d4a1132 100644 --- a/flake.nix +++ b/flake.nix @@ -413,14 +413,9 @@ }; 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; - attiny85 = boards.attiny85.apps; 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; }; checks = { # attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; @@ -509,34 +504,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.packages.pwm-fan-controller; - # todo Why can't it be pwm-fan-controller.pico? - pwm-fan-controller-pico = boards.pico.packages.pwm-fan-controller; - pwm-fan-controller-qt-py-ch32v203 = boards.qt-py-ch32v203.packages.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}.pwm-fan-controller-attiny85; + # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { + # cargoArtifacts = boards.attiny85.cargoArtifacts; + # }); + }; } ); } From 4c13f8a82be8eac1f757a6e31892ca9ae52bbecb Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 16:29:09 -0500 Subject: [PATCH 5/9] Add defaultBoard variable --- flake.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index d4a1132..21f1f2e 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; @@ -415,7 +416,7 @@ { apps = pkgs.lib.attrsets.genAttrs (builtins.attrNames boards) (board: boards.${board}.apps) // { inherit (nix-update-scripts.apps.${system}) update-nix-direnv; - default = self.apps.${system}.attiny85.flash.avrdude; + default = self.apps.${system}.${defaultBoard}.flash.avrdude; }; checks = { # attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; @@ -525,7 +526,7 @@ board: boards.${board}.packages.pwm-fan-controller ) // { - default = self.packages.${system}.pwm-fan-controller-attiny85; + default = self.packages.${system}.${defaultBoard}; # attiny85-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (boards.attiny85.commonArgs // { # cargoArtifacts = boards.attiny85.cargoArtifacts; # }); From 483c3732ec385158ea13bdd109e5269d306639da Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 16:31:23 -0500 Subject: [PATCH 6/9] Use simple and consistent names for apps --- flake.nix | 122 +++++++++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/flake.nix b/flake.nix index 21f1f2e..4cd7617 100644 --- a/flake.nix +++ b/flake.nix @@ -214,23 +214,21 @@ inherit (avrCrossPkgs) stdenv; }; apps = { - flash = { - avrdude = - 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 - ''; - }; - in - { - type = "app"; - program = "${script}/bin/flash-avrdude"; + 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 + ''; }; - }; + in + { + type = "app"; + program = "${script}/bin/flash-avrdude"; + }; }; devShell = craneLib.devShell { env = { @@ -286,40 +284,36 @@ cargoArtifacts = craneLib.buildDepsOnly commonArgs; apps = { - flash = { - elf2uf2-rs = - 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"; + 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 + ''; }; - }; - run = { - probe-rs = - 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"; + 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 = craneLib.devShell { packages = @@ -373,23 +367,21 @@ cargoArtifacts = craneLib.buildDepsOnly commonArgs; apps = { - flash = { - wchisp = - 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"; + 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 = @@ -416,7 +408,7 @@ { apps = pkgs.lib.attrsets.genAttrs (builtins.attrNames boards) (board: boards.${board}.apps) // { inherit (nix-update-scripts.apps.${system}) update-nix-direnv; - default = self.apps.${system}.${defaultBoard}.flash.avrdude; + default = self.apps.${system}.${defaultBoard}.flash; }; checks = { # attiny85-pwm-fan-controller = boards.attiny85.pwm-fan-controller; From 64b56be4c10d1eb57119f3ef1da84655200bab4b Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 16:32:33 -0500 Subject: [PATCH 7/9] Simplify a bit --- flake.nix | 60 ++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/flake.nix b/flake.nix index 4cd7617..378a673 100644 --- a/flake.nix +++ b/flake.nix @@ -213,23 +213,21 @@ inherit cargoArtifacts commonArgs craneLib; inherit (avrCrossPkgs) stdenv; }; - 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 - ''; - }; - in - { - type = "app"; - program = "${script}/bin/flash-avrdude"; + 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 + ''; }; - }; + in + { + type = "app"; + program = "${script}/bin/flash-avrdude"; + }; devShell = craneLib.devShell { env = { # Required by rust-analyzer @@ -366,23 +364,21 @@ }; 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"; + 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 = with pkgs; From c86e0dc149329da741e69d9cb37cf223cd49d408 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 17:07:32 -0500 Subject: [PATCH 8/9] Update GitHub Actions --- .github/workflows/build-attiny85.yaml | 2 +- .github/workflows/build-pico.yaml | 2 +- .github/workflows/build-qt-py-ch32v203.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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: From 921a175b9a8de99ad617fa624d1629b0f280e603 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Wed, 23 Oct 2024 17:08:37 -0500 Subject: [PATCH 9/9] Update justfile targets --- .justfile | 2 +- boards/attiny85/.justfile | 2 +- boards/pico/.justfile | 2 +- boards/qt-py-ch32v203/.justfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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