Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Dockerfile that allows efficient local builds #9

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*~
*.uf2
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM nixpkgs/nix:nixos-23.11

ENV PATH=/root/.nix-profile/bin:/usr/bin:/bin

RUN <<EOF
set -euo pipefail
nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use moergo-glove80-zmk-dev
mkdir /config
# Mirror ZMK repository to make it easier to reference both branches and
# tags without remote namespacing
git clone --mirror https://github.com/moergo-sc/zmk /zmk
GIT_DIR=/zmk git worktree add --detach /src
EOF

# Prepopulate the container's nix store with the build dependencies for the main
# branch and the most recent three tags
RUN <<EOF
cd /src
for tag in main $(git tag -l --sort=committerdate | tail -n 3); do
git checkout -q --detach $tag
nix-shell --run true -A zmk ./default.nix
done
EOF

COPY --chmod=755 <<EOF /bin/entrypoint.sh
#!/usr/bin/env bash
set -euo pipefail
: "\${BRANCH:=main}"

echo "Checking out \$BRANCH from moergo-sc/zmk" >&2
cd /src
git fetch origin
git checkout -q --detach "\$BRANCH"

echo 'Building Glove80 firmware' >&2
cd /config
nix-build ./config --arg firmware 'import /src/default.nix {}' -j2 -o /tmp/combined --show-trace
install -o "\$UID" -g "\$GID" /tmp/combined/glove80.uf2 ./glove80.uf2
EOF

ENTRYPOINT ["/bin/entrypoint.sh"]

# Run build.sh to use this file
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -euo pipefail

IMAGE=glove80-zmk-config-docker
BRANCH="${1:-main}"

docker build -t "$IMAGE" .
docker run --rm -v "$PWD:/config" -e UID="$(id -u)" -e GID="$(id -g)" -e BRANCH="$BRANCH" "$IMAGE"
5 changes: 3 additions & 2 deletions config/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {}
, firmware ? import ../src {}
}:

let
firmware = import ../src {};
config = ./.;

glove80_left = firmware.zmk.override { board = "glove80_lh"; keymap = "${config}/glove80.keymap"; kconfig = "${config}/glove80.conf"; };
Expand Down
Loading