-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-debian-package.nix
76 lines (67 loc) · 1.53 KB
/
build-debian-package.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
{
lib,
stdenv,
runCommand,
dpkg,
python3,
}:
let
python = python3.pythonOnBuildForHost.withPackages (ps: [ ps.debian ]);
in
{
name ? "package.deb",
# A list of paths for Debian package.
paths ? [ ],
extraCommands ? "",
# Contents of the DEBIAN/control file.
# Mandatory fields: Package, Version, Architecture, Maintainer, Description.
# See https://debian.org/doc/debian-policy/ch-controlfields.html#debian-binary-package-control-files-debian-control
#
# Architecture defaults to stdenv.hostPlatform.linuxArch.
debianControl ? { },
}:
let
pathsList = lib.toList paths;
in
stdenv.mkDerivation {
inherit name;
__structuredAttrs = true;
exportReferencesGraph.graph = pathsList;
unsafeDiscardReferences.out = true;
debianContent = pathsList;
debianControl = {
Architecture = stdenv.hostPlatform.linuxArch;
} // debianControl;
nativeBuildInputs = [
python
dpkg
];
debianBuilder = ./debian-builder.py;
dontUnpack = true;
dontConfigure = true;
dontFixup = true;
doInstallCheck = true;
buildPhase =
''
runHook preBuild
${python.executable} -- "$debianBuilder" --output pkgroot
''
+ lib.optionalString (extraCommands != "") ''
pushd pkgroot
${extraCommands}
popd
''
+ ''
runHook postBuild
'';
installPhase = ''
runHook preInstall
dpkg-deb --build pkgroot "$out"
runHook postInstall
'';
installCheckPhase = ''
runHook preInstallCheck
dpkg --simulate --install "$out"
runHook postInstallCheck
'';
}