better nix-shell support via shellHook (#3243)

This commit is contained in:
Mathew Polzin 2024-04-01 10:00:10 -05:00 committed by GitHub
parent 2c2aa85048
commit 1977dbd640
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,7 +13,7 @@
{ src { src
, ipkgName , ipkgName
, version ? "unversioned" , version ? "unversioned"
, idrisLibraries , idrisLibraries # Other libraries built with buildIdris
, ... }@attrs: , ... }@attrs:
let let
@ -29,7 +29,8 @@ let
"idrisLibraries" "idrisLibraries"
]; ];
sharedAttrs = drvAttrs // { derivation = stdenv.mkDerivation (finalAttrs:
drvAttrs // {
pname = ipkgName; pname = ipkgName;
inherit version; inherit version;
src = src; src = src;
@ -47,11 +48,16 @@ let
passthru = { passthru = {
inherit propagatedIdrisLibraries; inherit propagatedIdrisLibraries;
}; };
};
shellHook = ''
export IDRIS2_PACKAGE_PATH="${finalAttrs.IDRIS2_PACKAGE_PATH}"
'';
}
);
in rec { in rec {
executable = stdenv.mkDerivation (sharedAttrs // executable = derivation.overrideAttrs {
{ installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir -p $out/bin mkdir -p $out/bin
scheme_app="$(find ./build/exec -name '*_app')" scheme_app="$(find ./build/exec -name '*_app')"
@ -73,21 +79,19 @@ in rec {
fi fi
runHook postInstall runHook postInstall
''; '';
} };
);
library = { withSource ? false }: library = { withSource ? false }:
let installCmd = if withSource then "--install-with-src" else "--install"; let installCmd = if withSource then "--install-with-src" else "--install";
in stdenv.mkDerivation (sharedAttrs // in derivation.overrideAttrs {
{ installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir -p $out/${libSuffix} mkdir -p $out/${libSuffix}
export IDRIS2_PREFIX=$out/lib export IDRIS2_PREFIX=$out/lib
idris2 ${installCmd} ${ipkgFileName} idris2 ${installCmd} ${ipkgFileName}
runHook postInstall runHook postInstall
''; '';
} };
);
# deprecated aliases: # deprecated aliases:
build = lib.warn "build is a deprecated alias for 'executable'." executable; build = lib.warn "build is a deprecated alias for 'executable'." executable;
installLibrary = lib.warn "installLibrary is a deprecated alias for 'library { }'." (library { }); installLibrary = lib.warn "installLibrary is a deprecated alias for 'library { }'." (library { });