-
Notifications
You must be signed in to change notification settings - Fork 247
Add shellFor multi-package development environments #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4ecc0aa
Add config.hsPkgs.shellFor function
rvl 49eb327
shellFor: provide CABAL_CONFIG in shell
rvl bbd0133
shellFor: Provide correct dependencies
rvl b060ea5
tests: Add tests for the shellFor function
rvl dd1baeb
tests: Add a cabal new-build project
rvl e6b07b4
tests: Generated nix for cabal new-build project
rvl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,35 @@ | ||
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, writeText, runCommand, pkgconfig, nonReinstallablePkgs, ghcForComponent, hsPkgs }: | ||
|
||
{ flags | ||
, package | ||
, components | ||
, cabal-generator | ||
|
||
, name | ||
, sha256 | ||
, src | ||
, revision | ||
, revisionSha256 | ||
, patches | ||
|
||
, preUnpack | ||
, postUnpack | ||
, preConfigure | ||
, postConfigure | ||
, preBuild | ||
, postBuild | ||
, preCheck | ||
, postCheck | ||
, preInstall | ||
, postInstall | ||
, preHaddock | ||
, postHaddock | ||
|
||
, shellHook | ||
|
||
, ... | ||
}@config: | ||
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, pkgconfig, nonReinstallablePkgs, hsPkgs }: | ||
|
||
let | ||
cabalFile = if revision == null || revision == 0 then null else | ||
fetchurl { | ||
name = "${name}-${toString revision}.cabal"; | ||
url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal"; | ||
sha256 = revisionSha256; | ||
}; | ||
|
||
defaultSetupSrc = builtins.toFile "Setup.hs" '' | ||
import Distribution.Simple | ||
main = defaultMain | ||
''; | ||
defaultSetup = buildPackages.runCommand "default-Setup" { nativeBuildInputs = [buildGHC]; } '' | ||
cat ${defaultSetupSrc} > Setup.hs | ||
mkdir -p $out/bin | ||
${buildGHC.targetPrefix}ghc Setup.hs --make -o $out/bin/Setup | ||
''; | ||
|
||
setup = if package.buildType == "Simple" | ||
then defaultSetup | ||
else stdenv.mkDerivation { | ||
name = "${name}-setup"; | ||
nativeBuildInputs = [buildGHC]; | ||
inherit src; | ||
phases = ["unpackPhase" "buildPhase" "installPhase"]; | ||
buildPhase = '' | ||
for f in Setup.hs Setup.lhs; do | ||
if [ -f $f ]; then | ||
echo Compiling package $f | ||
ghc $f --make -o ./Setup | ||
setup=$(pwd)/Setup | ||
fi | ||
done | ||
[ -f ./Setup ] || (echo Failed to build Setup && exit 1) | ||
''; | ||
|
||
installPhase = '' | ||
mkdir -p $out/bin | ||
install ./Setup $out/bin/Setup | ||
''; | ||
}; | ||
# Builds a single component of a package. | ||
comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix { | ||
inherit ghc haskellLib makeConfigFiles ghcForComponent hsPkgs; | ||
}; | ||
|
||
comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix { inherit ghc haskellLib nonReinstallablePkgs ghcForComponent hsPkgs; }; | ||
# Wraps GHC to provide dependencies in a way that works for both the | ||
# component builder and for nix-shells. | ||
ghcForComponent = import ./ghc-for-component-wrapper.nix { | ||
inherit lib ghc; | ||
inherit (buildPackages) stdenv runCommand makeWrapper; | ||
inherit (buildPackages.xorg) lndir; | ||
}; | ||
|
||
buildComp = componentId: component: comp-builder { | ||
inherit componentId component package name src flags setup cabalFile cabal-generator patches revision | ||
preUnpack postUnpack preConfigure postConfigure | ||
preBuild postBuild preCheck postCheck | ||
preInstall postInstall preHaddock postHaddock | ||
shellHook | ||
; | ||
# Builds a derivation which contains a ghc package-db of | ||
# dependencies for a component. | ||
makeConfigFiles = haskellLib.weakCallPackage pkgs ./make-config-files.nix { | ||
inherit ghc haskellLib nonReinstallablePkgs; | ||
}; | ||
|
||
in { | ||
components = haskellLib.applyComponents buildComp config; | ||
inherit (package) identifier; | ||
inherit setup cabalFile; | ||
isHaskell = true; | ||
# Build a Haskell package from its config. | ||
# TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted | ||
build-package = haskellLib.weakCallPackage pkgs ./hspkg-builder.nix { | ||
inherit haskellLib ghc buildGHC comp-builder; | ||
}; | ||
|
||
# Same as haskellPackages.shellFor in nixpkgs. | ||
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix { | ||
inherit hsPkgs ghcForComponent makeConfigFiles; | ||
inherit (buildPackages) glibcLocales; | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, runCommand, pkgconfig, comp-builder }: | ||
|
||
|
||
{ flags | ||
, package | ||
, components | ||
, cabal-generator | ||
|
||
, name | ||
, sha256 | ||
, src | ||
, revision | ||
, revisionSha256 | ||
, patches | ||
|
||
, preUnpack | ||
, postUnpack | ||
, preConfigure | ||
, postConfigure | ||
, preBuild | ||
, postBuild | ||
, preCheck | ||
, postCheck | ||
, preInstall | ||
, postInstall | ||
, preHaddock | ||
, postHaddock | ||
|
||
, shellHook | ||
|
||
, ... | ||
}@config: | ||
|
||
let | ||
cabalFile = if revision == null || revision == 0 then null else | ||
fetchurl { | ||
name = "${name}-${toString revision}.cabal"; | ||
url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal"; | ||
sha256 = revisionSha256; | ||
}; | ||
|
||
defaultSetupSrc = builtins.toFile "Setup.hs" '' | ||
import Distribution.Simple | ||
main = defaultMain | ||
''; | ||
defaultSetup = buildPackages.runCommand "default-Setup" { nativeBuildInputs = [buildGHC]; } '' | ||
cat ${defaultSetupSrc} > Setup.hs | ||
mkdir -p $out/bin | ||
${buildGHC.targetPrefix}ghc Setup.hs --make -o $out/bin/Setup | ||
''; | ||
|
||
setup = if package.buildType == "Simple" | ||
then defaultSetup | ||
else stdenv.mkDerivation { | ||
name = "${name}-setup"; | ||
nativeBuildInputs = [buildGHC]; | ||
inherit src; | ||
phases = ["unpackPhase" "buildPhase" "installPhase"]; | ||
buildPhase = '' | ||
for f in Setup.hs Setup.lhs; do | ||
if [ -f $f ]; then | ||
echo Compiling package $f | ||
ghc $f --make -o ./Setup | ||
setup=$(pwd)/Setup | ||
fi | ||
done | ||
[ -f ./Setup ] || (echo Failed to build Setup && exit 1) | ||
''; | ||
|
||
installPhase = '' | ||
mkdir -p $out/bin | ||
install ./Setup $out/bin/Setup | ||
''; | ||
}; | ||
|
||
buildComp = componentId: component: comp-builder { | ||
inherit componentId component package name src flags setup cabalFile cabal-generator patches revision | ||
preUnpack postUnpack preConfigure postConfigure | ||
preBuild postBuild preCheck postCheck | ||
preInstall postInstall preHaddock postHaddock | ||
shellHook | ||
; | ||
}; | ||
|
||
in { | ||
components = haskellLib.applyComponents buildComp config; | ||
inherit (package) identifier; | ||
inherit setup cabalFile; | ||
isHaskell = true; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting shellHook from the comp-builder.nix input will break my (already merged) changes for configurable shellHooks per-package: #117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has been moved not deleted. You should find shellHook in
hspkg-builder.nix
.