-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathflake.nix
More file actions
217 lines (191 loc) · 5.77 KB
/
flake.nix
File metadata and controls
217 lines (191 loc) · 5.77 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
{
description = "A Nix-flake-based C/C++ development environment";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = {
self,
nixpkgs,
}: let
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forEachSupportedSystem = f:
nixpkgs.lib.genAttrs supportedSystems (system:
f rec {
pkgs = import nixpkgs {inherit system;};
isDarwin = pkgs.lib.hasSuffix system "darwin";
arch = if pkgs.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64";
linuxDeps = with pkgs; [
autoPatchelfHook
xorg.libX11
xorg.libXcursor
xorg.libXinerama
xorg.libXext
xorg.libXrandr
xorg.libXrender
xorg.libXi
xorg.libXfixes
libxkbcommon
wayland-scanner
wayland
libdecor
alsa-lib
libpulseaudio
udev
dbus
dbus.lib
];
darwinDeps = with pkgs; [
Foundation
Cocoa
AudioToolbox
CoreAudio
CoreVideo
AVFoundation
];
commonDeps = with pkgs; [
stdenv.cc
gcc-unwrapped
pkg-config
installShellFiles
python3
speechd
makeWrapper
mono
dotnet-sdk_8
dotnet-runtime_8
vulkan-loader
libGL
fontconfig
fontconfig.lib
scons
];
deps = if isDarwin then darwinDeps ++ commonDeps else linuxDeps ++ commonDeps;
libraryPathVar = if isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
platform = if isDarwin then "macos" else "linuxbsd";
});
in {
apps = forEachSupportedSystem ({
pkgs,
deps,
libraryPathVar,
platform,
arch,
...
}: let
script = pkgs.writeShellScript "redot" ''
export PATH=${pkgs.lib.makeBinPath deps}:$PATH
export ${libraryPathVar}=${pkgs.lib.makeLibraryPath deps}
scons_args=()
runtime_args=()
parsing_runtime_args=0
show_help=0
target=editor
target_arch=${arch}
scons_platform=${platform}
dev_build=no
precision=single
threads=yes
extra_suffix=
for arg in "$@"; do
if [ "$parsing_runtime_args" -eq 0 ] && [ "$arg" = "--help" ]; then
show_help=1
continue
fi
if [ "$parsing_runtime_args" -eq 0 ] && [ "$arg" = "--" ]; then
parsing_runtime_args=1
continue
fi
if [ "$parsing_runtime_args" -eq 0 ]; then
case "$arg" in
target=*) target=''${arg#target=} ;;
arch=*)
target_arch=''${arg#arch=}
if [ "$target_arch" = "auto" ]; then
target_arch=${arch}
fi
;;
platform=*)
scons_platform=''${arg#platform=}
continue
;;
dev_build=*) dev_build=''${arg#dev_build=} ;;
precision=*) precision=''${arg#precision=} ;;
threads=*) threads=''${arg#threads=} ;;
extra_suffix=*) extra_suffix=''${arg#extra_suffix=} ;;
esac
scons_args+=("$arg")
else
runtime_args+=("$arg")
fi
done
if [ "$show_help" -eq 1 ]; then
cat <<EOF
Usage:
nix run .
nix run . -- [scons build flags...]
nix run . -- [scons build flags...] -- [redot runtime args...]
Examples:
nix run .
nix run . -- target=editor dev_build=yes num_jobs=12
nix run . -- target=template_release production=yes
nix run . -- target=editor dev_build=yes -- --path /tmp/project
Argument handling:
- The first '--' is consumed by Nix.
- Arguments before the next '--' are passed to SCons.
- Arguments after the next '--' are passed to the Redot binary.
Notes:
- Common SCons flags include target=..., dev_build=yes, production=yes,
module_mono_enabled=yes, precision=double, num_jobs=..., and ccflags=...
- The wrapper auto-builds only when a matching binary is not already present.
Use 'nix develop' for full manual rebuild control.
EOF
exit 0
fi
binary_pattern="redot.$scons_platform.''${target}"
if [ "$dev_build" = "yes" ]; then
binary_pattern="$binary_pattern.dev"
fi
if [ "$precision" = "double" ]; then
binary_pattern="$binary_pattern.double"
fi
binary_pattern="$binary_pattern.''${target_arch}"
if [ "$threads" = "no" ]; then
binary_pattern="$binary_pattern.nothreads"
fi
if [ -n "$extra_suffix" ]; then
binary_pattern="$binary_pattern.$extra_suffix"
fi
binary_path="./bin/$binary_pattern"
if [ ! -f "$binary_path" ]; then
echo "Building Redot..."
scons "''${scons_args[@]}" platform=$scons_platform
fi
if [ ! -f "$binary_path" ]; then
echo "Could not find a built Redot binary at $binary_path" >&2
exit 1
fi
exec "$binary_path" "''${runtime_args[@]}"
'';
in {
default = {
type = "app";
program = "${script}";
};
});
devShells = forEachSupportedSystem ({
pkgs,
deps,
libraryPathVar,
...
}: {
default =
pkgs.mkShell.override
{
# Override stdenv in order to change compiler:
# stdenv = pkgs.clangStdenv;
}
{
packages = deps;
${libraryPathVar} = pkgs.lib.makeLibraryPath deps;
};
});
};
}