···
+
# lib1 = pkg.library { withSource = true; };
+
# # implicitly without source:
+
ipkgName, # ipkg filename without the extension
idrisLibraries, # Other libraries built with buildIdris
···
ipkgFileName = ipkgName + ".ipkg";
idrName = "idris2-${idris2.version}";
libSuffix = "lib/${idrName}";
+
libDirs = libs: (lib.makeSearchPath libSuffix libs) + ":${idris2}/${idrName}";
supportDir = "${idris2}/${idrName}/lib";
drvAttrs = builtins.removeAttrs attrs [
+
applyWithSource = lib: if withSource then lib.withSource else lib;
+
propagatedIdrisLibraries = map applyWithSource (propagate idrisLibraryLibs);
+
] ++ attrs.nativeBuildInputs or [ ];
+
buildInputs = propagatedIdrisLibraries ++ attrs.buildInputs or [ ];
+
env.IDRIS2_PACKAGE_PATH = libDirs propagatedIdrisLibraries;
+
idris2 --build ${ipkgFileName}
+
inherit propagatedIdrisLibraries;
+
} // (attrs.passthru or { });
+
export IDRIS2_PACKAGE_PATH="${finalAttrs.env.IDRIS2_PACKAGE_PATH}"
+
derivation = mkDerivation withSource;
+
derivation.overrideAttrs {
+
scheme_app="$(find ./build/exec -name '*_app')"
+
if [ "$scheme_app" = ''' ]; then
+
mv -- build/exec/* $out/bin/
+
# ^ remove after Idris2 0.8.0 is released. will be superfluous:
+
# https://github.com/idris-lang/Idris2/pull/3189
+
rm -f ./libidris2_support.{so,dylib}
+
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}
+
# allow an executable's dependencies to be built with source. this is convenient when
+
# building a development shell for the exectuable using `mkShell`'s `inputsFrom`.
+
passthru = derivation.passthru // {
+
withSource = mkExecutable true;
installCmd = if withSource then "--install-with-src" else "--install";
+
derivation = mkDerivation withSource;
derivation.overrideAttrs {
···
idris2 ${installCmd} ${ipkgFileName}
+
# allow a library built without source to be changed to one with source
+
# via a passthru attribute; i.e. `my-pkg.library'.withSource`.
+
# this is convenient because a library derivation can be distributed as
+
# without-source by default but downstream projects can still build it
+
# with-source. We surface this regardless of whether the original library
+
# was built with source because that allows downstream to call this
+
# property unconditionally.
+
passthru = derivation.passthru // {
+
withSource = mkLibrary true;
+
executable = mkExecutable false;
+
# Make a library without source; you can still use the `withSource` attribute
+
# on the resulting derivation to build the library with source at a later time.
+
library' = mkLibrary false;