Skip to content

Commit a646ae4

Browse files
authored
refactor nix ci (#47)
* refactor nix config Signed-off-by: Thing-han, Lim <[email protected]> * refactor nix ci Signed-off-by: Thing-han, Lim <[email protected]> --------- Signed-off-by: Thing-han, Lim <[email protected]>
1 parent e1ab38d commit a646ae4

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

.github/actions/setup-nix/action.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ inputs:
77
script:
88
description: The script to be run in the nix shell
99
required: false
10+
devShell:
11+
description: The name of the devShell
12+
required: true
13+
default: 'default'
1014

1115
runs:
1216
using: composite
1317
steps:
14-
- uses: nixbuild/nix-quick-install-action@v27
15-
with: {load_nixConfig: false}
18+
- uses: DeterminateSystems/nix-installer-action@v12
19+
- uses: DeterminateSystems/magic-nix-cache-action@main
1620
- name: Prepare nix dev shell
17-
shell: nix develop .#ci -c bash -e {0}
21+
shell: nix develop .#${{ inputs.devShell }} -c bash -e {0}
1822
run: |
1923
- name: Dependency check
20-
shell: nix develop .#ci -c bash -e {0}
24+
shell: nix develop .#${{ inputs.devShell }} -c bash -e {0}
2125
if: inputs.script != ''
2226
env:
2327
INPUT_SCRIPT: ${{ inputs.script }}

.github/workflows/build.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ on:
99
jobs:
1010
build_test:
1111
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
shell: nix develop .#ci -c bash -e {0}
1215
steps:
1316
- uses: actions/checkout@v4
1417
- name: Setup nix
1518
uses: ./.github/actions/setup-nix
1619
with:
20+
devShell: ci
1721
script: |
1822
astyle --version
1923
arm-none-eabi-gcc --version
2024
qemu-system-arm --version
2125
- name: Lint
22-
shell: nix develop .#ci -c bash -e {0}
2326
run: |
2427
lint
2528
- name: Build targets
26-
shell: nix develop .#ci -c bash -e {0}
2729
run: |
2830
make_platform() {
2931
echo "::group::make platform $1"
@@ -44,28 +46,24 @@ jobs:
4446
4547
- name: Functional test
4648
id: func_test
47-
shell: nix develop .#ci -c bash -e {0}
4849
run: |
4950
tests-qemu func
5051
- name: Speed test
5152
id: speed_test
52-
shell: nix develop .#ci -c bash -e {0}
5353
if: |
5454
success()
5555
|| steps.func_test.conclusion == 'failure'
5656
run: |
5757
tests-qemu speed
5858
- name: Stack test
5959
id: stack_test
60-
shell: nix develop .#ci -c bash -e {0}
6160
if: |
6261
success()
6362
|| steps.func_test.conclusion == 'failure'
6463
|| steps.speed_test.conclusion == 'failure'
6564
run: |
6665
tests-qemu stack
6766
- name: Nistkat test
68-
shell: nix develop .#ci -c bash -e {0}
6967
if: |
7068
success()
7169
|| steps.func_test.conclusion == 'failure'

flake.nix

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,22 @@
2424
mbed-os = pkgs.callPackage ./mbed-os.nix {
2525
targets = [ "TARGET_MPS2_M3" "TARGET_MPS2_M4" "TARGET_MPS2_M7" ];
2626
};
27-
astyle = pkgs.astyle.overrideAttrs (old: rec {
28-
version = "3.4.13";
29-
src = pkgs.fetchurl {
30-
url = "mirror://sourceforge/${old.pname}/${old.pname}-${version}.tar.bz2";
31-
hash = "sha256-eKYQq9OelOD5E+nuXNoehbtizWM1U97LngDT2SAQGc4=";
32-
};
33-
});
27+
3428
core = builtins.attrValues {
35-
libopencm3 = libopencm3;
36-
mbed-os = mbed-os;
37-
astyle = astyle;
29+
astyle = pkgs.astyle.overrideAttrs (old: rec {
30+
version = "3.4.13";
31+
src = pkgs.fetchurl {
32+
url = "mirror://sourceforge/${old.pname}/${old.pname}-${version}.tar.bz2";
33+
hash = "sha256-eKYQq9OelOD5E+nuXNoehbtizWM1U97LngDT2SAQGc4=";
34+
};
35+
});
3836

3937
inherit (pkgs)
4038
# formatter & linters
4139
nixpkgs-fmt
4240
shfmt
4341

4442
# build dependencies
45-
gcc-arm-embedded-13# arm-gnu-toolchain-13.2.rel1
4643
qemu# 8.2.4
4744

4845
yq;
@@ -53,34 +50,39 @@
5350
pyserial# 3.5
5451
click;
5552
};
53+
54+
arm-pkgs = builtins.attrValues {
55+
libopencm3 = libopencm3;
56+
mbed-os = mbed-os;
57+
inherit (pkgs)
58+
gcc-arm-embedded-13; # arm-gnu-toolchain-13.2.rel1
59+
};
60+
61+
wrapShell = mkShell: attrs:
62+
mkShell (attrs // {
63+
shellHook = ''
64+
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
65+
'';
66+
});
5667
in
5768
{
58-
devShells.default = pkgs.mkShellNoCC {
59-
packages = core ++ builtins.attrValues {
69+
devShells.default = wrapShell pkgs.mkShellNoCC {
70+
packages = core ++ arm-pkgs ++ builtins.attrValues {
6071
inherit (pkgs)
6172
direnv
6273
nix-direnv
6374

6475
# debug dependencies
6576
openocd; # 0.12.0
6677
};
67-
68-
shellHook = ''
69-
export OPENCM3_DIR=${libopencm3}
70-
export MBED_OS_DIR=${mbed-os}
71-
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
72-
eval "$(_TESTS_COMPLETE=bash_source tests)"
73-
'';
78+
OPENCM3_DIR = ''${libopencm3}'';
79+
MBED_OS_DIR = ''${mbed-os}'';
7480
};
7581

76-
devShells.ci = pkgs.mkShellNoCC {
77-
packages = core;
78-
79-
shellHook = ''
80-
export OPENCM3_DIR=${libopencm3}
81-
export MBED_OS_DIR=${mbed-os}
82-
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
83-
'';
82+
devShells.ci = wrapShell pkgs.mkShellNoCC {
83+
packages = core ++ arm-pkgs;
84+
OPENCM3_DIR = ''${libopencm3}'';
85+
MBED_OS_DIR = ''${mbed-os}'';
8486
};
8587
};
8688
flake = {

0 commit comments

Comments
 (0)