~evhan/beaker

ref: 3679375a8efe39d4cecd26d5ea483dc00927c84a beaker/default.nix -rw-r--r-- 2.2 KiB
3679375aEvan Hanson Extend `eggCache` to allow specifying eggs directly 8 months ago
                                                                                
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
{ pkgs ? import <nixpkgs> {} }:

with pkgs;

rec {
  repositoryPath = "lib/chicken/${toString chicken.binaryVersion}";

  eggCache = {
    name ? "eggs",
    eggs, hash,
    includeDependencies ? true,
    includeTestDependencies ? false,
  }: runCommand name {
    buildInputs = [ chicken ];
    outputHash = hash;
    outputHashMode = "recursive";
    CHICKEN_EGG_CACHE = "eggs";
  } ''
    chicken-install -retrieve \
      ${lib.optionalString (includeDependencies) "-recursive"} \
      ${lib.optionalString (includeTestDependencies) "-test"} \
      ${if builtins.typeOf eggs == "path"
        then "-from-list ${eggs}"
        else if builtins.typeOf eggs == "list"
        then lib.concatStringsSep " " (map (egg: "${egg.name}:${egg.version}") eggs)
        else ""}
    mv $CHICKEN_EGG_CACHE $out
    rm $out/*/STATUS
    rm $out/*/TIMESTAMP
  '';

  eggProgram = {
    name, src,
    buildInputs ? [],
    eggCache ? null,
    preUnpack ? "",
    preBuild ? "",
    ...
  } @ args: stdenv.mkDerivation {
    name = name;
    src = src;
    buildInputs = [ chicken makeWrapper ] ++ buildInputs;

    CHICKEN_EGG_CACHE = "/build/eggs";
    CHICKEN_INSTALL_PREFIX = "/build/out";
    CHICKEN_INSTALL_REPOSITORY = "/build/out/${repositoryPath}";
    CHICKEN_REPOSITORY_PATH = "/build/out/${repositoryPath}";

    preUnpack = lib.optionalString (eggCache != null) ''
      cp -R -L ${eggCache} $CHICKEN_EGG_CACHE
      chmod -R +w $CHICKEN_EGG_CACHE
    '' + preUnpack;

    preBuild = lib.optionalString (eggCache != null) ''
      chicken-install -cached $(ls $CHICKEN_EGG_CACHE)
    '' + preBuild;

    buildPhase = ''
      runHook preBuild

      chicken-install

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      mv $CHICKEN_INSTALL_PREFIX $out

      if [ -d $out/lib ]; then
        find $out/lib -type f -not -name \*.so -delete
      fi

      if [ -d $out/bin ]; then
        for bin in $out/bin/*; do
          wrapProgram $bin \
            --prefix CHICKEN_INCLUDE_PATH : $out/share \
            --prefix CHICKEN_REPOSITORY_PATH : $out/${repositoryPath} \
            --prefix LD_LIBRARY_PATH : ${chicken}/lib
        done
      fi

      runHook postInstall
    '';
  } // removeAttrs args [ "preUnpack" "preBuild" ];
}