{ stdenv, fetchgit, lib, writeText, # deps qmk, gnumake, git, fd, }: let layout_id = "soispha"; # The last two entries need to exist, so that the `qmk` cli accepts the repo as _the_ # `qmk_firmware` repository. paths_to_keep = writeText "files_to_keep" '' builddefs/ data/ drivers/ lib/ platforms/ quantum/ tmk_core/ version/ Makefile paths.mk qmk_version requirements-dev.txt requirements.txt ''; version = builtins.toString (import ./version.nix); in stdenv.mkDerivation { pname = "moonlander-layout"; inherit version; src = fetchgit { url = "https://github.com/qmk/qmk_firmware"; rev = "refs/tags/0.27.1"; hash = "sha256-pVKZsfQypW26oWD9CLevCW7Z3fF4JbcY+Bo1tTLgBGk="; fetchSubmodules = true; # This allows for a compiled-in version leaveDotGit = true; deepClone = true; postFetch = '' set -e cd "$out" git_desc() { ${lib.getExe git} describe --abbrev=0 --always --dirty --tags } mkdir --parents $out/version # For the 'version.h' file git_desc > $out/version/git_version ${lib.getExe git} rev-parse HEAD > $out/version/git_qmk_hash (cd lib/chibios && git_desc > $out/version/chibios_version) (cd lib/chibios-contrib && git_desc > $out/version/chibios_contrib_version) ${lib.getExe git} describe --abbrev=0 --tags > $out/version/qmk_version_make ${lib.getExe fd} . --max-depth 1 --hidden | while read -r file; do if ! grep "^$file" ${paths_to_keep}; then rm --recursive "$file"; fi done ''; }; nativeBuildInputs = [ gnumake qmk git fd ]; patchPhase = '' substituteInPlace ./lib/python/qmk/cli/generate/version_h.py \ --replace-fail 'git_version = "NA"' "git_version = '$(cat ./version/git_version)-${version}'" \ --replace-fail 'git_qmk_hash = "NA"' "git_qmk_hash = '$(cat ./version/git_qmk_hash)'" \ --replace-fail 'chibios_version = "NA"' "chibios_version = '$(cat ./version/chibios_version)'" \ --replace-fail 'chibios_contrib_version = "NA"' "chibios_contrib_version = '$(cat ./version/chibios_contrib_version)'" # substituteInPlace ./lib/python/qmk/info.py \ # --replace-fail "'keyboard_name': str(keyboard)," "" ''; buildPhase = /* bash */ '' runHook preBuild # Set the qmk_version without having to include the `.git` directory. QMK_VERSION="$(cat ./version/git_version)-${version}" SKIP_VERSION="true" export QMK_VERSION export SKIP_VERSION ## Copy layout files to the qmk folder key_dir="keyboards/zsa/moonlander" [ -d "$key_dir" ] && rm --recursive "$key_dir" mkdir --parents "$(dirname "$key_dir")" cp --recursive "${./src}" "$key_dir" # Needed by the `qmk` cli tool mkdir --parents ./layouts/default ## Build the layout mkdir ./.build make "zsa/moonlander:${layout_id}" | tee ./.build/make_build.log runHook postBuild ''; installPhase = '' runHook preInstall set -e # mkdir --parents "$out/raw_output" # cp --recursive "." "$out/raw_output" mkdir --parents "$out/binary_output" cp --recursive "./.build" "$out/build" fd . $out/build --extension d --extension o --hidden --exec rm while [ $(fd . $out/build --type empty --type directory --hidden | wc -l) -ne 0 ]; do fd . $out/build --type empty --type directory --hidden --exec rm --dir done ln --symbolic --relative "$out/build/zsa_moonlander_${layout_id}.bin" "$out/binary_output/zsa_moonlander_$QMK_VERSION.bin" runHook postInstall ''; }