-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
168 lines (155 loc) · 4.64 KB
/
flake.nix
File metadata and controls
168 lines (155 loc) · 4.64 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
{
description = "A devShell that can run three-d examples";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
config.allowUnfree = true;
};
rust = pkgs.rust-bin.nightly.latest.default.override {
targets = ["wasm32-unknown-unknown"];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
fs = pkgs.lib.fileset;
files = fs.unions [
./.cargo
./src
./assets
(fs.fileFilter (file: file.hasExt "toml") ./.)
(fs.fileFilter (file: file.name == "Cargo.lock") ./.)
];
src = fs.toSource {
root = ./.;
fileset = files;
};
cargoArtifacts = craneLib.buildDepsOnly {
inherit src buildInputs;
version = "0.1.0";
doCheck = false;
# cargoExtraArgs = "--target thumbv7em-none-eabihf";
};
wasmArtifacts = craneLib.buildDepsOnly {
inherit src buildInputs;
version = "0.1.0";
cargoExtraArgs = "--target wasm32-unknown-unknown";
doCheck = false;
};
nixCrate = craneLib.buildPackage {
inherit src cargoArtifacts buildInputs;
postFixup = ''
cp -r assets $out/bin/
wrapProgram $out/bin/${nixCrate.pname} \
--set LD_LIBRARY_PATH ${LIBS}
'';
};
wasmBuild = craneLib.buildPackage {
inherit src buildInputs;
cargoArtifacts = wasmArtifacts;
cargoExtraArgs = "--target wasm32-unknown-unknown";
doCheck = false;
postFixup = ''
mkdir $out/bin/wasm
cp -r assets $out/bin/wasm/
cd $out/bin
cp -r ${./www}/* .
# cp ${./www/index.html} index.html
# cp ${./www/wasm/index.html} wasm/index.html
mv ${wasmBuild.pname}.wasm wasm/
wasm-bindgen --no-typescript --target web \
--out-dir wasm/ \
--out-name game \
wasm/${wasmBuild.pname}.wasm
'';
};
wasmPublish = pkgs.writeShellScriptBin "publish" ''
rm -rf docs/*
mkdir docs/wasm/assets -p
# install result/bin/index.html docs/
install $(find result/bin/ -maxdepth 1 -type f ) docs/
install $(find result/bin/wasm/ -maxdepth 1 -type f ) docs/wasm/
install $(find result/bin/wasm/assets -maxdepth 1 -type f ) docs/wasm/assets/
'';
wasmServe = with pkgs;
writeShellScriptBin "serve" ''
${static-server}/bin/static-server $@ ${wasmBuild}/bin/
'';
libs = with pkgs; [
alsaLib
udev
vulkan-loader
wayland
libxkbcommon
];
buildInputs = with pkgs;
[
pkg-config
rust
lld
clang
vulkan-tools
vulkan-headers
vulkan-loader
vulkan-validation-layers
wasm-bindgen-cli
makeWrapper
]
++ libs;
utils = with pkgs; [
# video driver info
pciutils
glxinfo
gdb
lldb
rust-analyzer
vscode-langservers-extracted
# wasmServe
wasmPublish
static-server
];
LIBS = pkgs.lib.makeLibraryPath libs;
run = pkgs.writeShellScriptBin "run" ''
export LD_LIBRARY_PATH=${LIBS}
${rust}/bin/cargo run $@
'';
in
with pkgs; {
packages = {
inherit wasmBuild wasmArtifacts wasmServe;
default = nixCrate;
deps = cargoArtifacts;
};
devShells.default = mkShell {
inherit LIBS;
name = "rust graphics env";
buildInputs = buildInputs ++ utils ++ [run];
RUST_LOG = "error";
WINIT_UNIX_BACKEND = "wayland";
shellHook = ''
echo Entering rust env!
echo log level [RUST_LOG] set to: $RUST_LOG
'';
};
}
);
}