-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathderivation.nix
56 lines (48 loc) · 1.63 KB
/
derivation.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
{ stdenv, dotnet-runtime, dotnet-sdk, z3 }:
stdenv.mkDerivation {
name = "advent-of-code-2024-day17";
src = ./src;
nativeBuildInputs = [
dotnet-sdk
];
buildInputs = [
dotnet-runtime
z3
];
# https://stackoverflow.com/questions/46065777/is-it-possible-to-compile-a-single-c-sharp-code-file-with-the-net-core-roslyn-c
buildPhase = ''
sdk="$(echo "${dotnet-sdk.outPath}"/sdk/*)"
shared="$(echo "${dotnet-runtime.outPath}"/shared/Microsoft.NETCore.App/*)"
dotnet "$sdk/Roslyn/bincore/csc.dll" \
-r:"$shared/System.Private.CoreLib.dll" \
-r:"$shared/System.Runtime.dll" \
-r:"$shared/System.Runtime.InteropServices.dll" \
-r:"$shared/System.Collections.dll" \
-r:"$shared/System.ComponentModel.Primitives.dll" \
-r:"$shared/System.Diagnostics.Process.dll" \
-r:"$shared/System.Console.dll" \
-r:"$shared/System.IO.dll" \
-r:"$shared/System.Linq.dll" \
-r:"$shared/System.Text.RegularExpressions.dll" \
day17.cs
'';
installPhase = ''
mkdir -p $out/{bin,lib}
cp day17.exe $out/lib
cat <<EOF > $out/lib/day17.runtimeconfig.json
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "$(ls ${dotnet-runtime.outPath}/shared/Microsoft.NETCore.App)"
}
}
}
EOF
cat <<EOF > $out/bin/day17
#!/bin/bash
PATH="${z3.outPath}/bin:\$PATH" "${dotnet-runtime.outPath}/bin/dotnet" "\$(dirname "\$0")/../lib/day17.exe" "\$@"
EOF
chmod +x $out/bin/day17
'';
}