Build QMK with Nix: QMix

Hey for those people who like using Nix, I build helper functions to produce reproducable QMK firmware.

Back when I started to use QMK I could not figure out how to nixify my QMK firmware. That is why I build QMix. Using it’s overlay you can use the buildQmkFirmware function to very easily build QMK firmware. It’s main features include:

  • Absolute repoducibility using nix
  • Pinning to an exact QMK firmware version
  • using userspace as well as in repo QMK keyboards

and more! If you want to see an example of how easy it is:

pkgs.buildQmkFirmware {
  keyboard = "my-keyboard/rev1"; # or chose a keyboard in the main repo. <required>
  keymap = "default"; # or use a custom keymap. [optional]
  qmkFirmware = "latest"; # or use 'v0', 'v0.3', or 'v0.3.3' etc. [optional]
  qmkUserspace = ./some/path; # or ommit to use only the main repo. [optional]
  split = false; # supports split keyboards as well! [optional]
  ...
}

Let me know if you have thoughts or issues!

20 Likes

Hey. Thank you for sharing! I don’t have such hardware. Would you consider upstreaming this to Nixpkgs?

Nice project!

I will have to look at it closer, and how I can use it to build my moonlanders config!

Once I manage to build the downloaded configuration I can finally start actually tweaking it in code, rather than via the web interface!

Sounds like it might be useful for some. If you’ve come upon this thread because you’re more interested in learning how to write a derivation for your QMK firmware yourself, though, this might be more useful (though it’s on an old ZSA fork of qmk-firmware), as QMix is a lot more complex in its engineering.

At this moment in time, I’m not actually sure if it supports JSON as I’ve never worked with it. So the documentation does not mention it, and so this might require some reverse engineering. Open an issue if you need help with it, and I’ll try my best to help you out!

I thought it would be too specialized to belong in NixPkgs, especially because my implementation adds around 1700 derivations to make the consumers life easier. I’ve added a derivation for every QMK version possible, so that someone can just type “latest” or “v0.33.4” and not have to worry about fetching and hashes etc.

If you think they might be interested, I’m more then willing to upstream it. I just don’t know how. I’ve only up streamed packages before.

It’s a nice suggestion! Though I don’t think that one works for 90% the keyboards. It only supports .bin outputs, it does not support QMK userspaces, or selecting any modern version of the QMK repo. But then again, I am biased.

Yeah, it’s an example, not a solution. But an example often helps a lot in terms of finding some of the important “fixes”, like env.SKIP_GIT = 1;. Reading QMix’s code wouldn’t really help you find that.

1 Like

Definitely! I didn’t know about SKIP_GIT at all, and I am going to steal it if you don’t mind! :slight_smile:

Of course! That’s why I put it out there. :slight_smile:

1 Like

The web-editor of the moonlander does not offer JSON to download, you can download the actual C code, and have to link and build against a ZSA fork of QMK.

Hey, nice job!

I made something very similar a little while ago, and some folks came later adding support for flashing and IDE completion:

Feel free to take a look – maybe it’s worth considering joining efforts at some point :slight_smile:

4 Likes

this is very neat, thank you for sharing it! reminds me that I want to get my stuff out of a fork and into a userspace repo at some point too…

Oh wow that’s really cool actually! very polished! Especially the IDE completion is a nice touch. I’m gonna add that too if you don’t mind! I see that you’re missing the userspace and a couple of other features from QMix though so if you want you can copy them!

No worries, my pleasure! Let me know how well it works! It’s currently only tested using CI, not with real people’s creations, so if you find quirks I’ll be more then happy to take a look at them!

Now we just need to do this for katana and kmonad