-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
172 lines (154 loc) · 4.18 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Basic configuration for Zephyr development.
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz") { } }:
let
pp = pkgs.python3.pkgs;
imgtool = pp.buildPythonPackage rec {
version = "1.10.0";
pname = "imgtool";
src = pp.fetchPypi {
inherit pname version;
sha256 = "sha256-A7NOdZNKw9lufEK2vK8Rzq9PRT98bybBfXJr0YMQS0A=";
};
propagatedBuildInputs = with pp; [
cbor2
click
intelhex
cryptography
];
doCheck = false;
pythonImportsCheck = [
"imgtool"
];
};
python-packages = pkgs.python3.withPackages (p: with p; [
pip
autopep8
pyelftools
pyyaml
pykwalify
canopen
packaging
progress
psutil
anytree
intelhex
west
imgtool
cryptography
intelhex
click
cbor2
# For mcuboot CI
toml
# For twister
tabulate
ply
# For TFM
pyasn1
graphviz
jinja2
requests
beautifulsoup4
# These are here because pip stupidly keeps trying to install
# these in /nix/store.
wcwidth
sortedcontainers
]);
# Build the Zephyr SDK as a nix package.
new-zephyr-sdk-pkg =
{ stdenv
, fetchurl
, which
, python38
, wget
, file
, cmake
, libusb
, autoPatchelfHook
}:
let
version = "0.16.4";
arch = "arm";
# https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/zephyr-sdk-0.16.4_linux-x86_64_minimal.tar.xz
# https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/zephyr-sdk-0.16.4_linux-x86_64_minimal.tar.gz
sdk = fetchurl {
url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/zephyr-sdk-${version}_linux-x86_64_minimal.tar.xz";
hash = "sha256-PLnZfwj+ddUq/d09SOdJVaQhtkIUzL30nFrQ4NdTCy0=";
};
armToolchain = fetchurl {
url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/toolchain_linux-x86_64_arm-zephyr-eabi.tar.xz";
hash = "sha256-IGHlhTTFf5jxsFtVfZpdDhhzrDizEIQVYtNg+XFflvs=";
};
x86_64Toolchain = fetchurl {
url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/toolchain_linux-x86_64_x86_64-zephyr-elf.tar.xz";
hash = "sha256-+x/1/m7aUGTX2+wuozqnmXgdZBTjwTSAmo7fgSAk5xk=";
};
in
stdenv.mkDerivation {
name = "zephyr-sdk";
inherit version;
srcs = [ sdk armToolchain x86_64Toolchain ];
srcRoot = ".";
nativeBuildInputs = [
which
wget
file
python38
autoPatchelfHook
cmake
libusb
];
phases = [ "installPhase" "fixupPhase" ];
installPhase = ''
runHook preInstall
echo out=$out
mkdir -p $out
set $srcs
tar -xf $1 -C $out --strip-components=1
tar -xf $2 -C $out
tar -xf $3 -C $out
(cd $out; bash ./setup.sh -h)
rm $out/zephyr-sdk-x86_64-hosttools-standalone-0.9.sh
runHook postInstall
'';
};
zephyr-sdk = pkgs.callPackage new-zephyr-sdk-pkg { };
packages = with pkgs; [
# Tools for building the languages we are using
llvmPackages_16.clang-unwrapped # Newer than base clang, includes clang-format options Zephyr uses
gcc_multi
glibc_multi
# Dependencies of the Zephyr build system.
(python-packages)
cmake
ninja
gperf
python3
virtualenv
ccache
dtc
gmp.dev
zephyr-sdk
];
in
pkgs.mkShell {
nativeBuildInputs = [ packages ];
# For Zephyr work, we need to initialize some environment variables,
# and then invoke the zephyr setup script.
shellHook = ''
export ZEPHYR_SDK_INSTALL_DIR=${zephyr-sdk}
export PATH=$PATH:${zephyr-sdk}/arm-zephyr-eabi/bin
unset CFLAGS
unset LDFLAGS
virtualenv ./.venv
source ./.venv/bin/activate
# clone zmk
git clone [email protected]:infused-kim/zmk.git -b pr-testing/mouse_ps2_v2 ./zmk
# setup
# https://zmk.dev/docs/development/setup
west init -l ./zmk/app/
cd ./zmk && west update && west zephyr-export && cd ..
pip3 install -r ./zmk/zephyr/scripts/requirements.txt
source ./zmk/zephyr/zephyr-env.sh
'';
}