summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/release/rpm-build.nix
blob: ee50f0a1e63b42eeeebb107bcd4cac755bbff984 (plain)
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
# This function builds an RPM from a source tarball that contains a
# RPM spec file (i.e., one that can be built using `rpmbuild -ta').

{
  name ? "rpm-build",
  diskImage,
  src,
  lib,
  vmTools,
  ...
}@args:

vmTools.buildRPM (

  removeAttrs args [ "vmTools" ]
  //

    {
      name = name + "-" + diskImage.name + (lib.optionalString (src ? version) "-${src.version}");

      preBuild = ''
        . ${./functions.sh}
        propagateImageName
        src=$(findTarball $src)
      '';

      postInstall = ''
        declare -a rpms rpmNames
        for i in $out/rpms/*/*.rpm; do
          if echo $i | grep -vq "\.src\.rpm$"; then
            echo "file rpm $i" >> $out/nix-support/hydra-build-products
            rpms+=($i)
            rpmNames+=("$(rpm -qp "$i")")
          fi
        done

        echo "installing ''${rpms[*]}..."
        rpm -Up ''${rpms[*]} --excludepath /nix/store

        eval "$postRPMInstall"

        echo "uninstalling ''${rpmNames[*]}..."
        rpm -e ''${rpmNames[*]} --nodeps

        for i in $out/rpms/*/*.src.rpm; do
          echo "file srpm $i" >> $out/nix-support/hydra-build-products
        done

        for rpmdir in $extraRPMs ; do
          echo "file rpm-extra $(ls $rpmdir/rpms/*/*.rpm | grep -v 'src\.rpm' | sort | head -1)" >> $out/nix-support/hydra-build-products
        done
      '';

      meta = (lib.optionalAttrs (args ? meta) args.meta) // {
        description = "RPM package for ${diskImage.fullName}";
      };
    }

)