Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add treefmt-nix flake-part #13

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions firmware/keyberon/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# Requires:
# - inputs.fenix
# - inputs.naersk
{ lib, inputs, ... }:

{
lib,
inputs,
...
}: {
perSystem = {
pkgs,
system,
Expand Down Expand Up @@ -61,16 +63,16 @@
cargo = toolchain;
rustc = toolchain;
})
.buildPackage {
src = ./.;
overrideMain = x: {
preConfigure = ''
cargo_build_options="$cargo_build_options --package=keyboard-labs-keyberon-rp2040"
'';
};
CARGO_BUILD_TARGET = target;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc}/bin/${target}-gcc";
.buildPackage {
src = ./.;
overrideMain = x: {
preConfigure = ''
cargo_build_options="$cargo_build_options --package=keyboard-labs-keyberon-rp2040"
'';
};
CARGO_BUILD_TARGET = target;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc}/bin/${target}-gcc";
};

keyberon-firmware-stm32f4-elf = let
target = "thumbv7em-none-eabihf";
Expand All @@ -79,47 +81,47 @@
cargo = toolchain;
rustc = toolchain;
})
.buildPackage {
src = ./.;
overrideMain = x: {
preConfigure = ''
cargo_build_options="$cargo_build_options --package=keyboard-labs-keyberon-stm32f4"
'';
};
CARGO_BUILD_TARGET = target;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc}/bin/${target}-gcc";
.buildPackage {
src = ./.;
overrideMain = x: {
preConfigure = ''
cargo_build_options="$cargo_build_options --package=keyboard-labs-keyberon-stm32f4"
'';
};
CARGO_BUILD_TARGET = target;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc}/bin/${target}-gcc";
};

keyberon-firmware-bin = pkgs.runCommand "keyboard-labs-keyberon-firmware-bin" {} ''
mkdir -p $out/bin
export RUSTC=${toolchain}/bin/rustc
mkdir -p $out/bin
export RUSTC=${toolchain}/bin/rustc

env PATH=$PATH:${pkgs.cargo-binutils}/bin \
${pkgs.gnumake}/bin/make \
--file ${./Makefile} \
RP2040_RELEASE_TARGET_DIR=${keyberon-firmware-rp2040-elf}/bin \
STM32F4_RELEASE_TARGET_DIR=${keyberon-firmware-stm32f4-elf}/bin \
DEST_DIR=$out/bin \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.bin") rp2040-bins)} \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.bin") stm32f4-bins)}
'';
env PATH=$PATH:${pkgs.cargo-binutils}/bin \
${pkgs.gnumake}/bin/make \
--file ${./Makefile} \
RP2040_RELEASE_TARGET_DIR=${keyberon-firmware-rp2040-elf}/bin \
STM32F4_RELEASE_TARGET_DIR=${keyberon-firmware-stm32f4-elf}/bin \
DEST_DIR=$out/bin \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.bin") rp2040-bins)} \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.bin") stm32f4-bins)}
'';

keyberon-firmware-uf2 = pkgs.runCommand "" {} ''
mkdir -p $out/bin
mkdir -p $out/bin

cp ${keyberon-firmware-bin}/bin/*.bin $out/bin
cp ${keyberon-firmware-bin}/bin/*.bin $out/bin

env PATH=$PATH:${uf2conv}/bin \
${pkgs.gnumake}/bin/make \
--file ${./Makefile} \
RP2040_RELEASE_TARGET_DIR=${keyberon-firmware-rp2040-elf}/bin \
STM32F4_RELEASE_TARGET_DIR=${keyberon-firmware-stm32f4-elf}/bin \
DEST_DIR=$out/bin \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.uf2") rp2040-bins)} \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.uf2") stm32f4-bins)}
env PATH=$PATH:${uf2conv}/bin \
${pkgs.gnumake}/bin/make \
--file ${./Makefile} \
RP2040_RELEASE_TARGET_DIR=${keyberon-firmware-rp2040-elf}/bin \
STM32F4_RELEASE_TARGET_DIR=${keyberon-firmware-stm32f4-elf}/bin \
DEST_DIR=$out/bin \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.uf2") rp2040-bins)} \
${lib.concatStringsSep " " (map (x: "$out/bin/${x}.uf2") stm32f4-bins)}

rm $out/bin/*.bin
'';
rm $out/bin/*.bin
'';
};
};
}
2 changes: 1 addition & 1 deletion firmware/keyberon/rp2040/src/app_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ pub use keyberon::debounce::Debouncer;

pub use embedded_hal::digital::v2::InputPin;
pub use fugit::ExtU32;
pub use rp_pico::hal;
pub use hal::{
clocks, gpio, gpio::DynPinId, gpio::FunctionSio, gpio::PullDown, gpio::SioInput, pac, sio::Sio,
timer, timer::Alarm, usb::UsbBus,
};
pub use rp_pico::hal;

pub use usb_device::bus::UsbBusAllocator;
pub use usb_device::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion firmware/keyberon/rp2040/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rp2040_hal as hal;
use hal::usb::UsbBus;
use rp2040_hal as hal;

pub use keyboard_labs_keyberon::common::*;

Expand Down
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
};

systems.url = "github:nix-systems/x86_64-linux";

treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {
Expand All @@ -38,12 +43,14 @@
flake-parts,
nixos-generators,
systems,
treefmt-nix,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = import systems;

imports = [
treefmt-nix.flakeModule
./firmware/keyberon/flake-module.nix
];

Expand Down Expand Up @@ -173,6 +180,8 @@
tag = "kicad-7";
};
};

treefmt = import ./treefmt.nix;
};
};
}
7 changes: 7 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
projectRootFile = "flake.nix";
programs.alejandra.enable = true;
programs.rustfmt.enable = true;
programs.shellcheck.enable = true;
programs.shfmt.enable = true;
}
Loading