-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
196 lines (171 loc) · 6.39 KB
/
flake.nix
File metadata and controls
196 lines (171 loc) · 6.39 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
{
description = "eframe devShell";
# Cross-compilation shamelessly lifted from https://mediocregopher.com/posts/x-compiling-rust-with-nix
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
# Cross-compile
fenix.url = "github:nix-community/fenix";
naersk.url = "github:nix-community/naersk/master";
# Shell
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, nixpkgs, flake-utils, fenix, naersk, rust-overlay, ... }:
let
buildTargets = {
"x86_64-linux" = {
crossSystemConfig = "x86_64-unknown-linux-musl";
rustTarget = "x86_64-unknown-linux-musl";
};
"i686-linux" = {
crossSystemConfig = "i686-unknown-linux-musl";
rustTarget = "i686-unknown-linux-musl";
};
"aarch64-linux" = {
crossSystemConfig = "aarch64-unknown-linux-musl";
rustTarget = "aarch64-unknown-linux-musl";
};
# Old Raspberry Pi's
"armv6l-linux" = {
crossSystemConfig = "armv6l-unknown-linux-musleabihf";
rustTarget = "arm-unknown-linux-musleabihf";
};
"x86_64-windows" = {
crossSystemConfig = "x86_64-w64-mingw32";
rustTarget = "x86_64-pc-windows-gnu";
makeBuildPackageAttrs = pkgsCross: {
depsBuildBuild = [
pkgsCross.stdenv.cc
];
};
};
};
# eachSystem [system] (system: ...)
#
# Returns an attrset with a key for every system in the given array, with
# the key's value being the result of calling the callback with that key.
eachSystem = supportedSystems: callback: builtins.foldl'
(overall: system: overall // { ${system} = callback system; })
{}
supportedSystems;
# eachCrossSystem [system] (buildSystem: targetSystem: ...)
#
# Returns an attrset with a key "$buildSystem.cross-$targetSystem" for
# every combination of the elements of the array of system strings. The
# value of the attrs will be the result of calling the callback with each
# combination.
#
# There will also be keys "$system.default", which are aliases of
# "$system.cross-$system" for every system.
#
eachCrossSystem = supportedSystems: callback:
eachSystem supportedSystems (buildSystem: builtins.foldl'
(inner: targetSystem: inner // {
"cross-${targetSystem}" = callback buildSystem targetSystem;
})
{ default = callback buildSystem buildSystem; }
supportedSystems
);
mkPkgs = buildSystem: targetSystem: import nixpkgs ({
system = buildSystem;
} // (if targetSystem == null then {} else {
# The nixpkgs cache doesn't have any packages where cross-compiling has
# been enabled, even if the target platform is actually the same as the
# build platform (and therefore it's not really cross-compiling). So we
# only set up the cross-compiling config if the target platform is
# different.
crossSystem.config = buildTargets.${targetSystem}.crossSystemConfig;
}));
in rec {
packages = eachCrossSystem
(builtins.attrNames buildTargets)
(buildSystem: targetSystem: let
pkgs = mkPkgs buildSystem null;
pkgsCross = mkPkgs buildSystem targetSystem;
rustTarget = buildTargets.${targetSystem}.rustTarget;
fenixPkgs = fenix.packages.${buildSystem};
mkToolchain = fenixPkgs: fenixPkgs.toolchainOf {
channel = "1.83";
sha256 = "sha256-s1RPtyvDGJaX/BisLT+ifVfuhDT1nZkZ1NcK8sbwELM=";
};
toolchain = fenixPkgs.combine [
(mkToolchain fenixPkgs).rustc
(mkToolchain fenixPkgs).cargo
(mkToolchain fenixPkgs.targets.${rustTarget}).rust-std
];
buildPackageAttrs = if
builtins.hasAttr "makeBuildPackageAttrs" buildTargets.${targetSystem}
then
buildTargets.${targetSystem}.makeBuildPackageAttrs pkgsCross
else
{};
naersk-lib = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
in
naersk-lib.buildPackage (buildPackageAttrs // rec {
src = ./.;
strictDeps = true;
doCheck = false;
cargoBuildOptions = x: x ++ [ "-p" "planchette" "-p" "seance-app" ];
cargoTestOptions = x: x ++ [ "-p" "planchette" "-p" "seance-app" ];
TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
CARGO_BUILD_TARGET = rustTarget;
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS =
"-L native=${pkgs.pkgsCross.mingwW64.windows.pthreads}/lib";
CARGO_BUILD_RUSTFLAGS = [
"-C" "target-feature=+crt-static"
# https://github.com/rust-lang/cargo/issues/4133
"-C" "linker=${TARGET_CC}"
];
})
);
} //
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
nativeBuildInputs = with pkgs; [
rustToolchain
cargo-deb
typos
dpkg
];
buildInputs = with pkgs; [
# So many things required for wgpu
libxkbcommon
libGL
fontconfig
wayland
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libX11
alsa-lib
freetype
shaderc
directx-shader-compiler
cmake
vulkan-headers
vulkan-loader
vulkan-tools
vulkan-tools-lunarg
vulkan-extension-layer
vulkan-validation-layers
];
in with pkgs; {
formatter = pkgs.alejandra;
devShells.default = mkShell rec {
inherit buildInputs nativeBuildInputs;
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}";
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
});
}