Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
128 lines (107 loc) · 3.89 KB
/
Copy pathflake.nix
File metadata and controls
128 lines (107 loc) · 3.89 KB
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
{
description = "Framework Laptop 16 Input Module firmware and control tool";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "thumbv6m-none-eabi" ];
extensions = [ "rust-src" "rustfmt" "clippy" ];
};
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
# st7306 is a git dependency; fetch it via builtins.fetchGit so we
# don't have to hand-maintain an outputHash entry.
allowBuiltinFetchGit = true;
};
firmwareTarget = "thumbv6m-none-eabi";
mkFirmware = pname:
rustPlatform.buildRustPackage {
inherit pname src cargoLock;
version = "0.2.0";
nativeBuildInputs = [ pkgs.flip-link pkgs.elf2uf2-rs ];
# buildRustPackage's cargoBuildHook hard-codes --target to the host
# triple, which breaks no_std firmware builds. Replace the build
# and install phases instead of fighting the hook.
buildPhase = ''
runHook preBuild
cargo build \
--release \
--frozen \
--target ${firmwareTarget} \
-p ${pname}
runHook postBuild
'';
checkPhase = ''
runHook preCheck
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${firmwareTarget}/release/${pname} $out/bin/${pname}.elf
elf2uf2-rs \
target/${firmwareTarget}/release/${pname} \
$out/bin/${pname}.uf2
runHook postInstall
'';
meta.description = "Framework Input Module firmware (${pname})";
};
inputmodule-control = rustPlatform.buildRustPackage {
pname = "inputmodule-control";
version = "0.2.0";
inherit src cargoLock;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.udev ];
cargoBuildFlags = [ "-p" "inputmodule-control" ];
# Override the workspace-default embedded target so this builds
# natively for the host.
CARGO_BUILD_TARGET = pkgs.stdenv.hostPlatform.rust.rustcTarget;
doCheck = false;
meta = {
description = "Host-side control tool for Framework Input Modules";
mainProgram = "inputmodule-control";
};
};
in {
packages = {
default = inputmodule-control;
inherit inputmodule-control;
ledmatrix = mkFirmware "ledmatrix";
b1display = mkFirmware "b1display";
c1minimal = mkFirmware "c1minimal";
qtpy = mkFirmware "qtpy";
};
apps.default = {
type = "app";
program = "${inputmodule-control}/bin/inputmodule-control";
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
rustToolchain
pkgs.flip-link
pkgs.cargo-make
pkgs.pkg-config
pkgs.elf2uf2-rs
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.udev ];
};
formatter = pkgs.nixpkgs-fmt;
});
}