-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebian-overlay.nix
139 lines (137 loc) · 4.62 KB
/
debian-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
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
final: prev: {
buildForDebian =
# the original package to override
pkg:
# debian package's name
{ name
# debian package's verison
, version
# where to find *.pc files in the given debian packages.
, pkgConfigPrefix ? "/usr/lib/pkgconfig"
# default include directories inside dependencies.
, includeDirs ? [
"/usr/include"
]
# set of debian packages to download, patch and put into buildInputs
, deps ? { }
# name of the target system (in NixOS terminology)
, targetSystem }:
let
patch-pkg-config = import ./patch-pkg-config.nix;
fetchDeb = { path, sha256, ... }:
builtins.fetchurl {
url = "http://deb.debian.org/${path}";
inherit sha256;
};
pkgFromDebs = name: input:
let
hasDev = builtins.hasAttr "dev" input;
srcs = [ (fetchDeb input) ]
++ (if hasDev then [ (fetchDeb input.dev) ] else [ ]);
basePkg = prev.stdenvNoCC.mkDerivation {
name = "dpkg-${name}";
inherit srcs;
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
unpackPhase = ''
mkdir -p upstream
${prev.dpkg}/bin/dpkg-deb -x ${builtins.elemAt srcs 0} upstream
'' + (if hasDev then ''
${prev.dpkg}/bin/dpkg-deb -x ${builtins.elemAt srcs 1} upstream
'' else
"");
patchPhase = ''
runHook prePatch
shopt -s globstar
for pcFile in upstream/**/pkgconfig/*.pc; do
${patch-pkg-config prev} $pcFile $out
done
rm -f upstream/**/*.a
runHook postPatch
'';
installPhase = ''
runHook preInstall
mkdir -p $out/
cp -rt $out upstream/*
runHook postInstall
'';
};
in if builtins.hasAttr "overrideAttrs" input then
basePkg.overrideAttrs input.overrideAttrs
else
basePkg;
debianArch = { "armv7l-hf-multiplatform" = "armhf"; };
in pkg.overrideAttrs (origAttrs: {
inherit pkgConfigPrefix includeDirs;
ZIG_TARGET = prev.zig.systemName.${targetSystem};
buildInputs = prev.lib.mapAttrsToList pkgFromDebs deps;
passthru.deb = {
Package = name;
Version = version;
Architecture = debianArch.${targetSystem};
Depends = prev.lib.concatStringsSep ", " (prev.lib.mapAttrsToList
(key: value: "${value.packageName} (>= ${value.minVersion})")
(prev.lib.filterAttrs (_: builtins.hasAttr "packageName") deps));
};
targetSharePath = "/usr/share/${name}";
postConfigure = ''
for item in $buildInputs; do
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$item$pkgConfigPrefix"
for dir in $includeDirs; do
export CFLAGS="$CFLAGS -I$item$dir"
done
done
'' + (origAttrs.postConfigure or "");
});
packageForDebian =
# the original package to override
pkg:
# debian package's name
{ name
# debian package's verison
, version
# where to find *.pc files in the given debian packages.
, pkgConfigPrefix ? "/usr/lib/pkgconfig"
# default include directories inside dependencies.
, includeDirs ? [
"/usr/include"
]
# set of debian packages to download, patch and put into buildInputs
, deps ? { }
# name of the target system (in NixOS terminology)
, targetSystem }@args':
let
name = src.deb.Package;
version = src.deb.Version;
src = final.buildForDebian pkg args';
in prev.stdenvNoCC.mkDerivation {
name = "${name}-${version}.deb";
CONTROL = ''
Package: ${name}
Version: ${version}
Section: base
Priority: optional
Architecture: ${src.deb.Architecture}
Depends: ${src.deb.Depends}
Maintainer: ${prev.lib.concatStringsSep ", " src.meta.maintainers}
Description: ${src.meta.description}
'';
unpackPhase = ''
packDir=${name}_${version}
mkdir -p $packDir/{DEBIAN,usr}
cp -rt $packDir/usr --no-preserve=mode ${src}/bin | true # allow missing bin
if [ -e ${src}/share ]; then
mkdir -p $packDir/usr/share/${name}
cp -rt $packDir/usr/share/${name} --no-preserve=mode ${src}/share/*
fi
'';
configurePhase = ''
printenv CONTROL > ${name}_${version}/DEBIAN/control
'';
buildPhase = ''
${prev.dpkg}/bin/dpkg-deb --build ${name}_${version}
'';
installPhase = ''
cp *.deb $out
'';
};
}