Flashing QMK keyboard with Nix

I have an ErgoDox EZ which I haven’t flashed for years, but am now thinking of fiddling with the layout again. Looking at the notes I made describing the various hoops that need to be jumped through in order to compile a new layout from C sources and then flash the keyboard, gives me a strong urge to wrap it all up in a flake.

Does anyone have any wisdom to offer in this area?

It seems that the recommended procedure has changed significantly since I last looked. Very briefly, it goes something like this

  1. qmk setup (Clones qmk/qmk_firmware repo with submodules, and verifies that everything looks OK.)
  2. qmk compile (ignoring injection of my own keymaps, for now)
  3. qmk flash

Crucially, the ‘check that everything looks OK’ part in step 1 requires udev rules to be set. On NixOS this can be done by including pkgs.qmk-udev-rules in services.udev.packages, but I have no idea how to approach this in the sandboxed nix build environment.

Adding

    qmk-firmware = {
      flake = false;
      url = "https://github.com/qmk/qmk_firmware.git";
      ref = "refs/tags/0.24.6";
      type = "git";
      submodules = true;
    };

as a flake input and using it as the src of a derivation, seems to get the git repo and all its submodules (with version pinning in flake.lock) but the verification step of qmk setup fails when pointed at this clone. Furthermore, I don’t see how I would inject my own keymap into this clone which would be in the immutable Nix store.

I have an xbows nature and compile qmk for it, but despite using nix for as much as possible, I simply took the container route as I had to wait forever for the compilers to be compiled. The qmk tool itself is fine - it’s everything around compiling for the MCU on your keyboard that’s painful.

Take a look at qmk_firmware/flake.nix at b9d97d2b49995a5647baade7cb343d7ee611d3e3 · RyanGibb/qmk_firmware · GitHub

Interesting.

How does it work without any flake inputs?

With GitHub - NixOS/flake-registry: Global registry of Nix flakes