-
Notifications
You must be signed in to change notification settings - Fork 10
/
flake.nix
218 lines (203 loc) · 6.83 KB
/
flake.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright lowRISC Contributors.
# SPDX-License-Identifier: Apache-2.0
{
description = "Sonata Software";
inputs = {
sonata-system.url = "github:lowRISC/sonata-system";
lowrisc-nix.follows = "sonata-system/lowrisc-nix";
nixpkgs.follows = "lowrisc-nix/nixpkgs";
flake-utils.follows = "lowrisc-nix/flake-utils";
mdutils = {
url = "git+https://codeberg.org/HU90m/mdutils.git";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-substituters = ["https://nix-cache.lowrisc.org/public/"];
extra-trusted-public-keys = ["nix-cache.lowrisc.org-public-1:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o="];
};
outputs = {
self,
nixpkgs,
flake-utils,
lowrisc-nix,
sonata-system,
mdutils,
}: let
system_outputs = system: let
pkgs = import nixpkgs {inherit system;};
lrPkgs = lowrisc-nix.outputs.packages.${system};
mdutilsPkgs = mdutils.outputs.packages.${system};
lrDoc = lowrisc-nix.lib.doc {inherit pkgs;};
sonataSystemPkgs = sonata-system.outputs.packages.${system};
cheriotPkgs = lowrisc-nix.outputs.devShells.${system}.cheriot.nativeBuildInputs;
inherit (pkgs.lib) fileset getExe;
commonSoftwareBuildAttributes = {
buildInputs = cheriotPkgs ++ [lrPkgs.uf2conv];
installPhase = ''
mkdir -p $out/share/
cp build/cheriot/cheriot/release/* $out/share/
'';
dontFixup = true;
};
sonata-automotive-demo-legacy-component = pkgs.stdenvNoCC.mkDerivation {
name = "sonata-automotive-demo-legacy-component";
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [./examples/automotive ./third_party];
};
buildInputs = with lrPkgs; [xmake lowrisc-toolchain-gcc-rv32imcb];
buildPhase = "xmake -P ./examples/automotive/legacy/";
installPhase = ''
mkdir -p $out/share/
cp build/ilp32/rv32imc/release/automotive_demo_send_legacy $out/share
'';
dontFixup = true;
};
sonata-software-documentation = lrDoc.buildMdbookSite {
version = "";
pname = "sonata-software-documentation";
src = fileset.toSource {
root = ./.;
fileset = lrDoc.standardMdbookFileset ./.;
};
buildInputs = [mdutilsPkgs.default];
};
sonata-tests = pkgs.stdenvNoCC.mkDerivation ({
name = "sonata-tests";
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [./tests ./common.lua ./cheriot-rtos];
};
buildPhase = "xmake -P ./tests/";
}
// commonSoftwareBuildAttributes);
sonata-examples = pkgs.stdenvNoCC.mkDerivation ({
name = "sonata-examples";
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [
./common.lua
./cheriot-rtos
./libraries
./third_party
./examples
];
};
buildPhase = "xmake -P ./examples/";
}
// commonSoftwareBuildAttributes);
sonata-exercises = pkgs.stdenvNoCC.mkDerivation ({
name = "sonata-exercises";
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [./exercises ./common.lua ./cheriot-rtos];
};
buildPhase = "xmake -P ./exercises/";
}
// commonSoftwareBuildAttributes);
tests-runner =
pkgs.writers.writePython3Bin "tests-runner" {
libraries = [pkgs.python3Packages.pyserial];
}
./scripts/test_runner.py;
tests-fpga-runner = pkgs.writers.writeBashBin "tests-fpga-runner" ''
set -e
if [ -z "$1" ]; then
echo "Please provide the tty device location (e.g. /dev/ttyUSB2)" \
"as the first argument."
exit 2
fi
${getExe tests-runner} -t 30 fpga $1 --uf2-file ${sonata-tests}/share/sonata_test_suite.uf2
'';
tests-simulator = pkgs.stdenvNoCC.mkDerivation {
name = "tests-simulator";
src = ./.;
dontBuild = true;
doCheck = true;
buildInputs = [sonataSystemPkgs.sonata-simulator];
SONATA_SIM_BOOT_STUB = "${sonataSystemPkgs.sonata-sim-boot-stub.out}/share/sim_boot_stub";
checkPhase = ''
${getExe tests-runner} -t 30 sim --elf-file ${sonata-tests}/share/sonata_test_suite
'';
installPhase = "mkdir $out";
};
lint-python = pkgs.writeShellApplication {
name = "lint-python";
runtimeInputs = with pkgs; [
ruff
(python3.withPackages (pyPkg: with pyPkg; [mypy pyserial]))
];
text = ''
ruff format --check .
ruff check .
mypy .
'';
};
lint-cpp = let
srcGlob = "{examples/**/*.{h,cc},exercises/**/*.{hh,cc},{libraries,tests}/*.{cc,hh}}";
in
pkgs.writeShellApplication {
name = "lint-cpp";
runtimeInputs = with lrPkgs; [llvm_cheriot];
text = ''
shopt -s globstar
clang-format --dry-run --Werror ${srcGlob}
clang-tidy ${srcGlob}
echo "No warnings outside of dependancies."
'';
};
lint-all = pkgs.writeShellApplication {
name = "lint-all";
text = ''
${getExe pkgs.reuse} lint
${getExe pkgs.lychee} --offline --no-progress .
${getExe lint-python}
${getExe lint-cpp}
'';
};
in {
formatter = pkgs.alejandra;
devShells = rec {
default = pkgs.mkShell {
name = "sonata-sw";
packages =
cheriotPkgs
++ [
lrPkgs.uf2conv
lrPkgs.cheriot-audit
pkgs.python3Packages.pyserial
mdutilsPkgs.default
];
};
env-with-sim = pkgs.mkShell {
name = "sonata-sw-with-sim";
packages = [sonataSystemPkgs.sonata-simulator] ++ default.nativeBuildInputs;
SONATA_SIM_BOOT_STUB = "${sonataSystemPkgs.sonata-sim-boot-stub.out}/share/sim_boot_stub";
};
build-legacy-software = pkgs.mkShell {
name = "sonata-sw-legacy";
packages = [lrPkgs.lowrisc-toolchain-gcc-rv32imcb];
};
};
packages = {
inherit
sonata-exercises
sonata-examples
sonata-tests
sonata-software-documentation
sonata-automotive-demo-legacy-component
;
};
checks = {inherit tests-simulator;};
apps = builtins.listToAttrs (map (program: {
inherit (program) name;
value = {
type = "app";
program = getExe program;
};
}) [lint-all lint-cpp lint-python tests-runner tests-fpga-runner]);
};
in
flake-utils.lib.eachDefaultSystem system_outputs;
}