Refactor Idris packaging infrastructure

The main two changes are

1. Completely rewrite how with-packages works to remove use of envHooks
2. The package description is now an idris specific set rather than
    being a subset of the arguments to mkDerivation. This mirrors the
    way Haskell packages are treated.
This commit is contained in:
Matthew Pickering
2018-02-07 19:25:50 +00:00
parent 8d55538f97
commit 947e7d80b4
8 changed files with 90 additions and 103 deletions
@@ -1,46 +1,20 @@
# Build a version of idris with a set of packages visible
# packages: The packages visible to idris
{ stdenv, idris }: packages: stdenv.mkDerivation {
inherit (idris) name;
{ stdenv, idris, symlinkJoin, makeWrapper }: packages:
buildInputs = packages;
let paths = stdenv.lib.closePropagation packages;
in
symlinkJoin {
preHook = ''
mkdir -p $out/lib/${idris.name}
name = idris.name + "-with-packages";
installIdrisLib () {
if [ -d $1/lib/${idris.name} ]; then
ln -fsv $1/lib/${idris.name}/* $out/lib/${idris.name}
fi
}
paths = paths ++ [idris] ;
envHostTargetHooks+=(installIdrisLib)
'';
buildInputs = [ makeWrapper ];
unpackPhase = ''
cat >idris.c <<EOF
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
postBuild = ''
wrapProgram $out/bin/idris \
--set IDRIS_LIBRARY_PATH $out/libs
'';
int main (int argc, char ** argv) {
/* idris currently only supports a single library path, so respect it if the user set it */
setenv("IDRIS_LIBRARY_PATH", "$out/lib/${idris.name}", 0);
execv("${idris}/bin/idris", argv);
perror("executing ${idris}/bin/idris");
return 127;
}
EOF
'';
buildPhase = ''
$CC -O3 -o idris idris.c
'';
installPhase = ''
mkdir -p $out/bin
mv idris $out/bin
'';
stripAllList = [ "bin" ];
}