-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
154 lines (141 loc) · 4.68 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
{
description = "A very basic flake";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
rust-overlay.url = "github:oxalica/rust-overlay";
systems.url = "github:nix-systems/default";
};
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
# To import a flake module
# 1. Add foo to inputs
# 2. Add foo as a parameter to the outputs function
# 3. Add here: foo.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
];
perSystem =
{ config
# , self'
# , inputs'
, pkgs
, system
, lib
, ...
}:
let
minBuildInputs = with pkgs; [
gcc-arm-embedded
flip-link
stdenv.cc.cc.lib
stdenv.cc
git
rustc
];
uploadInputs = with pkgs; [
dfu-util
];
in
{
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
# This sets `pkgs` to a nixpkgs with allowUnfree option set.
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
(self: _super: {
rustc = self.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
targets = [ "x86_64-unknown-linux-gnu" "thumbv7em-none-eabihf" ];
};
})
];
# config.allowUnfree = true;
};
apps = {
upload_usb = {
type = "app";
program = pkgs.writeShellScriptBin "upload_usb" ''
set -e
export PATH="${pkgs.lib.makeBinPath (minBuildInputs ++ uploadInputs)}":$PATH
cargo build --release --bin ''${1:-split}
arm-none-eabi-objcopy -O binary target/thumbv7em-none-eabihf/release/split split.bin
sudo dfu-util -a 0 -s 0x8000000 -RD split.bin
''
;
};
update_keyboard = {
type = "app";
program = pkgs.writeShellScriptBin "upload_update_keyboard" ''
set -e
export PATH="${pkgs.lib.makeBinPath (minBuildInputs ++ uploadInputs)}":$PATH
cargo build --release --bin ''${1:-split}
arm-none-eabi-objcopy -O binary target/thumbv7em-none-eabihf/release/split split.bin
echo Flashing pads until stop
while true ; do
sudo dfu-util -a 0 -s 0x8000000 -RD split.bin || true
echo Retrying in 5 seconds
sleep 5
done
''
;
};
};
pre-commit = {
settings = {
hooks = {
deadnix.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
clippy.enable = true;
rustfmt.enable = true;
# cargo-test = {
# enable = true;
# name = "cargo test";
# description = "Test Rust code.";
# entry = toString (pkgs.writeShellScript "cargo test" ''
# export PATH=${lib.makeBinPath minBuildInputs}
# cargo test'');
# files = "\\.rs$";
# pass_filenames = false;
# };
};
tools = {
cargo = lib.mkForce pkgs.rustc;
clippy = lib.mkForce pkgs.rustc;
rustfmt = lib.mkForce pkgs.rustc;
};
};
};
devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';
buildInputs = minBuildInputs ++ uploadInputs ++ (
with pkgs; [
# cmake
# expect
# gdb-multitarget
minicom
probe-run
usbutils
]
);
# depsBuildBuild = with pkgs; [ qemu ];
# LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
# CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "cc";
# CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64";
};
formatter = pkgs.nixpkgs-fmt;
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
}