Skip to content

Fix setup-depends dependencies #124

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 13 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ let
inherit ghc haskellLib makeConfigFiles ghcForComponent hsPkgs;
};

setup-builder = haskellLib.weakCallPackage pkgs ./setup-builder.nix {
ghc = buildGHC;
hsPkgs = hsPkgs.buildPackages;
inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
};

# 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 {
Expand All @@ -19,6 +25,12 @@ let
makeConfigFiles = haskellLib.weakCallPackage pkgs ./make-config-files.nix {
inherit ghc haskellLib nonReinstallablePkgs;
};
# When building setup depends we need to use the build systems GHC and Packages
makeSetupConfigFiles = haskellLib.weakCallPackage buildPackages ./make-config-files.nix {
inherit haskellLib nonReinstallablePkgs;
ghc = buildGHC;
};


hoogleLocal = let
nixpkgsHoogleLocal = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
Expand All @@ -45,7 +57,7 @@ in {
# 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;
inherit haskellLib ghc buildGHC comp-builder setup-builder;
};

inherit shellFor;
Expand Down
25 changes: 4 additions & 21 deletions builder/hspkg-builder.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, runCommand, pkgconfig, comp-builder }:
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, runCommand, comp-builder, setup-builder }:


{ flags
Expand Down Expand Up @@ -38,26 +38,9 @@ let

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
'';
else setup-builder {
setup-depends = package.setup-depends;
inherit package name src flags;
};

buildComp = componentId: component: comp-builder {
Expand Down
46 changes: 46 additions & 0 deletions builder/setup-builder.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }:

{ setup-depends, package, name, src, flags }:

let
fullName = "${name}-setup";

includeGhcPackage = lib.any (p: p.identifier.name == "ghc") setup-depends;

configFiles = makeSetupConfigFiles {
inherit (package) identifier;
inherit fullName flags;
component = {
depends = setup-depends;
libs = [];
frameworks = [];
doExactConfig = false;
};
};

in
stdenv.lib.fix (drv:
stdenv.mkDerivation {
name = "${fullName}";
inherit src;
nativeBuildInputs = [ghc];

CABAL_CONFIG = configFiles + /cabal.config;
phases = ["unpackPhase" "buildPhase" "installPhase"];
buildPhase = ''
for f in Setup.hs Setup.lhs; do
if [ -f $f ]; then
echo Compiling package $f
ghc $f '' + (if includeGhcPackage then "-package ghc " else "")
+ ''-package-db ${configFiles}/package.conf.d --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
'';
})
1 change: 1 addition & 0 deletions nix-tools/.plan.nix/nix-tools.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion nix-tools/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, symlinkJoin, makeWrapper
{ pkgs, lib, symlinkJoin, makeWrapper
, hpack, git, nix, nix-prefetch-git
, fetchExternal, cleanSourceHaskell, mkCabalProjectPkgSet }:

Expand All @@ -8,6 +8,14 @@ let
specJSON = ./nix-tools-src.json;
override = "nix-tools-src";
});
# we need to patch Cabal, as its data directory logic is broken for component builds, which haskell.nix
# uses excessively. See issue https://github.com/haskell/cabal/issues/5862, and the fix for Cabal 3.0
# in https://github.com/haskell/cabal/pull/6055. We apply the haskell/cabal#6055 here.
cabalPatch = pkgs.fetchpatch {
url = "https://patch-diff.githubusercontent.com/raw/haskell/cabal/pull/6055.diff";
sha256 = "145g7s3z9q8d18pxgyngvixgsm6gmwh1rgkzkhacy4krqiq0qyvx";
stripLen = 1;
};

pkgSet = mkCabalProjectPkgSet {
plan-pkgs = import ./pkgs.nix;
Expand All @@ -22,6 +30,12 @@ let
{
packages.nix-tools.src = src;
}

({ config, ...}: {
packages = {
Cabal.patches = [ cabalPatch ];
};
})
];
};

Expand Down
Loading