summaryrefslogtreecommitdiffstats
path: root/pkgs/tools/package-management/akku/akkuDerivation.nix
blob: 59ede90eb1aa139b7c4495c59652c27ddd11403a (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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
  stdenv,
  akku,
  chez,
  guile,
  chibi,
  makeWrapper,
  lib,
  writeShellScriptBin,
}:
{
  pname,
  version,
  src,
  buildInputs ? [ ],
  r7rs ? false,
  nativeBuildInputs ? [ ],
  ...
}@args:
let
  parse-akku_ = writeShellScriptBin "parse-akku" "${guile}/bin/guile --no-auto-compile ${./parse-akku.scm} \"$@\"";
  parse-akku = "${parse-akku_}/bin/parse-akku";
in
stdenv.mkDerivation (
  {
    inherit version src;

    pname = "akku-${pname}";
    propagatedBuildInputs = buildInputs;
    buildInputs = [ ];
    nativeBuildInputs = [
      makeWrapper
      akku
      chez
      chibi
    ]
    ++ nativeBuildInputs;
    buildPhase = ''
      runHook preBuild

      # only install the project
      rm -f Akku.lock Akku.manifest

      akku install

      # make sure akku metadata is present during testing and onwards
      echo $PWD $CHEZSCHEMELIBDIRS \
      | sed "s/:/ /g" \
      | xargs find \
      | grep "metadata.sls" \
      | xargs ${parse-akku} merge ${pname} ${version} > temp___
      mv temp___ .akku/lib/akku/metadata.sls

      runHook postBuild
    '';
    checkPhase = ''
      IS_R7RS=false
      runHook preCheck


      propagated_chez=$CHEZSCHEMELIBDIRS
      propagated_chibi=$CHIBI_MODULE_PATH

      export CHEZSCHEMELIBDIRS="$PWD/.akku/lib:$CHEZSCHEMELIBDIRS"
      export CHIBI_MODULE_PATH="$PWD/.akku/lib:$CHIBI_MODULE_PATH"

      # Run all test .sps files if they exist
      # and run tests for libs mirrored from snow-fort.
      for path in $(find test* -type f | grep -e "\.sps") \
                  $(find . | grep "run-test" | grep "\.scm"); do
        echo Running test: $path
        [[ "\n$SKIP\n" =~ $(basename $path) ]] && continue
        if [ -x $path ]; then
          patchShebangs $path
          ./$path
        elif ${lib.trivial.boolToString r7rs}; then
          chibi-scheme $path
        else
          scheme-script $path
        fi
      done

      runHook postCheck

      export CHEZSCHEMELIBDIRS=$propagated_chez
      export CHIBI_MODULE_PATH=$propagated_chibi
    '';
    doCheck = true;
    installPhase = ''
      runHook preInstall

      mkdir -p $out/lib

      cd .akku

      rm -f bin/activate*

      cp -rL lib $out/lib/scheme-libs
      cp -rL bin $out/bin

      [ -d ffi ]    && cp -rL ffi $out/lib
      [ -d libobj ] && cp -rL libobj $out/lib

      CHEZSCHEMELIBDIRS="$out/lib/scheme-libs:$CHEZSCHEMELIBDIRS"

      # add support for other schemes
      for f in $out/bin/*
      do
      patchShebangs $f
      wrapProgram $f \
        --prefix CHEZSCHEMELIBDIRS : $CHEZSCHEMELIBDIRS
      done

      runHook postInstall
    '';
    meta = {
      inherit (akku.meta) platforms;
    }
    // args.meta or { };
    setupHook = ./setup-hook.sh;
  }
  // removeAttrs args [
    "name"
    "buildInputs"
    "meta"
    "nativeBuildInputs"
  ]
)