forked from disorderedmaterials/dissolve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
286 lines (266 loc) · 9.44 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
outdated.url = "github:NixOS/nixpkgs/nixos-21.05";
nixGL-src.url = "github:guibou/nixGL";
nixGL-src.flake = false;
};
outputs =
{ self, nixpkgs, outdated, home-manager, flake-utils, bundlers, nixGL-src }:
let
toml = pkgs: ((import ./nix/toml11.nix) { inherit pkgs; });
onedpl = pkgs:
((import ./nix/onedpl.nix) {
inherit (pkgs) lib stdenv fetchFromGitHub fetchpatch cmake;
tbb = pkgs.tbb_2021_8;
});
exe-name = mpi: gui:
if mpi then
"dissolve-mpi"
else
(if gui then "dissolve-gui" else "dissolve");
cmake-bool = x: if x then "ON" else "OFF";
version = "1.6.0";
base_libs = pkgs:
with pkgs; [
antlr4
antlr4.runtime.cpp
antlr4.runtime.cpp.dev
gbenchmark
cmake
cli11
fmt_8
fmt_8.dev
freetype
gsl
inetutils # for rsh
ninja
jre
pkg-config
pugixml
(toml pkgs)
];
gui_libs = system: pkgs:
with pkgs; [
glib
freetype
ftgl
libGL.dev
libglvnd
libglvnd.dev
qt6.qt3d
qt6.qtbase
qt6.qtbase.dev
qt6.qtquick3d
qt6.qtsvg
qt6.qtshadertools
qt6.qttools
qt6.qtdeclarative
qt6.qtdeclarative.dev
qt6.wrapQtAppsHook
];
check_libs = pkgs: with pkgs; [ gtest ];
in flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
let
pkgs = import nixpkgs { inherit system; };
nixGL = import nixGL-src { inherit pkgs; };
dissolve =
{ mpi ? false, gui ? false, threading ? true, checks ? true }:
assert (!(gui && mpi));
pkgs.stdenv.mkDerivation ({
inherit version;
pname = exe-name mpi gui;
src = ./. ;
buildInputs = base_libs pkgs ++ pkgs.lib.optional mpi pkgs.openmpi
++ pkgs.lib.optionals gui (gui_libs system pkgs)
++ pkgs.lib.optionals checks (check_libs pkgs)
++ pkgs.lib.optionals threading [
pkgs.tbb_2021_8
(onedpl pkgs)
(onedpl pkgs).dev
];
nativeBuildInputs = pkgs.lib.optionals gui [ pkgs.wrapGAppsHook ];
CTEST_OUTPUT_ON_FAILURE = "ON";
cmakeFlags = [
"-DCONAN=OFF"
"-G Ninja"
("-DMULTI_THREADING=" + (cmake-bool threading))
("-DPARALLEL=" + (cmake-bool mpi))
("-DGUI=" + (cmake-bool gui))
"-DBUILD_TESTS:bool=${cmake-bool checks}"
"-DCMAKE_BUILD_TYPE=Release"
];
doCheck = checks;
installPhase = ''
mkdir -p $out/bin
ls nix
mv ./$out/bin/* $out/bin/
'';
meta = with pkgs.lib; {
description = "";
homepage = "";
# license = licenses.unlicense;
maintainers = [ maintainers.rprospero ];
};
}) // (if checks then { QT_QPA_PLATFORM = "offscreen"; } else { });
mkSingularity = { mpi ? false, gui ? false, threading ? true }:
outdated.legacyPackages.${system}.singularity-tools.buildImage {
name = "${exe-name mpi gui}-${version}";
diskSize = 1024 * 50;
contents = [ (dissolve { inherit mpi gui threading; }) ];
runScript = if gui then
"${nixGL.nixGLIntel}/bin/nixGLIntel ${
dissolve { inherit mpi gui threading; }
}/bin/${exe-name mpi gui} $@"
else
"${dissolve { inherit mpi gui threading; }}/bin/${
exe-name mpi gui
} $@";
};
in {
checks.dissolve = dissolve { checks = true; };
checks.dissolve-gui = dissolve {
gui = true;
checks = true;
};
checks.dissolve-mpi = dissolve {
mpi = true;
gui = false;
checks = true;
};
checks.dissolve-threadless = dissolve {
threading = false;
gui = false;
checks = true;
};
defaultPackage = self.packages.${system}.dissolve;
devShells.default = pkgs.mkShell {
name = "dissolve-shell";
buildInputs = base_libs pkgs ++ gui_libs system pkgs
++ check_libs pkgs ++ (with pkgs; [
(pkgs.clang-tools.override {
llvmPackages = pkgs.llvmPackages_13;
})
(onedpl pkgs)
ccache
ccls
cmakeWithGui
cmake-format
cmake-language-server
conan
direnv
gdb
gtk3
nixGL.nixGLIntel
openmpi
qt6.qttools
tbb_2021_8
valgrind
]);
shellHook = ''
export XDG_DATA_DIRS=$GSETTINGS_SCHEMAS_PATH:$XDG_DATA_DIRS
export LIBGL_DRIVERS_PATH=${
pkgs.lib.makeSearchPathOutput "lib" "lib/dri"
[ pkgs.mesa.drivers ]
}
export LIBVA_DRIVERS_PATH=${
pkgs.lib.makeSearchPathOutput "out" "lib/dri"
[ pkgs.mesa.drivers ]
}
export __EGL_VENDOR_LIBRARY_FILENAMES=${pkgs.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json
export LD_LIBRARY_PATH=${
pkgs.lib.makeLibraryPath [ pkgs.mesa.drivers ]
}:${
pkgs.lib.makeSearchPathOutput "lib" "lib/vdpau" [ pkgs.libvdpau ]
}:${
pkgs.lib.makeLibraryPath [ pkgs.libglvnd ]
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
# export QT_PLUGIN_PATH="${pkgs.qt6.qt3d}/lib/qt-6/plugins:${pkgs.qt6.qtsvg}/lib/qt-6/plugins:$QT_PLUGIN_PATH"
export QT_PLUGIN_PATH="${pkgs.qt6.qtquick3d}/lib/qt-6/plugins:${pkgs.qt6.qt3d}/lib/qt-6/plugins:${pkgs.qt6.qtsvg}/lib/qt-6/plugins:$QT_PLUGIN_PATH"
'';
CMAKE_CXX_COMPILER_LAUNCHER =
"${pkgs.ccache}/bin/ccache";
CMAKE_C_COMPILER_LAUNCHER =
"${pkgs.ccache}/bin/ccache";
CMAKE_CXX_FLAGS_DEBUG = "-g -O0";
CXXL = "${pkgs.stdenv.cc.cc.lib}";
Qt6Quick3D_DIR = "${pkgs.qt6.qtquick3d}/lib/";
QML_IMPORT_PATH = "${pkgs.qt6.qtquick3d}/lib/qt-6/qml:${pkgs.qt6.qtdeclarative}/lib/qt-6/qml/";
QML2_IMPORT_PATH = "$${pkgs.qt6.qtquick3d}/lib/qt-6/qml:{pkgs.qt6.qtdeclarative}/lib/qt-6/qml/";
};
apps = {
dissolve-app =
flake-utils.lib.mkApp { drv = self.packages.${system}.dissolve; };
dissolve-mpi-app = flake-utils.lib.mkApp {
drv = self.packages.${system}.dissolve-mpi;
};
dissolve-gui-app = flake-utils.lib.mkApp {
drv = self.packages.${system}.dissolve-gui;
};
uploader = {
type = "app";
program = toString (pkgs.writeScript "upload.sh" ''
#!/bin/sh
set -e
if [ "$#" -ne 4 ] ; then
echo "Usage: nix run .#uploader HARBOR_USER HARBOR_SECRET IMAGE TAG" >&2
exit 1
fi
${
outdated.legacyPackages.${system}.singularity
}/bin/singularity remote login --username $1 --password $2 docker://harbor.stfc.ac.uk
${
outdated.legacyPackages.${system}.singularity
}/bin/singularity push $3 oras://harbor.stfc.ac.uk/isis_disordered_materials/dissolve:$4
'');
};
};
defaultApp =
flake-utils.lib.mkApp { drv = self.defaultPackage.${system}; };
packages = {
dissolve = dissolve { };
dissolve-threadless = dissolve {
gui = false;
threading = false;
};
dissolve-mpi = dissolve {
mpi = true;
gui = false;
};
dissolve-gui = dissolve { gui = true; };
singularity = mkSingularity { };
singularity-mpi = mkSingularity { mpi = true; };
singularity-gui = mkSingularity { gui = true; };
singularity-threadless = mkSingularity {
gui = false;
threading = false;
};
docker = pkgs.dockerTools.buildImage {
name = "dissolve";
tag = "latest";
config.Cmd = [ "${self.packages.${system}.dissolve}/bin/dissolve" ];
};
docker-gui = pkgs.dockerTools.buildImage {
name = "dissolve-gui";
tag = "latest";
config.ENTRYPOINT = [
"${nixGL.nixGLIntel}/bin/nixGLIntel"
"${self.packages.${system}.dissolve-gui}/bin/dissolve-gui"
];
};
docker-mpi = pkgs.dockerTools.buildImage {
name = "dissolve-mpi";
tag = "latest";
config.ENTRYPOINT =
[ "${self.packages.${system}.dissolve-mpi}/bin/dissolve-mpi" ];
};
};
homeConfigurations = {
"dissolve" = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = with self.homeManagerModules; [ user-env ];
};
};
homeManagerModule = { user-env = import ./nix/user-env.nix; };
});
}