2024-02-07 01:22:34 +00:00
|
|
|
{ stdenv, lib, idris2, makeWrapper
|
2024-01-25 14:12:00 +00:00
|
|
|
}:
|
|
|
|
# Usage: let
|
|
|
|
# pkg = idris2Packages.buildIdris {
|
|
|
|
# src = ...;
|
2024-02-07 01:22:34 +00:00
|
|
|
# ipkgName = "my-pkg";
|
2024-01-25 14:12:00 +00:00
|
|
|
# idrisLibraries = [ ];
|
|
|
|
# };
|
|
|
|
# in {
|
|
|
|
# lib = pkg.library { withSource = true; };
|
|
|
|
# bin = pkg.executable;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
{ src
|
2024-02-07 01:22:34 +00:00
|
|
|
, ipkgName
|
|
|
|
, version ? "unversioned"
|
2024-01-25 14:12:00 +00:00
|
|
|
, idrisLibraries # Other libraries built with buildIdris
|
|
|
|
, ... }@attrs:
|
|
|
|
|
|
|
|
let
|
2024-04-21 15:54:59 +00:00
|
|
|
propagate = libs: lib.unique (lib.concatMap (nextLib: [nextLib] ++ nextLib.propagatedIdrisLibraries) libs);
|
2024-02-07 01:22:34 +00:00
|
|
|
ipkgFileName = ipkgName + ".ipkg";
|
2024-01-25 14:12:00 +00:00
|
|
|
idrName = "idris2-${idris2.version}";
|
|
|
|
libSuffix = "lib/${idrName}";
|
2024-04-21 15:54:59 +00:00
|
|
|
propagatedIdrisLibraries = propagate idrisLibraries;
|
2024-01-25 14:12:00 +00:00
|
|
|
libDirs =
|
2024-04-21 15:54:59 +00:00
|
|
|
(lib.makeSearchPath libSuffix propagatedIdrisLibraries) +
|
2024-02-07 01:22:34 +00:00
|
|
|
":${idris2}/${idrName}";
|
|
|
|
supportDir = "${idris2}/${idrName}/lib";
|
|
|
|
drvAttrs = builtins.removeAttrs attrs [
|
|
|
|
"ipkgName"
|
|
|
|
"idrisLibraries"
|
|
|
|
];
|
2024-01-25 14:12:00 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
derivation = stdenv.mkDerivation (finalAttrs:
|
|
|
|
drvAttrs // {
|
|
|
|
pname = ipkgName;
|
|
|
|
inherit version;
|
|
|
|
src = src;
|
|
|
|
nativeBuildInputs = [ idris2 makeWrapper ] ++ attrs.nativeBuildInputs or [];
|
|
|
|
buildInputs = propagatedIdrisLibraries ++ attrs.buildInputs or [];
|
2024-01-25 14:12:00 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
IDRIS2_PACKAGE_PATH = libDirs;
|
2024-01-25 14:12:00 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
idris2 --build ${ipkgFileName}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit propagatedIdrisLibraries;
|
|
|
|
};
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
export IDRIS2_PACKAGE_PATH="${finalAttrs.IDRIS2_PACKAGE_PATH}"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
2024-01-25 14:12:00 +00:00
|
|
|
|
|
|
|
in {
|
2024-04-21 15:54:59 +00:00
|
|
|
executable = derivation.overrideAttrs {
|
2024-02-07 01:22:34 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/bin
|
|
|
|
scheme_app="$(find ./build/exec -name '*_app')"
|
|
|
|
if [ "$scheme_app" = ''' ]; then
|
|
|
|
mv -- build/exec/* $out/bin/
|
|
|
|
chmod +x $out/bin/*
|
|
|
|
# ^ remove after Idris2 0.8.0 is released. will be superfluous:
|
|
|
|
# https://github.com/idris-lang/Idris2/pull/3189
|
|
|
|
else
|
|
|
|
cd build/exec/*_app
|
|
|
|
rm -f ./libidris2_support.so
|
|
|
|
for file in *.so; do
|
|
|
|
bin_name="''${file%.so}"
|
|
|
|
mv -- "$file" "$out/bin/$bin_name"
|
|
|
|
wrapProgram "$out/bin/$bin_name" \
|
|
|
|
--prefix LD_LIBRARY_PATH : ${supportDir} \
|
|
|
|
--prefix DYLD_LIBRARY_PATH : ${supportDir}
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
};
|
2024-02-07 01:22:34 +00:00
|
|
|
|
|
|
|
library = { withSource ? false }:
|
|
|
|
let installCmd = if withSource then "--install-with-src" else "--install";
|
2024-04-21 15:54:59 +00:00
|
|
|
in derivation.overrideAttrs {
|
2024-02-07 01:22:34 +00:00
|
|
|
installPhase = ''
|
2024-01-25 14:12:00 +00:00
|
|
|
runHook preInstall
|
2024-02-07 01:22:34 +00:00
|
|
|
mkdir -p $out/${libSuffix}
|
|
|
|
export IDRIS2_PREFIX=$out/lib
|
|
|
|
idris2 ${installCmd} ${ipkgFileName}
|
2024-01-25 14:12:00 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
};
|
2024-01-25 14:12:00 +00:00
|
|
|
}
|