nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 makeWrapper,
5 pkg-config,
6 mono,
7 dotnetbuildhelpers,
8}:
9
10attrsOrig@{
11 pname,
12 version,
13 nativeBuildInputs ? [ ],
14 xBuildFiles ? [ ],
15 xBuildFlags ? [ "/p:Configuration=Release" ],
16 outputFiles ? [ "bin/Release/*" ],
17 dllFiles ? [ "*.dll" ],
18 exeFiles ? [ "*.exe" ],
19 # Additional arguments to pass to the makeWrapper function, which wraps
20 # generated binaries.
21 makeWrapperArgs ? [ ],
22 ...
23}:
24let
25 arrayToShell = (a: toString (map (lib.escape (lib.stringToCharacters "\\ ';$`()|<>\t")) a));
26
27 attrs = {
28 inherit pname version;
29
30 nativeBuildInputs = [
31 pkg-config
32 makeWrapper
33 dotnetbuildhelpers
34 mono
35 ]
36 ++ nativeBuildInputs;
37
38 configurePhase = ''
39 runHook preConfigure
40
41 [ -z "''${dontPlacateNuget-}" ] && placate-nuget.sh
42 [ -z "''${dontPlacatePaket-}" ] && placate-paket.sh
43 [ -z "''${dontPatchFSharpTargets-}" ] && patch-fsharp-targets.sh
44
45 runHook postConfigure
46 '';
47
48 buildPhase = ''
49 runHook preBuild
50
51 echo Building dotNET packages...
52
53 # Probably needs to be moved to fsharp
54 if pkg-config FSharp.Core
55 then
56 export FSharpTargetsPath="$(dirname $(pkg-config FSharp.Core --variable=Libraries))/Microsoft.FSharp.Targets"
57 fi
58
59 ran=""
60 for xBuildFile in ${arrayToShell xBuildFiles} ''${xBuildFilesExtra}
61 do
62 ran="yes"
63 xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray} $xBuildFile
64 done
65
66 [ -z "$ran" ] && xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray}
67
68 runHook postBuild
69 '';
70
71 dontStrip = true;
72
73 installPhase = ''
74 runHook preInstall
75
76 target="$out/lib/dotnet/${pname}"
77 mkdir -p "$target"
78
79 cp -rv ${arrayToShell outputFiles} "''${outputFilesArray[@]}" "$target"
80
81 if [ -z "''${dontRemoveDuplicatedDlls-}" ]
82 then
83 pushd "$out"
84 remove-duplicated-dlls.sh
85 popd
86 fi
87
88 set -f
89 for dllPattern in ${arrayToShell dllFiles} ''${dllFilesArray[@]}
90 do
91 set +f
92 for dll in "$target"/$dllPattern
93 do
94 [ -f "$dll" ] || continue
95 if pkg-config $(basename -s .dll "$dll")
96 then
97 echo "$dll already exported by a buildInputs, not re-exporting"
98 else
99 create-pkg-config-for-dll.sh "$out/lib/pkgconfig" "$dll"
100 fi
101 done
102 done
103
104 set -f
105 for exePattern in ${arrayToShell exeFiles} ''${exeFilesArray[@]}
106 do
107 set +f
108 for exe in "$target"/$exePattern
109 do
110 [ -f "$exe" ] || continue
111 mkdir -p "$out"/bin
112 commandName="$(basename -s .exe "$(echo "$exe" | tr "[A-Z]" "[a-z]")")"
113 makeWrapper \
114 "${mono}/bin/mono" \
115 "$out"/bin/"$commandName" \
116 --add-flags "\"$exe\"" \
117 ''${makeWrapperArgs}
118 done
119 done
120
121 runHook postInstall
122 '';
123 };
124in
125stdenv.mkDerivation (attrs // (removeAttrs attrsOrig [ "nativeBuildInputs" ]))