-
Notifications
You must be signed in to change notification settings - Fork 3
/
windows-overlay.nix
104 lines (101 loc) · 3.53 KB
/
windows-overlay.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
final: prev: {
buildForWindows =
# the original package to override
pkg:
# where to find *.pc files in the given MSYS2 packages.
{ pkgConfigPrefix ? "/clang64/lib/pkgconfig"
# set of MSYS2 packages to download, patch and put into buildInputs
, deps ? { }
# list of executables in /bin where a `.exe` should be appended.
, appendExe ? [ ]
# name of the target system (in NixOS terminology)
, targetSystem }:
let
patch-pkg-config = import ./patch-pkg-config.nix;
fetchMsys = { tail, sha256, ... }:
builtins.fetchurl {
url =
"https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-${tail}";
inherit sha256;
};
pkgsFromPacman = name: input:
let src = fetchMsys input;
in prev.stdenvNoCC.mkDerivation
((builtins.removeAttrs input [ "tail" "sha256" ]) // {
name = "msys2-${name}";
inherit src;
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
nativeBuildInputs = [ prev.gnutar prev.zstd ];
unpackPhase = ''
runHook preUnpack
mkdir -p upstream
${prev.gnutar}/bin/tar -xvpf $src -C upstream \
--exclude .PKGINFO --exclude .INSTALL --exclude .MTREE --exclude .BUILDINFO
runHook postUnpack
'';
patchPhase = ''
runHook prePatch
shopt -s globstar
for pcFile in upstream/**/pkgconfig/*.pc; do
${patch-pkg-config prev} $pcFile $out
done
find -type f -name "*.a" -not -name "*.dll.a" -not -name "*main.a" -delete
runHook postPatch
'';
installPhase = ''
runHook preInstall
mkdir -p $out/
cp -rt $out upstream/*
runHook postInstall
'';
});
in pkg.overrideAttrs (origAttrs: {
inherit pkgConfigPrefix appendExe;
ZIG_TARGET = prev.zig.systemName.${targetSystem};
buildInputs = prev.lib.mapAttrsToList pkgsFromPacman deps;
targetSharePath = "../share";
postConfigure = ''
for item in $buildInputs; do
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$item$pkgConfigPrefix"
export CFLAGS="$CFLAGS -I$item/clang64/include"
done
'' + (origAttrs.postConfigure or "");
postInstall = (origAttrs.postInstall or "") + ''
for item in $buildInputs; do
cp -t $out/bin $item/clang64/bin/*.dll | true # allow deps without dlls
done
for item in $appendExe; do
mv $out/bin/$item $out/bin/$item.exe
done
'';
});
packageForWindows =
# the original package to override
pkg:
# where to find *.pc files in the given MSYS2 packages.
{ pkgConfigPrefix ? "/clang64/lib/pkgconfig"
# set of MSYS2 packages to download, patch and put into buildInputs
, deps ? { }
# list of executables in /bin where a `.exe` should be appended.
, appendExe ? [ ]
# name of the target system (in NixOS terminology)
, targetSystem }:
let
src = final.buildForWindows pkg {
inherit pkgConfigPrefix deps appendExe targetSystem;
};
in prev.stdenvNoCC.mkDerivation {
name = "${src.name}-win64.zip";
unpackPhase = ''
packDir=${src.name}-win64
mkdir -p $packDir
cp -rt $packDir --no-preserve=mode ${src}/*
'';
buildPhase = ''
${prev.zip}/bin/zip -r $packDir.zip $packDir
'';
installPhase = ''
cp $packDir.zip $out
'';
};
}