Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
133 lines (123 loc) · 4.96 KB
/
Copy pathflake.nix
File metadata and controls
133 lines (123 loc) · 4.96 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
129
130
131
132
133
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2026 RS-Key contributors
{
description = "RS-Key (RSK) — an open security-key firmware for the RP2350: FIDO2, OpenPGP, PIV, OATH, OTP";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# SDL2 ONLY, and deliberately not the main pin. `tools/emu --display` opens its
# window through the Rust `sdl2` crate, whose event enum is SDL2's; unstable now
# ships `sdl2-compat` (SDL3 behind an SDL2 API) as `SDL2`, which emits SDL3-era
# window events (0x207) the crate aborts on. 24.11 is the last branch carrying
# real SDL2, and nothing else is taken from it — the toolchain, every tool and
# every build stay on the main pin.
nixpkgs-sdl2.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
# The per-system pieces live in nix/: firmware.nix (the `nix build` packages +
# the mkFirmware builder), host-tools.nix (the Python + rsk/rsk-tui commands),
# devshells.nix (the dev + fuzz shells), checks.nix (`nix flake check`), and
# ccid.nix (the host-side CCID driver package + overlay). This file just wires
# the shared context (pkgs, the cross target, the toolchains) into them.
outputs =
{
self,
nixpkgs,
nixpkgs-sdl2,
flake-utils,
fenix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(_final: prev: { picotool = import ./nix/picotool.nix { pkgs = prev; }; })
];
};
sdl2 = (import nixpkgs-sdl2 { inherit system; }).SDL2;
fx = fenix.packages.${system};
# RP2350 = dual Cortex-M33 -> thumbv8m.main-none-eabihf (hardware float).
# (RP2350 also has RISC-V Hazard3 cores; we target the ARM cores, which embassy-rp supports.)
target = "thumbv8m.main-none-eabihf";
toolchain = fx.combine [
fx.stable.toolchain
fx.targets.${target}.stable.rust-std
];
# cargo-fuzz needs nightly (libfuzzer + -Zsanitizer); host target only.
fuzzToolchain = fx.complete.toolchain;
hostTools = import ./nix/host-tools.nix { inherit pkgs; };
firmware = import ./nix/firmware.nix { inherit pkgs target toolchain; };
apps' = import ./nix/apps.nix {
inherit pkgs self toolchain;
inherit (hostTools) rskPython;
firmwarePackage = firmware.packages.firmware;
};
in
{
packages =
firmware.packages
// apps'.packages
// {
ccid-rs-key = import ./nix/ccid.nix { inherit pkgs; };
}
# The guest for the USB-stack suites. Linux only — it exists to own a
# `vhci_hcd`, and there is no such thing to own elsewhere.
// nixpkgs.lib.optionalAttrs (nixpkgs.lib.hasSuffix "-linux" system) {
usbip-vm = import ./nix/usbip-vm.nix {
inherit nixpkgs system sdl2;
inherit (hostTools) rskPython;
ccidOverlay = self.overlays.ccid-rs-key;
};
};
inherit (firmware) lib;
apps = apps'.apps;
devShells = import ./nix/devshells.nix (
{
inherit
pkgs
sdl2
target
toolchain
fuzzToolchain
;
}
// hostTools
);
# `nix fmt` formats the flake's Nix; `nix flake check` runs nix/checks.nix.
# Plain nixfmt only takes file args, so wrap it to recurse the tree when
# `nix fmt` is called with none.
formatter = pkgs.writeShellApplication {
name = "fmt";
runtimeInputs = [ pkgs.nixfmt ];
text = ''
targets=("$@")
if [ "''${#targets[@]}" -eq 0 ]; then targets=("."); fi
find "''${targets[@]}" -name '*.nix' -not -path '*/.git/*' -print0 \
| xargs -0 -r nixfmt
'';
};
checks = import ./nix/checks.nix {
inherit pkgs toolchain;
inherit (firmware) firmwareSrc cargoDeps;
};
}
)
// {
# System-independent, so it sits outside eachDefaultSystem. Applying it
# (`nixpkgs.overlays = [ rs-key.overlays.ccid-rs-key ]`) is the whole fix on
# NixOS: the pcscd module's plugin list is `[ pkgs.ccid ]`, so replacing that
# attribute is enough. Overriding `prev.ccid`, not `final.ccid` — the latter
# is the attribute being defined here. Without the overlay, point
# services.pcscd.plugins at packages.<system>.ccid-rs-key with lib.mkForce:
# the module assigns its own `[ pkgs.ccid ]`, and two ccid bundles collide in
# the plugin buildEnv it maps them through (docs/linux.md).
overlays.ccid-rs-key = _final: prev: {
ccid = import ./nix/ccid.nix { pkgs = prev; };
};
};
}