~evhan/beaker

ref: 6bfb584b378e2a07ff11a8ad9b377ad581d8eb0f beaker/default.nix -rw-r--r-- 1.8 KiB
6bfb584bEvan Hanson Add "eggCache" and "eggProgram" Nix helpers 1 year, 10 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
{ pkgs ? import <nixpkgs> {} }:

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

  eggCache = {
    name ? "eggs",
    hash,
    overrideFile,
  }: with pkgs; runCommand name {
    buildInputs = [ chicken ];
    outputHash = hash;
    outputHashMode = "recursive";
    CHICKEN_EGG_CACHE = "eggs";
  } ''
    chicken-install -retrieve -recursive -from-list ${overrideFile}
    mv $CHICKEN_EGG_CACHE $out
    rm $out/*/STATUS
    rm $out/*/TIMESTAMP
  '';

  eggProgram = {
    name, src,
    buildInputs ? [],
    eggCache ? null,
    preUnpack ? "",
    preBuild ? "",
    ...
  } @ args: with pkgs; 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
      find $out/lib -type f -not -name \*.so -delete
      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
      runHook postInstall
    '';
  } // removeAttrs args [ "preUnpack" "preBuild" ];
}