{ stdenv, fetchgit, # deps qmk, gnumake, }: let layout_id = "KWBYA"; layout_geometry = "moonlander"; FIRMWARE_VERSION = "24"; in stdenv.mkDerivation { pname = "moonlander-layout"; version = "25"; src = fetchgit { url = "https://github.com/zsa/qmk_firmware"; rev = "4ae6ea9679fbd4277caa1036d326ddfce278b4d2"; # 2024-12-09T17:43:04 CET hash = "sha256-c+fojw64dHIYoO20cO9Nd1pnQwBDPPbrh6Erf9QTyGw="; fetchSubmodules = true; }; nativeBuildInputs = [ gnumake qmk ]; buildPhase = /* bash */ '' runHook preBuild ## Set keyboard directory and make prefix based on firmware version if [ "${FIRMWARE_VERSION}" -ge 24 ]; then keyboard_directory="keyboards/zsa" keyboard_folder="zsa/${layout_geometry}" else keyboard_directory="keyboards" keyboard_folder="${layout_geometry}" fi ## Copy layout files to the qmk folder key_dir="$keyboard_directory/${layout_geometry}/keymaps/${layout_id}" [ -d "$key_dir" ] && rm --recursive "$key_dir" mkdir --parents "$(dirname "$key_dir")" cp --recursive "${./src}" "$key_dir" ## Build the layout # qmk setup "zsa/qmk_firmware" -b 'firmware${FIRMWARE_VERSION}' -y make "$keyboard_folder:${layout_id}" runHook postBuild ''; installPhase = '' runHook preInstall mkdir --parents "$out/binary_output" cp "./.build/zsa_moonlander_${layout_id}.bin" "$out/binary_output/" runHook postInstall ''; }