-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
200 lines (178 loc) · 5.69 KB
/
flake.nix
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
197
198
199
200
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-std = {
url = "github:chessai/nix-std";
};
};
outputs = {
nixpkgs,
crane,
flake-utils,
rust-overlay,
devshell,
nix-gitignore,
nix-std,
self,
...
}: let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
std = nix-std.lib;
in
{ inherit std; } // flake-utils.lib.eachSystem supportedSystems (system: let
wasmTarget = "wasm32-unknown-unknown";
rustToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
rustToolchainWasm = rustToolchain.override {
targets = [ wasmTarget ];
};
craneLib = crane.lib.${system}.overrideToolchain rustToolchain;
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuilding anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
craneLibWasm = craneLib.overrideToolchain rustToolchainWasm;
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
devshell.overlay
(self: super: {
wasm-server-runner = self.callPackage ./nix/wasm-server-runner {};
})
];
};
code = pkgs.callPackage ./deeper.nix {
inherit nixpkgs system craneLib craneLibWasm rustToolchain rustToolchainWasm wasmTarget nix-gitignore std;
};
# some helpful utilities
isLinux = std.string.hasInfix "linux";
isDarwin = std.string.hasInfix "darwin";
isArm64 = std.string.hasInfix "aarch64";
makePkgconfigPath = pkgs.lib.makeSearchPathOutput "dev" "lib/pkgconfig";
makeLinkerPath = linker: "${linker}/bin/${linker.pname}";
in {
inherit pkgs;
packages = {
app = code.app;
wasm = code.wasm;
all = pkgs.symlinkJoin {
name = "all";
paths = [ code.app code.wasm ];
};
default = self.packages.${system}.all;
};
apps.default = flake-utils.lib.mkApp {drv = self.packages.${system}.default;};
checks = {
inherit (code) deeper;
};
devShells.default = pkgs.devshell.mkShell {
env = [
{
name = "CARGO_RUSTFLAGS";
value = std.string.concatSep " " [
"-Clink-arg=-fuse-ld=${makeLinkerPath code.linker}"
"-Zshare-generics=y"
];
}
{
name = "RUSTFLAGS";
value = std.string.concatSep " " [
"-Clink-arg=-fuse-ld=${makeLinkerPath code.linker}"
"-Zshare-generics=y"
];
}
{
name = "SHADERC_LIBRARY_PATH";
value = "${pkgs.shaderc.lib}/lib";
}
{
name = "PKG_CONFIG_PATH";
value = "$PKG_CONFIG_PATH:${makePkgconfigPath code.commonArgs.buildInputs}";
}
{
name = "LD_LIBRARY_PATH";
value = "$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath code.commonArgs.buildInputs}";
}
{
# The coreaudio-sys crate is configured to look for things in whatever the
# output of `xcrun --sdk macosx --show-sdk-path` is. However, this does not
# always contain the right frameworks, and it uses system versions instead of
# what we control via Nix. Instead of having to run a lot of extra scripts
# to set our systems up to build, we can just create a SDK directory with
# the same layout as the `MacOSX{version}.sdk` that XCode produces.
#
# TODO: I'm not 100% confident that this being blank won't cause issues for
# Nix-on-Linux development. It may be sufficient to use the pkgs.symlinkJoin
# above regardless of system! That'd set us up for cross-compilation as well.
name = "COREAUDIO_SDK_PATH";
value =
if isDarwin system
then pkgs.symlinkJoin {
name = "sdk";
paths = with pkgs.darwin.apple_sdk.frameworks; [
AppKit
AudioToolbox
AudioUnit
CoreAudio
CoreFoundation
CoreMIDI
OpenAL
];
postBuild = ''
mkdir -p $out/System
mv $out/Library $out/System
'';
}
else "";
}
];
# Should add some commands for easier wasm generation/running
commands = [];
devshell = {
name = "deeper";
packages = self.packages.${system}.app.buildInputs ++ [
pkgs.pkg-config
pkgs.clang
# LSP's
pkgs.rust-analyzer
pkgs.rnix-lsp
# Tools
code.rustToolchain
pkgs.alejandra
pkgs.shellcheck
pkgs.jq
];
};
};
});
}