Skip to content

Commit

Permalink
Add nix build tooling
Browse files Browse the repository at this point in the history
This patch adds a nix-shell environment and a Makefile to build the
firmware binaries using Nix.  The idea is to make it easier to build a
previous version of the firmware the same way it was built at the time
of development.  Potentially, it could also be used with the CI for
reproducible builds (to be investigated).
  • Loading branch information
robin-nitrokey committed Nov 14, 2023
1 parent 28a46ae commit 056b62c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/nix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.bin
23 changes: 23 additions & 0 deletions utils/nix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RUNNER ?= ../../runners/embedded
RUNNER_NK3AM ?= $(RUNNER)/artifacts/runner-nrf52-bootloader-nk3am.bin
RUNNER_NK3XN ?= $(RUNNER)/artifacts/runner-lpc55-nk3xn.bin

.PHONY: all
all:
@nix-shell --pure --run "make binaries"
@ls -l *.bin

.PHONY: binaries
binaries:
$(MAKE) -C $(RUNNER) build-nk3xn
cp $(RUNNER_NK3XN) firmware-nk3xn.bin
$(MAKE) -C $(RUNNER) build-nk3xn FEATURES=provisioner
cp $(RUNNER_NK3XN) provisioner-nk3xn.bin
$(MAKE) -C $(RUNNER) build-nk3xn FEATURES=test
cp $(RUNNER_NK3XN) firmware-test-nk3xn.bin
$(MAKE) -C $(RUNNER) build-nk3am.bl
cp $(RUNNER_NK3AM) firmware-nk3am.bin
$(MAKE) -C $(RUNNER) build-nk3am.bl FEATURES=provisioner
cp $(RUNNER_NK3AM) provisioner-nk3am.bin
$(MAKE) -C $(RUNNER) build-nk3am.bl FEATURES=test
cp $(RUNNER_NK3AM) firmware-test-nk3am.bin
35 changes: 35 additions & 0 deletions utils/nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Commit from 2023-11-10
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/da4024d0ead5d7820f6bd15147d3fe2a0c0cec73.tar.gz") {} }:

let
fenix = pkgs.callPackage
(pkgs.fetchFromGitHub {
owner = "nix-community";
repo = "fenix";
# commit from: 2023-11-01
rev = "1a92c6d75963fd594116913c23041da48ed9e020";
hash = "sha256-L3vZfifHmog7sJvzXk8qiKISkpyltb+GaThqMJ7PU9Y=";
})
{ };
toolchain = fenix.fromToolchainFile {
dir = ../..;
sha256 = "sha256-Q9UgzzvxLi4x9aWUJTn+/5EXekC98ODRU1TwhUs9RnY=";
};
in
pkgs.mkShell {
name = "nk3";
nativeBuildInputs = with pkgs.buildPackages; [
flip-link
gcc-arm-embedded
git
gnumake
libclang
toolchain
(python3.withPackages(ps: with ps; [ toml ]))
];

shellHook = ''
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
export TARGET_CC=arm-none-eabi-gcc
'';
}

0 comments on commit 056b62c

Please sign in to comment.