~jack/misc

misc/ergodox/default.nix -rw-r--r-- 2.5 KiB
008ecc90Jack Kelly Add functional-images to default.nix/ci 30 days ago
                                                                                
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
76
77
78
79
80
81
let
  # We don't use the repo's nixpkgs pin:
  #
  # 1. newer nixpkgs pull in a gcc that causes linker errors which I
  #    don't want to debug
  #
  # 2. newer keyboard firmware has bugs on the Infinity Ergodox that
  #    the maintainer doesn't know how to fix.
  #
  # 3. Keeping up with the latest versions of everything doesn't really
  #    matter if the firmware works right on the keyboard.
  pkgs = import (builtins.fetchTarball {
    url = "https://github.com/nixos/nixpkgs/archive/eda60c51a9e6553631f01053bc05d9c914936249.tar.gz";
    sha256 = "1a26y3r5wcwv5h203jz6j7qsks2qq9s27hk50nl14mjh1abbxyk9";
  }) { };

  controller = pkgs.fetchFromGitHub {
    owner = "kiibohd";
    repo = "controller";
    rev = "c7fb6d1c3be29de1bcb0b9c7201448e66fb2ca33";
    sha256 = "170fz7qa6zdjs4hgal3v0h6nsh99wnscf6kd467frg5d61lyxr5g";
  };

  kll = pkgs.fetchFromGitHub {
    owner = "kiibohd";
    repo = "kll";
    rev = "2062be08e34430d523b20947e9eb5a3ec3948331";
    sha256 = "0xgg12bsg1gq3jfy7g7qyngaxq2nmzl747w1nr2nb85dvqq1mkad";
  };

  static-inline-patch = builtins.fetchurl {
    url = "https://gist.githubusercontent.com/wailashi/3f4322985c2f752bc8e76e1bfb4a127b/raw/1ecfb2bc999b0c32d6d65906873b190865f45e1b/inline_fix.patch";
    sha256 = "0cwza4cmq7knggwkn8pmw9wmranb2h053i8mn8a61g81r377lnp9";
  };
in
  pkgs.stdenv.mkDerivation rec {
    name = "ergodox-infinity-firmware";
    src = ./config;

    buildInputs = with pkgs; [
      cmake dfu-util gcc-arm-embedded gnumake git
    ];

    patches = [ static-inline-patch ];

    unpackPhase = ''
      cp -R ${controller}/* .
      cp -R ${kll} kll
      chmod -R +w .

      # Fix the interpreters
      sed -i '1c#!${pkgs.bash}/bin/bash' Lib/CMake/sizeCalculator
      sed -i '1c#!${pkgs.bash}/bin/bash' Lib/CMake/writer
      sed -i '1c#!${pkgs.python3}/bin/python3' kll/kll.py

      # Copy our config
      cp -v $src/scancode_map.kll Scan/Infinity_Ergodox
      cp -v $src/ergodox-custom.bash Keyboards
      cp -v $src/MDErgo1-Default-*.kll kll/layouts
    '';

    configurePhase = ":";

    buildPhase = ''
      cd Keyboards
      bash ergodox-custom.bash || true
    '';

    installPhase = ''
      mkdir $out
      cp ICED-L.gcc/kiibohd.dfu.bin $out/left.dfu.bin
      cp ICED-R.gcc/kiibohd.dfu.bin $out/right.dfu.bin
    '';

    meta = with pkgs.lib; {
      description = "Firmware for my Infinity Ergodox";
      license = licenses.agpl3Plus;
      maintainers = [ maintainers.endgame ];
      platforms = platforms.all;
    };
  }