aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/development/compilers/gerbil/gerbil-support.nix
blob: e3f4bb0e0d254e21cca7297a9bfd1af879b4b14d (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
{ pkgs, gccStdenv, callPackage, fetchFromGitHub }:
# See ../gambit/build.nix regarding gccStdenv

rec {
  # Gerbil libraries
  gerbilPackages-unstable = {
    gerbil-utils = callPackage ./gerbil-utils.nix { };
    gerbil-crypto = callPackage ./gerbil-crypto.nix { };
    gerbil-poo = callPackage ./gerbil-poo.nix { };
    gerbil-persist = callPackage ./gerbil-persist.nix { };
    gerbil-ethereum = callPackage ./gerbil-ethereum.nix { };
  };

  # Use this function in any package that uses Gerbil libraries, to define the GERBIL_LOADPATH.
  gerbilLoadPath =
    gerbilInputs : builtins.concatStringsSep ":" (map (x : x + "/gerbil/lib") gerbilInputs);

  # Use this function to create a Gerbil library. See gerbil-utils as an example.
  gerbilPackage = {
    pname, version, src, meta, gerbil-package,
    git-version ? "", version-path ? "",
    gerbil ? pkgs.gerbil-unstable,
    gambit-params ? pkgs.gambit-support.stable-params,
    gerbilInputs ? [],
    buildInputs ? [],
    softwareName ? ""} :
    let buildInputs_ = buildInputs; in
    gccStdenv.mkDerivation rec {
      inherit src meta pname version;
      passthru = { inherit gerbil-package version-path ;};
      buildInputs = [ gerbil ] ++ gerbilInputs ++ buildInputs_;
      postPatch = ''
        set -e ;
        if [ -n "${version-path}.ss" ] ; then
          echo -e '(import :clan/versioning${builtins.concatStringsSep ""
                     (map (x : if x.passthru.version-path != ""
                               then " :${x.passthru.gerbil-package}/${x.passthru.version-path}" else "")
                          gerbilInputs)
                     })\n(register-software "${softwareName}" "v${git-version}")\n' > "${passthru.version-path}.ss"
        fi
        patchShebangs . ;
      '';

      postConfigure = ''
        export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
        export GERBIL_PATH=$PWD/.build
        export GERBIL_LOADPATH=${gerbilLoadPath gerbilInputs}
        ${pkgs.gambit-support.export-gambopt gambit-params}
      '';

      buildPhase = ''
        runHook preBuild
        ./build.ss
        runHook postBuild
      '';

      installPhase = ''
        runHook preInstall
        mkdir -p $out/gerbil/lib
        cp -fa .build/lib $out/gerbil/
        bins=(.build/bin/*)
        if [ 0 -lt ''${#bins} ] ; then
          cp -fa .build/bin $out/gerbil/
          mkdir $out/bin
          cd $out/bin
          ln -s ../gerbil/bin/* .
        fi
        runHook postInstall
      '';

      dontFixup = true;
    };
}