summary refs log tree commit diff stats
path: root/package.nix
blob: 8cde8bf5d5c97bd3582547b0a8b9f6241fed1eeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
  stdenv,
  fetchgit,
  # deps
  qmk,
  gnumake,
  git,
}: let
  layout_id = "KWBYA";
  layout_geometry = "moonlander";
  firmware_version = "24";
in
  stdenv.mkDerivation
  {
    pname = "moonlander-layout";
    version = "25";

    src = fetchgit {
      url = "https://github.com/qmk/qmk_firmware/";
      rev = "refs/tags/0.27.1";
      hash = "sha256-Chq4R8rICY1eyt5r2dkPm34zDOm6TqPKAXQWPp0nByA=";

      fetchSubmodules = true;

      # This allows for a compiled in version
      leaveDotGit = true;
    };

    nativeBuildInputs = [
      gnumake
      qmk
      git
    ];

    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
        make "$keyboard_folder:${layout_id}"

        runHook postBuild
      '';
    installPhase = ''
      runHook preInstall

      mkdir --parents "$out/binary_output"

      cp --recursive "./.build" "$out/build"
      rm --recursive "$out/build/obj_zsa_moonlander_${layout_id}"

      ln --symbolic --relative "$out/build/zsa_moonlander_${layout_id}.bin" "$out/binary_output/"

      runHook postInstall
    '';
  }