Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
158 lines (143 loc) · 5.43 KB
/
Copy pathflake.nix
File metadata and controls
158 lines (143 loc) · 5.43 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
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
{
description = "hidra: pure-Rust HID library with native, nusb and WebHID backends";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
# Reproducible Windows 11 VM builder (M-Labs). Pins its own nixpkgs (23.11);
# we deliberately do NOT `follows` it, makeWindowsImage is only tested against
# that pin, and it always evaluates its layers with its own pkgs regardless.
wfvm = {
url = "git+https://git.m-labs.hk/m-labs/wfvm";
};
};
outputs =
{
self,
nixpkgs,
rust-overlay,
wfvm,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
cargoToml = nixpkgs.lib.importTOML ./Cargo.toml;
# e2e/targets/macos virtual-HID test binary, built + ad-hoc-signed with the HID
# entitlement (defined in e2e/platform/macos; only runnable on a SIP-off host).
macosVirtualSigned =
pkgs:
import ./e2e/platform/macos/macos-virtual-signed.nix {
inherit pkgs self;
version = cargoToml.package.version;
};
# Reproducible Windows 11 test VM (x86_64-linux + KVM only). See
# e2e/platform/windows/test-vm.nix. Returns { image; run; }.
windowsTestVm =
pkgs:
import ./e2e/platform/windows/test-vm.nix {
inherit pkgs self;
wfvm = wfvm.lib;
};
in
{
packages = forAllSystems (
pkgs:
{
default = pkgs.rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
version = cargoToml.package.version;
src = self;
cargoLock.lockFile = ./Cargo.lock;
buildFeatures = [ "nusb" ];
cargoBuildFlags = [ "--examples" ];
# nusb enumerates via libudev on Linux; pkg-config + udev supply the link flags.
nativeBuildInputs = nixpkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.pkg-config ];
buildInputs = nixpkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.udev ];
# The crate is a library; install the example binaries for a runnable output.
postInstall = ''
mkdir -p $out/bin
find target -type f -executable \
-regex '.*/release/examples/[a-z_]+' \
-exec install -m755 -t $out/bin {} \;
'';
meta = {
description = "Pure-Rust HID library";
homepage = "https://github.com/karstx/hidra";
license = nixpkgs.lib.licenses.mit;
};
};
}
// nixpkgs.lib.optionalAttrs pkgs.stdenv.isDarwin {
macos-virtual-signed = macosVirtualSigned pkgs;
}
// nixpkgs.lib.optionalAttrs (pkgs.stdenv.hostPlatform.system == "x86_64-linux") {
# Bootable NixOS VM for the full Linux test matrix. See e2e/platform/linux/test-vm.nix.
test-vm = self.nixosConfigurations.hidra-test.config.system.build.vm;
# Reproducible Windows 11 test VM. `-base` is Win11 + SSH + test signing
# (builds from just the Windows ISO); `windows-test-vm` adds the toolchain
# + a built/installed WinUHid driver; `-run` boots it in snapshot mode and
# runs `cargo test -p windows` over SSH. See e2e/platform/windows/README.md.
windows-test-vm-base = (windowsTestVm pkgs).baseImage;
windows-test-vm-toolchain = (windowsTestVm pkgs).toolchainImage;
windows-test-vm = (windowsTestVm pkgs).image;
windows-test-vm-run = (windowsTestVm pkgs).run;
}
);
nixosConfigurations.hidra-test = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit self; };
modules = [
"${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix"
{ nixpkgs.overlays = [ rust-overlay.overlays.default ]; }
./e2e/platform/linux/test-vm.nix
];
};
checks = forAllSystems (
pkgs:
{
build = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
fmt =
pkgs.runCommand "hidra-fmt"
{
nativeBuildInputs = [
pkgs.cargo
pkgs.rustfmt
];
}
''
export HOME=$TMPDIR
# Each path is its own workspace, so fmt-check them individually.
for ws in "" e2e e2e/targets/webhid e2e/targets/webhid/fixture; do
( cd ${self}/$ws && cargo fmt --check )
done
touch $out
'';
}
// nixpkgs.lib.optionalAttrs pkgs.stdenv.isDarwin {
macos-virtual-signed = macosVirtualSigned pkgs;
}
);
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
cargo
rustc
clippy
rustfmt
rust-analyzer
];
# libudev for nusb's enumeration on Linux.
nativeBuildInputs = nixpkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.pkg-config ];
buildInputs = nixpkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.udev ];
};
});
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}