-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
182 lines (159 loc) · 4.31 KB
/
flake.nix
File metadata and controls
182 lines (159 loc) · 4.31 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixgl = {
url = "github:guibou/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
};
shuvlog = {
url = "github:lypitech/shuvlog/0a81e259e91b9679e22714635b77e04b1d16aa1f";
flake = false;
};
yml-parser = {
url = "github:lypitech/yml-parser/f857e76a0e31676926094da4518475b7bc508ff8";
flake = false;
};
};
outputs = {
self,
nixpkgs,
nixgl,
shuvlog,
yml-parser,
...
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
# SELECT YOUR DRIVER HERE IF "Default" FAILS:
# Use `nixGLIntel` for Intel integrated graphics
# Use `nixGLNvidia` for proprietary Nvidia drivers
# Use `nixGLDefault` for Mesa/AMD (Standard)
nixGL = nixgl.packages.${system}.nixGLDefault;
nativeBuildInputs = with pkgs; [cmake pkg-config];
x11Libs = with pkgs; [
xorg.libxcb
xorg.libICE
xorg.libSM
xorg.libX11
xorg.libXext
xorg.libXrandr
xorg.libXcursor
xorg.libXi
xorg.libXinerama
xorg.xcbutilwm
xorg.xcbutilimage
xorg.xcbutilkeysyms
xorg.xcbutilrenderutil
xorg.xcbutil
xorg.xcbutilcursor
libxaw
libxcomposite
libxdamage
libxdmcp
libxkbfile
libxpm
libxres
libxscrnsaver
libxtst
libxv
libxxf86vm
libfontenc
];
buildInputs = with pkgs;
[
asio
nlohmann_json
imgui
raylib
]
++ x11Libs;
in {
devShells.${system} = {
default =
pkgs.mkShell.override {
stdenv = pkgs.gcc15Stdenv;
} {
inputsFrom = [
self.packages.${system}.r-type_client
self.packages.${system}.r-type_server
];
buildInputs = with pkgs;
[
stdenv.cc.cc.lib
cmake
conan
util-linux
]
++ x11Libs;
shellHook = ''
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath ([pkgs.stdenv.cc.cc.lib pkgs.util-linux pkgs.gtest] ++ x11Libs)}:$LD_LIBRARY_PATH"
'';
};
};
packages.${system} = {
r-type_client = pkgs.gcc15Stdenv.mkDerivation {
name = "r-type_client";
src = ./.;
inherit nativeBuildInputs buildInputs;
postPatch = ''
rm -rf lib/shuvlog lib/yml-parser
cp -r ${shuvlog} lib/shuvlog
cp -r ${yml-parser} lib/yml-parser
chmod -R +w lib/shuvlog lib/yml-parser
'';
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DUSE_CONAN=OFF"
"-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" # nix RPATH handling
];
buildPhase = ''
cmake --build . --parallel --target r-type_client
'';
# Wrap the binary with nixGL to ensure proper OpenGL driver usage
installPhase = ''
mkdir -p $out/bin
cp Client/r-type_client $out/bin/.r-type_client-real
cat > $out/bin/r-type_client <<EOF
#!/bin/sh
exec ${nixGL}/bin/nixGL $out/bin/.r-type_client-real "\$@"
EOF
chmod +x $out/bin/r-type_client
'';
};
r-type_server = pkgs.gcc15Stdenv.mkDerivation {
name = "r-type_server";
src = ./.;
inherit nativeBuildInputs buildInputs;
postPatch = ''
rm -rf lib/shuvlog lib/yml-parser
cp -r ${shuvlog} lib/shuvlog
cp -r ${yml-parser} lib/yml-parser
chmod -R +w lib/shuvlog lib/yml-parser
'';
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DUSE_CONAN=OFF"
];
buildPhase = ''
cmake --build . --parallel --target r-type_server
'';
installPhase = ''
mkdir -p $out/bin
cp Server/r-type_server $out/bin/
'';
};
};
apps.${system} = {
default = self.apps.${system}.r-type_client;
r-type_client = {
type = "app";
program = "${self.packages.${system}.r-type_client}/bin/r-type_client";
};
r-type_server = {
type = "app";
program = "${self.packages.${system}.r-type_server}/bin/r-type_server";
};
};
formatter.${system} = pkgs.alejandra;
};
}