-
Notifications
You must be signed in to change notification settings - Fork 9
/
flake.nix
267 lines (223 loc) · 8.81 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
{
description = "Stochastic Ordering-Based Railway Operations Simulation";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
# the llvm in nixpkgs isn't quite ready yet, but with the fixes from this PR
# it works
# FIXME(lgcl): change this to unstable once this is available
# https://github.com/NixOS/nixpkgs/pull/216273
unstable.url = "github:rrbutani/nixpkgs/fix/llvm-15-libcxx-linker-script-bug";
nix-filter.url = "github:numtide/nix-filter";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, unstable, nix-filter, flake-utils, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
name = "soro-s";
lib = nixpkgs.lib;
pkgs = unstable.legacyPackages.${system}.extend (final: super: {
# this produces a git package that will replace ssh pulls from github
# with https pulls. this is done, because pulling via ssh is very
# uncomfortable inside nix and many, if not all, dependencies
# (including transitive ones) that pkg pulls are pull via ssh
httpsGit = let
gitConfig = super.writeTextFile {
name = "https-git-config";
text = ''
[url "https://github.com/"]
insteadOf = git@github.com:
'';
destination = "/.gitconfig";
};
in super.symlinkJoin {
name = "https-git";
inherit (super.git) version;
paths = [ super.git ];
gitConfigHome = gitConfig;
nativeBuildInputs = [ super.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/git \
--set HOME $gitConfigHome
'';
};
# these are new variants of fetchgit and fetchFromGitHub using
# httpsGit. the originals are not overwritten so we don't built
# everything from source
fetchgit' = super.fetchgit.override { git = final.httpsGit; };
fetchFromGitHub' = super.fetchFromGitHub.override { fetchgit = final.fetchgit'; };
# make sure the tooling uses the up-to date toolchain
# FIXME(lgcl): drop this once llvmPackages is bumped up to llvmPackages_15
clang-tools = super.clang-tools.overrideAttrs (old: rec {
unwrapped = final.llvmPackages_15.clang-unwrapped;
version = lib.getVersion unwrapped;
clang = final.llvmPackages_15.clang;
meta = unwrapped.meta // {
description = "Standalone command line tools for C++ development";
maintainers = with lib.maintainers; [ patryk27 ];
};
});
# see: https://github.com/NixOS/nixpkgs/issues/214524
llvmPackages_15 = super.llvmPackages_15.extend (_: _: let
llvmPkgs = super.llvmPackages_15;
inherit (llvmPkgs) tools;
libraries = llvmPkgs.libraries.extend (libFinal: libSuper: {
# FIXME(lgcl): remove this, once this is resolved:
# https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1431745905
libcxxabi = libSuper.libcxxabi.overrideAttrs (old: {
postInstall = old.postInstall or "" + ''
install -m 644 ../../${old.pname}/include/__cxxabi_config.h "$dev/include"
'';
});
});
in { inherit tools libraries; } // libraries // tools);
});
llvmPkgs = pkgs.llvmPackages_15;
# nix-package pkg, used both to pre-fetch the pkg dependecies and during
# the actual cmake build of soro-s
motisPkg = llvmPkgs.stdenv.mkDerivation {
name = "pkg";
version = "0.14";
src = pkgs.fetchFromGitHub' {
owner = "motis-project";
repo = "pkg";
rev = "6fa6f5a9e723c4e9a13cf874500281b307a8adb7";
sha256 = "ya1kU1JXyBP985Dypkd4eXNwt/pslzgDEFJLxrsXCdU=";
fetchSubmodules = true;
};
nativeBuildInputs = [ pkgs.cmake ];
buildInputs = [];
installPhase = ''
install -m 555 -D -t $out/bin pkg
'';
};
# prefetchs a set of pkg managed dependencies, as this takes quite a
# while and they shouldn't change often (and the .pkg file makes it very
# easy to notice when they do change)
#
# args: specs is the .pkg file (as a path) and sha256 the output hash
buildPkgDeps = specs: sha256: pkgs.runCommand "pkg-deps" ({
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = sha256;
PKG_SPEC = specs;
nativeBuildInputs = [ motisPkg pkgs.httpsGit pkgs.cacert ];
}) ''
cp $PKG_SPEC .pkg
pkg load -h
find deps -name .git -type d -prune -exec rm -rf {} \;
mkdir -p $out
cp -r deps $out
'';
pkgsDir = buildPkgDeps ./.pkg "jcsfB8ssEvD0wxxccpkA+KSU7/XV5WAIUbJ9QJFnzgU=";
depsDir = pkgs.runCommand "soro-s-deps-dir" {
PKG_DEPS = pkgsDir;
} ''
cp -r "$PKG_DEPS/deps" .
chmod -R +w deps
mkdir -p $out
cp -r deps $out
'';
# bypass buildcache (because -DNOBUILDCACHE=1 does not fully work when
# building the server/client)
buildcacheStub = pkgs.writeScriptBin "buildcache" ''
#!/bin/sh
exec "$@"
'';
# disable all pkg calls
pkgStub = pkgs.writeScriptBin "pkg" ''
#!/bin/sh
echo "skipping pkg invocation with args:" "$@"
exit 0
'';
soroSrc = nix-filter.lib.filter {
root = ./.;
include = [
"cmake"
"include"
"resources"
"src"
"test"
"tools"
"web"
".pkg"
"CMakeLists.txt"
"CMakePresets.json"
"logo.png"
];
};
build =
{ useClang ? true
, version ? "0.0.1"
, preset ? if useClang then "clang-release" else "gcc-release"
, target ? "soro-server"
} : let
stdenv = if useClang then llvmPkgs.libcxxStdenv else pkgs.gcc11Stdenv;
in stdenv.mkDerivation {
name = "soro-s";
inherit version;
src = soroSrc;
DEPS_DIR = depsDir;
nativeBuildInputs = [
pkgs.cmake pkgs.ninja
buildcacheStub pkgStub
] ++ (if useClang then [
llvmPkgs.lld
] else []);
buildInputs = [ pkgs.glibc.static ];
# provide pre-built pkg dependencies
# provide stub-pkg at download location
preConfigure = ''
cp -r $DEPS_DIR/deps .
chmod -R +w deps
'';
buildPhase = ''
cmake --build ${preset} --target ${target}
'';
installPhase = ''
find ${preset} -maxdepth 1 -executable -type f \! -name pkg \
-exec install -m 555 -D -t $out/bin {} \;
cp -r ${preset}/server_resources $out/bin/
cp -r ../resources $out/bin/
'';
checkPhase = ''
runHook preCheck
cmake --build ${preset} --target soro-test
./${preset}/soro-test
runHook postCheck
'';
cmakeFlags = [ "--preset" preset ];
};
py = nixpkgs.legacyPackages.${system}.python3.withPackages (pp: [ pp.python-lsp-server pp.selenium ]);
in rec {
packages = {
${name} = packages."${name}-clang";
"${name}-gcc" = build { useClang = false; };
"${name}-clang" = build { useClang = true; };
default = self.packages.${system}.${name};
inherit motisPkg depsDir;
inherit llvmPkgs;
inherit (llvmPkgs) bintools;
};
checks = lib.genAttrs
[ "${name}-gcc" "${name}-clang" ]
(p: packages.${p}.overrideAttrs (_: { doCheck = true; }));
devShells = {
default = pkgs.mkShell {
packages = [
pkgs.clang-tools motisPkg llvmPkgs.libcxxClang
py pkgs.chromedriver pkgs.chromium
] ++ packages."${name}-clang".nativeBuildInputs
++ packages."${name}-clang".buildInputs
++ packages."${name}-gcc".nativeBuildInputs
++ packages."${name}-gcc".buildInputs;
};
};
hydraJobs = let
prefixAttrNames = prefix: lib.mapAttrs' (n: lib.nameValuePair "${prefix}-${n}");
in lib.foldr (l: r: l // r) {} ([
(prefixAttrNames "package" packages)
(prefixAttrNames "check" checks)
(prefixAttrNames "shell" devShells)
]);
});
}