on fa2fa13 help sign in
haskell.nix/builder/default.nix
92 lines 3.7 kB history raw
1{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, pkgconfig, nonReinstallablePkgs, hsPkgs, compiler }:
3let
4 # Builds a single component of a package.
5 comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix {
6 inherit ghc haskellLib makeConfigFiles haddockBuilder ghcForComponent hsPkgs compiler;
7 };
9 haddockBuilder = haskellLib.weakCallPackage pkgs ./haddock-builder.nix {
10 inherit ghc ghcForComponent haskellLib makeConfigFiles nonReinstallablePkgs;
11 };
13 setup-builder = haskellLib.weakCallPackage pkgs ./setup-builder.nix {
14 ghc = (ghc.passthru.buildGHC or ghc);
15 hsPkgs = hsPkgs.buildPackages;
16 # We need to use the buildPackages stdenv to build the setup-builder.
17 # in the native case, it would be the same in the cross case however
18 # we *really* want to build the Setup.hs on the build machine and not
19 # have the stdenv confuse it with the target/host env.
20 inherit (buildPackages) stdenv pkgconfig;
21 inherit buildPackages;
22 inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
23 };
25 # Wraps GHC to provide dependencies in a way that works for both the
26 # component builder and for nix-shells.
27 ghcForComponent = import ./ghc-for-component-wrapper.nix {
28 inherit lib ghc haskellLib;
29 inherit (buildPackages) stdenv;
30 inherit (buildPackages.buildPackages) runCommand makeWrapper;
31 inherit (buildPackages.buildPackages.xorg) lndir;
32 };
34 # Builds a derivation which contains a ghc package-db of
35 # dependencies for a component.
36 makeConfigFiles = haskellLib.weakCallPackage pkgs ./make-config-files.nix {
37 inherit ghc haskellLib nonReinstallablePkgs;
38 };
39 # When building setup depends we need to use the build systems GHC and Packages
40 makeSetupConfigFiles = haskellLib.weakCallPackage buildPackages ./make-config-files.nix {
41 inherit haskellLib nonReinstallablePkgs;
42 ghc = (ghc.passthru.buildGHC or ghc);
43 };
46 hoogleLocal = let
47 nixpkgsHoogle = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
48 in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.tool "ghc8107" "hoogle" {
49 version = "5.0.18.3";
50 index-state = pkgs.haskell-nix.internalHackageIndexState;
51 }
52 }:
53 let
54 haskellPackages = {
55 # For musl we can use haddock from the buildGHC
56 ghc = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
57 then ghc.buildGHC
58 else ghc;
59 inherit packages hoogle;
60 };
61 in if lib.versionAtLeast lib.trivial.release "22.05"
62 then haskellLib.weakCallPackage pkgs nixpkgsHoogle {
63 inherit haskellPackages;
64 } (p: p.packages)
65 else haskellLib.weakCallPackage pkgs nixpkgsHoogle haskellPackages;
67 # Same as haskellPackages.shellFor in nixpkgs.
68 shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
69 inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib buildPackages compiler;
70 inherit (buildPackages) glibcLocales;
71 };
73 # Same as haskellPackages.ghcWithPackages and ghcWithHoogle in nixpkgs.
74 withPackages = {withHoogle}: packages: (shellFor {
75 name = ghc.name + "-with-packages";
76 packages = _: [];
77 additional = packages;
78 inherit withHoogle;
79 }).ghc;
81in {
82 # Build a Haskell package from its config.
83 # TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted
84 build-package = haskellLib.weakCallPackage pkgs ./hspkg-builder.nix {
85 inherit haskellLib ghc compiler-nix-name comp-builder setup-builder;
86 };
88 inherit shellFor makeConfigFiles;
90 ghcWithPackages = withPackages { withHoogle = false; };
91 ghcWithHoogle = withPackages { withHoogle = true; };