{ pkgs ? import {} }: 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 -T $CHICKEN_EGG_CACHE $out rm -f $out/*/STATUS rm -f $out/*/TIMESTAMP ''; eggProgram = { buildInputs ? [], eggCache ? null, preUnpack ? "", preBuild ? "", ... } @ args: stdenv.mkDerivation ({ buildInputs = [ chicken makeWrapper ] ++ buildInputs; # These are expanded below to make all paths absolute. CHICKEN_EGG_CACHE = "eggs"; CHICKEN_INSTALL_PREFIX = "out"; CHICKEN_INSTALL_REPOSITORY = "out/${repositoryPath}"; CHICKEN_REPOSITORY_PATH = "out/${repositoryPath}"; preUnpack = lib.optionalString (eggCache != null) '' CHICKEN_EGG_CACHE=$(realpath -m $CHICKEN_EGG_CACHE) CHICKEN_INSTALL_PREFIX=$(realpath -m $CHICKEN_INSTALL_PREFIX) CHICKEN_INSTALL_REPOSITORY=$(realpath -m $CHICKEN_INSTALL_REPOSITORY) CHICKEN_REPOSITORY_PATH=$(realpath -m $CHICKEN_REPOSITORY_PATH) 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 -T $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 [ "buildInputs" "eggCache" "preUnpack" "preBuild" ]); }