-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
81 lines (69 loc) · 2.73 KB
/
flake.nix
File metadata and controls
81 lines (69 loc) · 2.73 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
{
description = "Charon - USB keyboard pass-through device";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
# Rust toolchain with cross-compilation target for RP5
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
targets = [ "aarch64-unknown-linux-gnu" ];
};
# Common packages for all platforms
commonPackages = with pkgs; [
rustToolchain
bacon
cargo-machete
treefmt
just
pkg-config
openssl
perl # needed for vendored openssl build
];
# Linux-specific: cross-compilation toolchain for RP5
# Note: We don't add the cross-compiler to packages directly as it pollutes CC/etc.
# Instead, we reference it only in CARGO_TARGET_* env vars below.
aarch64Cc = pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc;
# Darwin-specific: use Zig as cross-linker (no Docker needed)
darwinPackages = with pkgs; [
zig
cargo-zigbuild
];
in
{
devShells.default = pkgs.mkShell {
packages = commonPackages
++ pkgs.lib.optionals pkgs.stdenv.isDarwin darwinPackages;
shellHook = ''
export DEBUG=1
# Zig cache directories (avoid Nix store conflicts)
export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig"
export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig-global"
# For Linux cross-compilation to RP5
${pkgs.lib.optionalString pkgs.stdenv.isLinux ''
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="${aarch64Cc}/bin/aarch64-unknown-linux-gnu-gcc"
export CC_aarch64_unknown_linux_gnu="${aarch64Cc}/bin/aarch64-unknown-linux-gnu-gcc"
''}
echo "Charon development environment"
echo " Local target: ${system}"
echo " Cross target: aarch64-unknown-linux-gnu (RP5)"
${pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
echo " Cross-compile: cargo zigbuild --target aarch64-unknown-linux-gnu --release"
''}
'';
# For openssl-sys
OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
};
}
);
}