-
Notifications
You must be signed in to change notification settings - Fork 62
/
flake.nix
267 lines (249 loc) · 8.21 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
#nix-appimage = {
# url = "github:ralismark/nix-appimage";
#};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, ... }:
let
# Systems supported to build this package
buildSystems = [
"i686-linux"
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
"powerpc64le-linux"
#"riscv64-linux"
];
#Systems that don't need overlay
stableSystems = [
"x86_64-linux"
"aarch64-linux"
];
# Systems targetted for this package
crossSystems = (map (system: { name = system; inherit system; } ) buildSystems) ++ [
{
name = "x86_64-linux-musl";
system = {
config = "x86_64-unknown-linux-musl";
};
}
{
name = "aarch64-linux-musl";
system = {
config = "aarch64-unknown-linux-musl";
};
}
{
name = "x86_64-mingwW64";
system = {
config = "x86_64-w64-mingw32";
libc = "msvcrt";
#isStatic = true;
};
}
];
# Helper to provide system-specific attributes
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f { inherit system; });
# Handle feature variants
mkPerimeterPackages = {
prefix ? "",
isStatic ? false,
pkgs,
}: let
prefix_sep = if prefix == "" then "" else prefix + "_";
in [
{
name = if prefix == "" then "default" else prefix;
value = pkgs.callPackage ./perimeter.nix {
inherit isStatic;
src = self;
flag_d3d9 = true;
flag_sokol = true;
};
}
{
name = "${prefix_sep}d3d9";
value = pkgs.callPackage ./perimeter.nix {
inherit isStatic;
src = self;
flag_d3d9 = true;
flag_sokol = false;
};
}
{
name = "${prefix_sep}sokol";
value = pkgs.callPackage ./perimeter.nix {
inherit isStatic;
src = self;
flag_d3d9 = false;
flag_sokol = true;
};
}
{
name = "${prefix_sep}debug";
value = pkgs.callPackage ./perimeter.nix {
inherit isStatic;
src = self;
flag_debug = true;
flag_d3d9 = true;
flag_sokol = true;
};
}
];
#Overlays to apply
overlays = [
#Allow all platforms for these pkgs
(self: super: (
nixpkgs.lib.genAttrs [ "SDL2_mixer" "SDL2_image" "SDL2_net" ] (name:
super.${name}.overrideAttrs (_: rec {
meta.platforms = super.lib.platforms.all;
})
)
))
#Overlay to trim dependencies pulling too much subdependencies
(self: super: {
#Stop pulling whole linux for a game
systemdMinimal = null;
systemd = null;
libusb1 = null;
gst_all_1 = null;
modemmanager = null;
pipewire = null;
e2fsprogs = null;
flac = null;
libavif = null;
#Populate osxMinVersion in stdenv for libvpx
libvpx = super.libvpx.override {
stdenv = super.stdenv // (if (!super.stdenv.hostPlatform.isDarwin || (builtins.hasAttr "osxMinVersion" super.stdenv.hostPlatform)) then {} else {
hostPlatform = super.stdenv.hostPlatform // {
osxMinVersion = super.stdenv.hostPlatform.darwinMinVersion;
};
});
};
dbus = super.dbus.override {
enableSystemd = false;
};
pulseaudio = super.pulseaudio.override {
libOnly = true;
udevSupport = false;
bluetoothSupport = false;
useSystemd = false;
};
#FFMPEG, only pick what actually needs
ffmpeg = (super.ffmpeg.override {
ffmpegVariant = "headless";
withHeadlessDeps = false;
withOpus = true;
withZlib = true;
withVpx = !super.stdenv.hostPlatform.isMinGW
&& !super.stdenv.hostPlatform.isDarwin;
buildAvcodec = true;
buildAvdevice = false;
buildAvfilter = true;
buildAvformat = true;
buildAvresample = true;
buildAvutil = true;
buildPostproc = false;
buildSwresample = true;
buildSwscale = true;
}).overrideAttrs (attrs: rec {
#Disable checks: libavutil/tests/pixelutils.c:68:41: error: 'sad_c' undeclared (first use in this function)
doCheck = false;
configureFlags = attrs.configureFlags ++ [
"--disable-everything"
"--enable-demuxer=rawvideo,bink,matroska"
"--enable-decoder=rawvideo,bink,binkaudio_dct,opus,vp9"
"--enable-parser=vp9"
"--enable-filter=aresample,aformat"
"--enable-protocol=file"
"--disable-ffplay"
"--disable-ffprobe"
"--disable-ffmpeg"
"--disable-iconv"
];
});
SDL2 = super.SDL2.override {
#Apparently on MinGW we need to add static generation
withStatic = super.stdenv.hostPlatform.isStatic || super.stdenv.hostPlatform.isWindows;
pipewireSupport = false;
libdecorSupport = false;
};
SDL2_mixer = super.SDL2_mixer.override {
flac = null;
fluidsynth = null;
libmodplug = null;
mpg123 = null;
opusfile = null;
smpeg2 = null;
timidity = "";
};
SDL2_image = super.SDL2_image.override {
libpng = null;
libjpeg = null;
libtiff = null;
giflib = null;
libwebp = null;
libXpm = null;
};
})
];
in {
# Main packages
packages = forSystems buildSystems ({ system }:
let
localSystem = system;
in (
builtins.listToAttrs (
mkPerimeterPackages {
pkgs = import nixpkgs {
inherit system;
overlays = if (builtins.elem system stableSystems) then [] else overlays;
};
} ++ (builtins.concatLists (map ({ name, system }:
let
target_pkgs = import nixpkgs {
inherit localSystem;
crossSystem = system;
overlays = if (builtins.elem system stableSystems) then [] else overlays;
};
validPlatform = !target_pkgs.stdenv.hostPlatform.isDarwin
|| (
#Add darwin cross only if build platform is darwin
target_pkgs.stdenv.buildPlatform.isDarwin && target_pkgs.stdenv.hostPlatform.isDarwin
#AARCH64 crosscompiling x86_64 is broken on darwin for now
#https://github.com/NixOS/nixpkgs/issues/180771
&& !(localSystem == "aarch64-darwin" && name == "x86_64-darwin")
)
;
in target_pkgs.lib.optionals validPlatform (mkPerimeterPackages {
pkgs = target_pkgs;
prefix = "platform_${name}";
})) crossSystems)
)
)
)
);
# Dev envs
devShells = forSystems buildSystems ({ system }: (
let
package = self.packages.${system}.default;
pkgs = import nixpkgs { inherit system; };
mkDevShell = extras: pkgs.mkShell {
buildInputs = package.buildInputs ++ package.nativeBuildInputs ++ extras;
};
in {
default = mkDevShell [];
clang = mkDevShell [ pkgs.clang ];
}
));
};
}