Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1/*
2 This function builds a binary tarball. The resulting binaries are
3 usually only useful if they are don't have any runtime dependencies
4 on any paths in the Nix store, since those aren't distributed in
5 the tarball. For instance, the binaries should be statically
6 linked: they can't depend on dynamic libraries in the store
7 (including Glibc).
8
9 The binaries are built and installed with a prefix of /usr/local by
10 default. They are installed by setting DESTDIR to a temporary
11 directory, so the Makefile of the package should support DESTDIR.
12*/
13
14{
15 src,
16 lib,
17 stdenv,
18 name ? "binary-tarball",
19 ...
20}@args:
21
22stdenv.mkDerivation (
23
24 {
25 # Also run a `make check'.
26 doCheck = true;
27
28 showBuildStats = true;
29
30 prefix = "/usr/local";
31
32 postPhases = [ "finalPhase" ];
33 }
34
35 // args
36 //
37
38 {
39 name = name + (lib.optionalString (src ? version) "-${src.version}");
40
41 postHook = ''
42 mkdir -p $out/nix-support
43 echo "$system" > $out/nix-support/system
44 . ${./functions.sh}
45
46 origSrc=$src
47 src=$(findTarball $src)
48
49 if test -e $origSrc/nix-support/hydra-release-name; then
50 releaseName=$(cat $origSrc/nix-support/hydra-release-name)
51 fi
52
53 installFlagsArray=(DESTDIR=$TMPDIR/inst)
54
55 # Prefix hackery because of a bug in stdenv (it tries to `mkdir
56 # $prefix', which doesn't work due to the DESTDIR).
57 prependToVar configureFlags "--prefix=$prefix"
58 dontAddPrefix=1
59 prefix=$TMPDIR/inst$prefix
60 '';
61
62 doDist = true;
63
64 distPhase = ''
65 mkdir -p $out/tarballs
66 tar cvfj $out/tarballs/''${releaseName:-binary-dist}.tar.bz2 -C $TMPDIR/inst .
67 '';
68
69 finalPhase = ''
70 for i in $out/tarballs/*; do
71 echo "file binary-dist $i" >> $out/nix-support/hydra-build-products
72 done
73
74 # Propagate the release name of the source tarball. This is
75 # to get nice package names in channels.
76 test -n "$releaseName" && (echo "$releaseName" >> $out/nix-support/hydra-release-name)
77 '';
78
79 meta = (lib.optionalAttrs (args ? meta) args.meta) // {
80 description = "Build of a generic binary distribution";
81 };
82
83 }
84)