From e362fea19ae4cd41e21bb2d4de1942b66ea3fddd Mon Sep 17 00:00:00 2001 From: Brian Romanko Date: Mon, 15 Nov 2021 08:34:46 -0800 Subject: [PATCH 1/6] Add nix-shell --- .envrc | 1 + .gitignore | 3 ++- shell.nix | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..1d953f4b --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore index 93c801d9..a7e6d4f7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /zmk-config /build *.DS_Store -__pycache__ \ No newline at end of file +__pycache__ +/.direnv diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..a4457345 --- /dev/null +++ b/shell.nix @@ -0,0 +1,23 @@ +{ pkgs ? import { } }: + +with pkgs; + +let inherit (lib) ; +in mkShell { + buildInputs = [ + cmake + ninja + python3 + ccache + dtc + dfu-util + gcc-arm-embedded + python38Packages.west + python38Packages.pyelftools + ]; + + shellHook = '' + export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb + export GNUARMEMB_TOOLCHAIN_PATH=${pkgs.gcc-arm-embedded} + ''; +} From 29af1411ce848a4c2ad31eede8e5a6dfd45604eb Mon Sep 17 00:00:00 2001 From: Brian Romanko Date: Fri, 10 Dec 2021 08:35:08 -0800 Subject: [PATCH 2/6] Move envrc to envrc-nix This will allow people to use other envrc files if they do not use nix. This file can simply be symlinked to `.envrc`. --- .envrc => .envrc-nix | 0 .gitignore | 1 + 2 files changed, 1 insertion(+) rename .envrc => .envrc-nix (100%) diff --git a/.envrc b/.envrc-nix similarity index 100% rename from .envrc rename to .envrc-nix diff --git a/.gitignore b/.gitignore index a7e6d4f7..66ae8e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.DS_Store __pycache__ /.direnv +.envrc From 23c2ef05568c81868cf7651f502f552d323c6479 Mon Sep 17 00:00:00 2001 From: Brian Romanko Date: Fri, 10 Dec 2021 09:21:39 -0800 Subject: [PATCH 3/6] Add nix flake support Now that nix 2.4 is out, flakes are no longer experimental. --- flake.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ flake.nix | 11 +++++++++++ shell.nix | 6 +++--- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..95b64bf1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1638910453, + "narHash": "sha256-fofA4tsAAdNgE+9Py0VsVbyX2ZQkgV+CVqQKGBA/dLE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f225322e3bea8638304adfcf415cd11de99f2208", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..1499b6c0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,11 @@ +{ + description = "# Zephyrâ„¢ Mechanical Keyboard (ZMK) Firmware"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { devShell = import ./shell.nix { inherit pkgs; }; }); +} diff --git a/shell.nix b/shell.nix index a4457345..145f7115 100644 --- a/shell.nix +++ b/shell.nix @@ -6,14 +6,14 @@ let inherit (lib) ; in mkShell { buildInputs = [ cmake - ninja - python3 ccache + ninja dtc dfu-util gcc-arm-embedded + python3 python38Packages.west - python38Packages.pyelftools + python38Packages.pip ]; shellHook = '' From 5ea1fa86ee32d6407a349ef2653d7ad1a7b8001d Mon Sep 17 00:00:00 2001 From: Dom H Date: Sat, 4 Dec 2021 10:56:54 +0000 Subject: [PATCH 4/6] fix(setup): Add zephyr requirements to nix-shell Use mach-nix to handle zephyr's python requirements. --- shell.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shell.nix b/shell.nix index 145f7115..e34f20c8 100644 --- a/shell.nix +++ b/shell.nix @@ -3,6 +3,15 @@ with pkgs; let inherit (lib) ; + mach-nix = import (builtins.fetchGit { + url = "https://github.com/DavHau/mach-nix"; + ref = "master"; + }) { + python = "python3"; + }; + machNix = mach-nix.mkPython rec { + requirements = builtins.readFile ./zephyr/scripts/requirements-base.txt; + }; in mkShell { buildInputs = [ cmake @@ -11,9 +20,7 @@ in mkShell { dtc dfu-util gcc-arm-embedded - python3 - python38Packages.west - python38Packages.pip + machNix ]; shellHook = '' From baed737e2f8a17f208090aabbffb41e12b923b39 Mon Sep 17 00:00:00 2001 From: Dom H Date: Sun, 16 Jan 2022 18:44:45 +0000 Subject: [PATCH 5/6] fix(setup): Fetch Zephyr requirements from URL The requirements cannot be read from the file in `./zephyr/` because this directory does not yet exist in a clean repo. Fetching the requirements file from an upstream URL is consistent with how the ZMK docker image does it: https://github.com/zmkfirmware/zmk-docker/blob/25972e7aad57a2b48f6141185711943cf76fc03b/Dockerfile#L26-L27 --- shell.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index e34f20c8..f36dc2e2 100644 --- a/shell.nix +++ b/shell.nix @@ -9,8 +9,12 @@ let inherit (lib) ; }) { python = "python3"; }; + zephyr-requirements = fetchurl { + url = "https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v2.5.0/scripts/requirements-base.txt"; + sha256 = "919a78ba9457a8e55451450329158ff7fdcbc4a2ddb0dd76ea804c3b04a3c6c6"; + }; machNix = mach-nix.mkPython rec { - requirements = builtins.readFile ./zephyr/scripts/requirements-base.txt; + requirements = builtins.readFile zephyr-requirements; }; in mkShell { buildInputs = [ From 8c8c245ba8cf74f0d6efda6272da3441c1abedc8 Mon Sep 17 00:00:00 2001 From: Dom H Date: Mon, 17 Jan 2022 05:20:07 +0000 Subject: [PATCH 6/6] refactor(setup): More descriptive variable name --- shell.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell.nix b/shell.nix index f36dc2e2..db301abf 100644 --- a/shell.nix +++ b/shell.nix @@ -13,7 +13,7 @@ let inherit (lib) ; url = "https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v2.5.0/scripts/requirements-base.txt"; sha256 = "919a78ba9457a8e55451450329158ff7fdcbc4a2ddb0dd76ea804c3b04a3c6c6"; }; - machNix = mach-nix.mkPython rec { + python-pkgs = mach-nix.mkPython rec { requirements = builtins.readFile zephyr-requirements; }; in mkShell { @@ -24,7 +24,7 @@ in mkShell { dtc dfu-util gcc-arm-embedded - machNix + python-pkgs ]; shellHook = ''