New nix-based build workflow #74
Replies: 3 comments 5 replies
-
This is fantastic. I can’t wait to try it out this weekend. Thank you for sharing and documenting it. It’s going to be awesome on macOS to have a local toolchain that doesn’t require docker. |
Beta Was this translation helpful? Give feedback.
-
That's awesome! I've been running my ZMK configs through zmk-nix - I assume you've looked at that already? |
Beta Was this translation helpful? Give feedback.
-
I added some automated tests to validate the local build environment for all major nix systems ( As of today the tests are passing for all tested systems. So this should work on all Linux and macOS systems. (Windows is indirectly supported via WSL.) One small caveat is that I had to disable |
Beta Was this translation helpful? Give feedback.
-
I had some fun re-organizing my ZMK workspace, leveraging
west
to set everything up. While at it, I also moved from adocker
-based workflow to anix
-based workflow. I updated the readme with technical details. Let me add a bit more motivation and background here.Does it affect past or future forks of this repo?
The short answer is: No! The new workflow is completely optional. The Github Actions workflow and traditional local development workflows all continue to work.
The only caveat is that I deleted my old
docker
-based build-scripts from this repository since I will no longer maintain them. If you still need them, you can download them from the latest commit before I deleted them.What do I mean by ZMK workspace?
After fully embracing ZMK's module system, I decided to make my
zmk-config
(i.e., this repository) the entry point for everything ZMK. So instead of having multiple ZMK-related repositories scattered across my filesystem, they now all live inside a singlezmk-workspace
:Technically,
zmk-workspace
is the same as thiszmk-config
(I decided to rename it on my computer to reflect it's new bigger role). This may seem odd at first. After all, neitherzmk
nor any of thezmk-modules
live in this repository. What ties everything together is mywest.yml
, which defines the structure of the workspace. In my opinion, usingwest
to organize the workspace has several advantages:zmk
,zephyr
and allzmk-modules
) are fully functionalgit
repos - stepping inside any of these subdirectories, one can switchzmk
branches as usual, commit changes, merge PRs , etc. It's sort of likegit-submodules
, just better :)Why a nix-based workflow?
Honestly, because it's awesome! Nix is a package manager that can be installed with a single command in macOS and Linux or WSL (not to be confused with nixOS, which is a operation system based on Nix). The major advantage is that it allows creating virtual, fully reproducible shells that isolate arbitrary development environments from the rest of the system.
Think about it as a Python
venv
but for the entire toolchain (in our case that's thezephyr-sdk
,cmake
,dtc
, apython
environment withwest
and various other packages, and evenkeymap-drawer
). Likevenv
, the nix environment is completely isolated from the rest of the system. In that sense, it serves the same purpose as adocker
container. But unlikedocker
, it spawns a native shell that we can interact with, without any added friction.Sounds interesting but is it really convenient?
Here's where two additional tools come in:
direnv
andjust
. The former completely automates the whole setup and activation of the nix-environment. The first time wecd
into ourzmk-workspace
, it automatically creates and activates the nix-environment. After that, the environment gets automatically activated and deactivated every time I enter and leave the workspace. (The environment is cached, so there is no waiting after it has been created the first time).The second tool that I find really useful is
just
. Think about it as aMakefile
on steroids. I have it set up to make various zmk-related recipes readily available from anywhere within the workspace.For instance, typing
just build all
will parsebuild.yaml
and build the firmware for all board and shield combinations, just like the Github Actions workflow does. It also supports matching of build targets. For example,just build zen
will build any board and shield combination matchingzen
- in my case that'scorneish_zen_v2_left
andcorneish_zen_v2_right
.On what platforms does it work?
It should run on all Linux and macOS systems (both Intel and Arm). Windows is indirectly supported via WSL. Currently, there is one known issue with
keymap-drawer
on arm-based Linux-systems, which is currently disabled.For the current status of any system, see the latest run of the test suite.
Where do I get all the goodies?
Glad you're convinced :) I added step-by-step instructions to the readme. It's really not that much, most of the setup is automated (mainly through
flake.nix
, which sets upwest
, thezephyr-sdk
and build tools, and through thejust init
recipe, which sets up the workspace).Beta Was this translation helpful? Give feedback.
All reactions