2024-11-21 13:19:21 +00:00
|
|
|
{ pkgs, ... }:
|
|
|
|
|
2025-01-19 13:49:10 +00:00
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
writeShellApplication {
|
2024-11-21 13:19:21 +00:00
|
|
|
name = "build-glove80";
|
|
|
|
|
2025-01-19 13:49:10 +00:00
|
|
|
runtimeInputs = [
|
2024-11-21 13:19:21 +00:00
|
|
|
cachix
|
|
|
|
git
|
|
|
|
nix
|
|
|
|
];
|
|
|
|
|
|
|
|
text = ''
|
|
|
|
BRANCH="''${1:-main}"
|
|
|
|
SRC_DIR="''${PWD}/src"
|
|
|
|
CONFIG_DIR="''${PWD}/config"
|
|
|
|
NIX_FILE="''${CONFIG_DIR}/default.nix"
|
|
|
|
|
|
|
|
# Ensure cachix is configured
|
|
|
|
echo "Using moergo-glove80-zmk-dev cache"
|
|
|
|
cachix use moergo-glove80-zmk-dev
|
|
|
|
|
|
|
|
# Clone or update the ZMK repository
|
|
|
|
if [ ! -d "$SRC_DIR" ]; then
|
|
|
|
echo "Cloning ZMK repository into ./src..."
|
|
|
|
git clone https://github.com/moergo-sc/zmk "$SRC_DIR"
|
|
|
|
else
|
|
|
|
echo "Updating ZMK repository in ./src..."
|
|
|
|
git -C "$SRC_DIR" fetch --all
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Checkout the specified branch or tag
|
|
|
|
echo "Checking out branch/tag: $BRANCH in ./src"
|
|
|
|
git -C "$SRC_DIR" checkout -q --detach "$BRANCH"
|
|
|
|
|
|
|
|
# Build firmware using Nix
|
|
|
|
echo "Building firmware from: $NIX_FILE"
|
|
|
|
nix-build "$NIX_FILE" --arg firmware "import ''${SRC_DIR}/default.nix {}" -j2 -o ./glove80.uf2 --show-trace
|
|
|
|
|
|
|
|
echo "Firmware built successfully: $(realpath ./glove80.uf2)"
|
|
|
|
'';
|
|
|
|
}
|