summary refs log tree commit diff
path: root/pkgs/applications/science/math/gap/default.nix
blob: 87071c0a7ae351e416d387767285b7cba3e539ec (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
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
{ stdenv
, fetchurl
, fetchpatch
, m4
, gmp
# don't remove any packages -- results in a ~1.3G size increase
# see https://github.com/NixOS/nixpkgs/pull/38754 for a discussion
, keepAllPackages ? true
}:

stdenv.mkDerivation rec {
  pname = "gap";
  # https://www.gap-system.org/Releases/
  # newer versions (4.9.0) are available, but still considered beta (https://github.com/gap-system/gap/wiki/GAP-4.9-release-notes)
  version = "4r8p10";
  pkgVer = "2018_01_15-13_02";
  name = "${pname}-${version}";

  src = let
    # 4r8p10 -> 48
    majorminor = stdenv.lib.replaceStrings ["r"] [""] (
      builtins.head (stdenv.lib.splitString "p" version) # 4r8p10 -> 4r8
    );
  in
    fetchurl {
    url = "https://www.gap-system.org/pub/gap/gap${majorminor}/tar.bz2/gap${version}_${pkgVer}.tar.bz2";
    sha256 = "0wzfdjnn6sfiaizbk5c7x44rhbfayis4lf57qbqqg84c7dqlwr6f";
  };

  # remove all non-essential packages (which take up a lot of space)
  preConfigure = stdenv.lib.optionalString (!keepAllPackages) ''
    find pkg -type d -maxdepth 1 -mindepth 1 \
       -not -name 'GAPDoc-*' \
       -not -name 'autpgrp*' \
       -exec echo "Removing package {}" \; \
       -exec rm -r {} \;
  '';

  configureFlags = [ "--with-gmp=system" ];
  buildInputs = [ m4 gmp ];

  patches = [
    #  fix infinite loop in writeandcheck() when writing an error message fails.
    (fetchpatch {
      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/gap/patches/writeandcheck.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
      sha256 = "1r1511x4kc2i2mbdq1b61rb6p3misvkf1v5qy3z6fmn6vqwziaz1";
    })
  ];

  doCheck = true;
  checkTarget = "testinstall";
  # "teststandard" is a superset of testinstall. It takes ~1h instead of ~1min.
  # tests are run twice, once with all packages loaded and once without
  # checkTarget = "teststandard";

  preCheck = ''
    # gap tests check that the home directory exists
    export HOME="$TMP/gap-home"
    mkdir -p "$HOME"
  '';

  postCheck = ''
    # The testsuite doesn't exit with a non-zero exit code on failure.
    # It leaves its logs in dev/log however.

    # grep for error messages
    if grep ^##### dev/log/*; then
        exit 1
    fi
  '';

  postBuild = ''
    pushd pkg
    bash ../bin/BuildPackages.sh
    popd
  '';

  installPhase = ''
    mkdir -p "$out/bin" "$out/share/gap/"

    cp -r . "$out/share/gap/build-dir"

    sed -e "/GAP_DIR=/aGAP_DIR='$out/share/gap/build-dir/'" -i "$out/share/gap/build-dir/bin/gap.sh"

    ln -s "$out/share/gap/build-dir/bin/gap.sh" "$out/bin/gap"
  '';

  meta = with stdenv.lib; {
    description = "Computational discrete algebra system";
    maintainers = with maintainers;
    [
      raskin
      chrisjefferson
    ];
    platforms = platforms.all;
    # keeping all packages increases the package size considerably, wchich
    # is why a local build is preferable in that situation. The timeframe
    # is reasonable and that way the binary cache doesn't get overloaded.
    hydraPlatforms = stdenv.lib.optionals (!keepAllPackages) platforms;
    license = licenses.gpl2;
    homepage = http://gap-system.org/;
  };
}