summary refs log tree commit diff stats
path: root/package.nix
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-09 19:43:04 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-09 19:43:04 +0100
commit5afb50b1e8a737a4b906d2cdda22888eca8468a7 (patch)
tree4e0372adb28d4185bf25472d377fd53d38d013e6 /package.nix
downloadqmk_layout-5afb50b1e8a737a4b906d2cdda22888eca8468a7.zip
build: Add infrastructure
Diffstat (limited to 'package.nix')
-rw-r--r--package.nix67
1 files changed, 67 insertions, 0 deletions
diff --git a/package.nix b/package.nix
new file mode 100644
index 0000000..807a57c
--- /dev/null
+++ b/package.nix
@@ -0,0 +1,67 @@
+{
+  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
+    '';
+  }