Skip to content

Commit 527410b

Browse files
committed
add flake.nix
1 parent 9c68066 commit 527410b

File tree

1 file changed

+223
-0
lines changed

1 file changed

+223
-0
lines changed

flake.nix

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
{
2+
description = "RAYX simulation tool with CUDA, OpenMP, valgrind, and Ninja build";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
6+
};
7+
8+
outputs = { self, nixpkgs }:
9+
let
10+
system = "x86_64-linux";
11+
pkgs = import nixpkgs { inherit system; config.allowUnfree = true; };
12+
13+
src = pkgs.fetchgit {
14+
url = "https://github.com/hz-b/rayx";
15+
rev = "5694a0117e7d8e58a1b19f35202891270dc5ee91"; # git commit hash for desired version
16+
sha256 = "sha256-clfHvQK9JI/TWDmpXiTtBie4q++F9+F37uzTvLqvMlc="; # fill after build failure
17+
fetchSubmodules = true;
18+
};
19+
in {
20+
packages.${system} = rec {
21+
rayx = pkgs.stdenv.mkDerivation {
22+
pname = "rayx";
23+
version = "1.1.0";
24+
inherit src;
25+
26+
nativeBuildInputs = with pkgs; [
27+
cmake
28+
gcc
29+
llvmPackages.openmp
30+
ninja
31+
patchelf
32+
];
33+
34+
buildInputs = with pkgs; [
35+
hdf5
36+
];
37+
38+
configurePhase = ''
39+
mkdir build
40+
cd build
41+
cmake -G Ninja .. \
42+
-DCMAKE_BUILD_TYPE=Release \
43+
-DCMAKE_SKIP_BUILD_RPATH=ON \
44+
-DRAYX_ENABLE_CUDA=OFF \
45+
-DRAYX_REQUIRE_CUDA=ON \
46+
-DRAYX_ENABLE_OPENMP=ON \
47+
-DRAYX_REQUIRE_OPENMP=ON \
48+
-DRAYX_ENABLE_H5=ON \
49+
-DRAYX_REQUIRE_H5=ON \
50+
-DRAYX_WERROR=OFF \
51+
-DRAYX_BUILD_TESTS=OFF \
52+
-DRAYX_BUILD_RAYX_CLI=ON \
53+
-DRAYX_BUILD_RAYX_UI=OFF
54+
'';
55+
56+
buildPhase = ''
57+
ninja -v rayx
58+
'';
59+
60+
installPhase = ''
61+
mkdir -p $out/bin
62+
cp -r bin/release/Data $out/bin
63+
cp -r bin/release/rayx $out/bin
64+
65+
mkdir -p $out/lib
66+
cp -r lib/release/* $out/lib
67+
'';
68+
69+
meta.description = "TODO"; # TODO: write description
70+
};
71+
72+
rayx-cuda = pkgs.stdenv.mkDerivation {
73+
pname = "rayx-cuda";
74+
version = "1.1.0";
75+
inherit src;
76+
77+
nativeBuildInputs = with pkgs; [
78+
cmake
79+
gcc14 # pin gcc version for cuda version 12 compatibility
80+
llvmPackages.openmp
81+
ninja
82+
patchelf
83+
];
84+
85+
buildInputs = with pkgs; [
86+
hdf5
87+
cudaPackages.cuda_cudart
88+
cudaPackages.cuda_nvcc
89+
];
90+
91+
configurePhase = ''
92+
mkdir build
93+
cd build
94+
echo "g++ --version"
95+
g++ --version
96+
echo "nvcc --version"
97+
nvcc --version
98+
cmake -G Ninja .. \
99+
-DCMAKE_BUILD_TYPE=Release \
100+
-DCMAKE_SKIP_BUILD_RPATH=ON \
101+
-DRAYX_ENABLE_CUDA=ON \
102+
-DRAYX_REQUIRE_CUDA=ON \
103+
-DRAYX_ENABLE_OPENMP=ON \
104+
-DRAYX_REQUIRE_OPENMP=ON \
105+
-DRAYX_ENABLE_H5=ON \
106+
-DRAYX_REQUIRE_H5=ON \
107+
-DRAYX_WERROR=OFF \
108+
-DRAYX_BUILD_TESTS=OFF \
109+
-DRAYX_BUILD_RAYX_CLI=ON \
110+
-DRAYX_BUILD_RAYX_UI=OFF
111+
'';
112+
113+
buildPhase = ''
114+
ninja -v rayx
115+
'';
116+
117+
installPhase = ''
118+
mkdir -p $out/bin
119+
cp -r bin/release/Data $out/bin
120+
cp -r bin/release/rayx $out/bin
121+
122+
mkdir -p $out/lib
123+
cp -r lib/release/* $out/lib
124+
'';
125+
126+
meta.description = "TODO"; # TODO: write description
127+
};
128+
129+
rayx-run-tests = pkgs.stdenv.mkDerivation {
130+
pname = "rayx-run-tests";
131+
version = "1.1.0";
132+
inherit src;
133+
134+
nativeBuildInputs = with pkgs; [
135+
cmake
136+
gcc
137+
llvmPackages.openmp
138+
ninja
139+
patchelf
140+
valgrind
141+
];
142+
143+
buildInputs = with pkgs; [
144+
hdf5
145+
];
146+
147+
configurePhase = ''
148+
mkdir build
149+
cd build
150+
cmake -G Ninja .. \
151+
-DCMAKE_BUILD_TYPE=Release \
152+
-DRAYX_ENABLE_CUDA=OFF \
153+
-DRAYX_REQUIRE_CUDA=ON \
154+
-DRAYX_ENABLE_OPENMP=ON \
155+
-DRAYX_REQUIRE_OPENMP=ON \
156+
-DRAYX_ENABLE_H5=ON \
157+
-DRAYX_REQUIRE_H5=ON \
158+
-DRAYX_WERROR=ON \
159+
-DRAYX_BUILD_TESTS=ON \
160+
-DRAYX_BUILD_RAYX_CLI=ON \
161+
-DRAYX_BUILD_RAYX_UI=OFF
162+
'';
163+
164+
buildPhase = ''
165+
ninja -v rayx rayx-core-tst
166+
'';
167+
168+
# TODO: provide a better way to access test input file
169+
# TODO: testing should not be in the build phase, but rayx-core-tst depends on source directory being preset
170+
installPhase = ''
171+
mkdir -p $out
172+
173+
RML=../Intern/rayx-core/tests/input/METRIX_U41_G1_H1_318eV_PS_MLearn_v114.rml
174+
# run rayx with valgrind to catch memory issues
175+
valgrind --error-exitcode=42 ./bin/release/rayx -x -V -i $RML |& tee $out/log_rayx.txt
176+
# run tests
177+
./bin/release/rayx-core-tst -x |& tee $out/log_rayx-core-tst.txt
178+
'';
179+
180+
meta.description = "TODO"; # TODO: write description
181+
};
182+
183+
default = rayx;
184+
};
185+
186+
devShells.${system} = rec {
187+
rayx = pkgs.mkShell {
188+
buildInputs = with pkgs; [
189+
self.packages.${system}.rayx
190+
hdf5
191+
];
192+
193+
shellHook = ''
194+
echo "To get info about rayx, run: rayx --help"
195+
'';
196+
};
197+
198+
rayx-cuda = pkgs.mkShell {
199+
buildInputs = with pkgs; [
200+
self.packages.${system}.rayx
201+
hdf5
202+
cudaPackages.cuda_cudart
203+
];
204+
205+
shellHook = ''
206+
echo "To get info about rayx, run: rayx --help"
207+
'';
208+
};
209+
210+
rayx-run-tests = pkgs.mkShell {
211+
buildInputs = with pkgs; [
212+
self.packages.${system}.rayx-run-tests
213+
];
214+
215+
shellHook = ''
216+
echo "Inspect the test results in log_rayx.txt and log_rayx-core-tst.txt"
217+
'';
218+
};
219+
220+
default = rayx;
221+
};
222+
};
223+
}

0 commit comments

Comments
 (0)