Merge pull request #164305 from hercules-ci/haskellPackages-shellFor-extraDependencies

haskellPackages.shellFor: Add extraDependencies
This commit is contained in:
Robert Hensing 2022-03-20 19:18:44 +01:00 committed by GitHub
commit 9bc841fec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -384,6 +384,18 @@ in package-set { inherit pkgs lib callPackage; } self // {
# for the "shellFor" environment (ensuring that any test/benchmark
# dependencies for "foo" will be available within the nix-shell).
, genericBuilderArgsModifier ? (args: args)
# Extra dependencies, in the form of cabal2nix build attributes.
#
# An example use case is when you have Haskell scripts that use
# libraries that don't occur in your packages' dependencies.
#
# Example:
#
# extraDependencies = p: {
# libraryHaskellDepends = [ p.releaser ];
# };
, extraDependencies ? p: {}
, ...
} @ args:
let
@ -474,7 +486,7 @@ in package-set { inherit pkgs lib callPackage; } self // {
# See the Note in `zipperCombinedPkgs` for what gets filtered out from
# each of these dependency lists.
packageInputs =
pkgs.lib.zipAttrsWith (_name: zipperCombinedPkgs) cabalDepsForSelected;
pkgs.lib.zipAttrsWith (_name: zipperCombinedPkgs) (cabalDepsForSelected ++ [ (extraDependencies self) ]);
# A attribute set to pass to `haskellPackages.mkDerivation`.
#
@ -514,7 +526,7 @@ in package-set { inherit pkgs lib callPackage; } self // {
# pkgWithCombinedDepsDevDrv :: Derivation
pkgWithCombinedDepsDevDrv = pkgWithCombinedDeps.envFunc { inherit withHoogle; };
mkDerivationArgs = builtins.removeAttrs args [ "genericBuilderArgsModifier" "packages" "withHoogle" "doBenchmark" ];
mkDerivationArgs = builtins.removeAttrs args [ "genericBuilderArgsModifier" "packages" "withHoogle" "doBenchmark" "extraDependencies" ];
in pkgWithCombinedDepsDevDrv.overrideAttrs (old: mkDerivationArgs // {
nativeBuildInputs = old.nativeBuildInputs ++ mkDerivationArgs.nativeBuildInputs or [];

View file

@ -2,6 +2,7 @@
(haskellPackages.shellFor {
packages = p: [ p.constraints p.linear ];
extraDependencies = p: { libraryHaskellDepends = [ p.releaser ]; };
nativeBuildInputs = [ cabal-install ];
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
unpackPhase = ''
@ -16,6 +17,16 @@
export HOME=$(mktemp -d)
mkdir -p $HOME/.cabal
touch $HOME/.cabal/config
# Check extraDependencies.libraryHaskellDepends arg
ghci <<EOF
:m + Releaser.Primitives
:m + System.IO
writeFile "done" "done"
EOF
[[ done == $(cat done) ]]
# Check packages arg
cabal v2-build --offline --verbose constraints linear --ghc-options="-O0 -j$NIX_BUILD_CORES"
'';
installPhase = ''