summary refs log tree commit diff
path: root/pkgs/build-support/release/binary-tarball.nix
blob: 168343c8082141922c0c499046aa2bb91a93691a (plain) (blame)
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
/* This function builds a binary tarball.  The resulting binaries are
   usually only useful if they are don't have any runtime dependencies
   on any paths in the Nix store, since those aren't distributed in
   the tarball.  For instance, the binaries should be statically
   linked: they can't depend on dynamic libraries in the store
   (including Glibc).

   The binaries are built and installed with a prefix of /usr/local by
   default.  They are installed by setting DESTDIR to a temporary
   directory, so the Makefile of the package should support DESTDIR.
*/

{ src, stdenv
, name ? "binary-tarball"
, ... } @ args:

stdenv.mkDerivation (

  {
    # Also run a `make check'.
    doCheck = true;

    showBuildStats = true;

    prefix = "/usr/local";

    postPhases = "finalPhase";
  }

  // args //

  {
    name = name + (if src ? version then "-" + src.version else "");

    postHook = ''
      mkdir -p $out/nix-support
      echo "$system" > $out/nix-support/system
      . ${./functions.sh}

      origSrc=$src
      src=$(findTarball $src)

      if test -e $origSrc/nix-support/hydra-release-name; then
          releaseName=$(cat $origSrc/nix-support/hydra-release-name)
      fi

      installFlagsArray=(DESTDIR=$TMPDIR/inst)

      # Prefix hackery because of a bug in stdenv (it tries to `mkdir
      # $prefix', which doesn't work due to the DESTDIR).
      configureFlags="--prefix=$prefix $configureFlags"
      dontAddPrefix=1
      prefix=$TMPDIR/inst$prefix
    '';

    doDist = true;

    distPhase = ''
      mkdir -p $out/tarballs
      tar cvfj $out/tarballs/''${releaseName:-binary-dist}.tar.bz2 -C $TMPDIR/inst .
    '';

    finalPhase = ''
      for i in $out/tarballs/*; do
          echo "file binary-dist $i" >> $out/nix-support/hydra-build-products
      done

      # Propagate the release name of the source tarball.  This is
      # to get nice package names in channels.
      test -n "$releaseName" && (echo "$releaseName" >> $out/nix-support/hydra-release-name)
    '';

    meta = (if args ? meta then args.meta else {}) // {
      description = "Build of a generic binary distribution";
    };

  }
)