haskell infra: Misc cleanups

- The haskell lib is very close to not relying on Nixpkgs. I think
this is good---simpler to think about and matches Nixpkgs's lib.

- The haskell lib is only imported once

- stdenv is exposed more shallowly so it can be overriden more easily.
I'll eventually use this on Darwin to avoid the Sierra shared
library problems (unless changes are to be made system-wide).

Closes https://github.com/NixOS/nixpkgs/pull/27840.

+2 -2
pkgs/development/haskell-modules/configuration-common.nix
···
#
# See comment at the top of configuration-nix.nix for more information about this
# distinction.
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
#
# See comment at the top of configuration-nix.nix for more information about this
# distinction.
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-6.12.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.0.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.10.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.2.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.4.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.6.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-7.8.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-8.0.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-8.2.x.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghc-head.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-ghcjs.nix
···
#
# Please insert new packages *alphabetically*
# in the OTHER PACKAGES section.
-
{ pkgs }:
let
removeLibraryHaskellDepends = pnames: depends:
builtins.filter (e: !(builtins.elem (e.pname or "") pnames)) depends;
in
-
with import ./lib.nix { inherit pkgs; };
self: super:
···
#
# Please insert new packages *alphabetically*
# in the OTHER PACKAGES section.
+
{ pkgs, haskellLib }:
let
removeLibraryHaskellDepends = pnames: depends:
builtins.filter (e: !(builtins.elem (e.pname or "") pnames)) depends;
in
+
with haskellLib;
self: super:
+2 -2
pkgs/development/haskell-modules/configuration-halvm-2.4.0.nix
···
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
self: super: {
···
+
{ pkgs, haskellLib }:
+
with haskellLib;
self: super: {
+2 -2
pkgs/development/haskell-modules/configuration-nix.nix
···
# * enabling/disabling certain features in packages
#
# If you have an override of this kind, see configuration-common.nix instead.
-
{ pkgs }:
-
with import ./lib.nix { inherit pkgs; };
# All of the overrides in this set should look like:
#
···
# * enabling/disabling certain features in packages
#
# If you have an override of this kind, see configuration-common.nix instead.
+
{ pkgs, haskellLib }:
+
with haskellLib;
# All of the overrides in this set should look like:
#
+7 -7
pkgs/development/haskell-modules/default.nix
···
-
{ pkgs, stdenv, ghc, all-cabal-hashes
, compilerConfig ? (self: super: {})
, packageSetConfig ? (self: super: {})
, overrides ? (self: super: {})
···
let
-
inherit (stdenv.lib) extends makeExtensible;
-
inherit (import ./lib.nix { inherit pkgs; }) overrideCabal makePackageSet;
-
haskellPackages = makePackageSet {
package-set = initialPackages;
-
inherit ghc extensible-self;
};
-
commonConfiguration = configurationCommon { inherit pkgs; };
-
nixConfiguration = configurationNix { inherit pkgs; };
extensible-self = makeExtensible
(extends overrides
···
+
{ pkgs, stdenv, lib, haskellLib, ghc, all-cabal-hashes
, compilerConfig ? (self: super: {})
, packageSetConfig ? (self: super: {})
, overrides ? (self: super: {})
···
let
+
inherit (lib) extends makeExtensible;
+
inherit (haskellLib) overrideCabal makePackageSet;
+
haskellPackages = pkgs.callPackage makePackageSet {
package-set = initialPackages;
+
inherit stdenv haskellLib ghc extensible-self;
};
+
commonConfiguration = configurationCommon { inherit pkgs haskellLib; };
+
nixConfiguration = configurationNix { inherit pkgs haskellLib; };
extensible-self = makeExtensible
(extends overrides
+9 -8
pkgs/development/haskell-modules/lib.nix
···
-
{ pkgs }:
rec {
-
makePackageSet = pkgs.callPackage ./make-package-set.nix {};
overrideCabal = drv: f: (drv.override (args: args // {
mkDerivation = drv: (args.mkDerivation drv).override f;
···
dontDistribute = drv: overrideCabal drv (drv: { hydraPlatforms = []; });
appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; });
-
removeConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = pkgs.stdenv.lib.remove x (drv.configureFlags or []); });
addBuildTool = drv: x: addBuildTools drv [x];
addBuildTools = drv: xs: overrideCabal drv (drv: { buildTools = (drv.buildTools or []) ++ xs; });
···
disableHardening = drv: flags: overrideCabal drv (drv: { hardeningDisable = flags; });
-
sdistTarball = pkg: pkgs.lib.overrideDerivation pkg (drv: {
name = "${drv.pname}-source-${drv.version}";
buildPhase = "./Setup sdist";
haddockPhase = ":";
···
isLibrary = false;
doHaddock = false;
postFixup = "rm -rf $out/lib $out/nix-support $out/share/doc";
-
} // (if pkgs.stdenv.isDarwin then {
configureFlags = (drv.configureFlags or []) ++ ["--ghc-option=-optl=-dead_strip"];
-
} else {})
-
);
-
buildFromSdist = pkg: pkgs.lib.overrideDerivation pkg (drv: {
unpackPhase = let src = sdistTarball pkg; tarname = "${pkg.pname}-${pkg.version}"; in ''
echo "Source tarball is at ${src}/${tarname}.tar.gz"
tar xf ${src}/${tarname}.tar.gz
···
+
# TODO(@Ericson2314): Remove `pkgs` param, which is only used for
+
# `buildStackProject` and `justStaticExecutables`
+
{ pkgs, lib }:
rec {
+
makePackageSet = import ./make-package-set.nix;
overrideCabal = drv: f: (drv.override (args: args // {
mkDerivation = drv: (args.mkDerivation drv).override f;
···
dontDistribute = drv: overrideCabal drv (drv: { hydraPlatforms = []; });
appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; });
+
removeConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = lib.remove x (drv.configureFlags or []); });
addBuildTool = drv: x: addBuildTools drv [x];
addBuildTools = drv: xs: overrideCabal drv (drv: { buildTools = (drv.buildTools or []) ++ xs; });
···
disableHardening = drv: flags: overrideCabal drv (drv: { hardeningDisable = flags; });
+
sdistTarball = pkg: lib.overrideDerivation pkg (drv: {
name = "${drv.pname}-source-${drv.version}";
buildPhase = "./Setup sdist";
haddockPhase = ":";
···
isLibrary = false;
doHaddock = false;
postFixup = "rm -rf $out/lib $out/nix-support $out/share/doc";
+
} // lib.optionalAttrs (pkgs.hostPlatform.isDarwin) {
configureFlags = (drv.configureFlags or []) ++ ["--ghc-option=-optl=-dead_strip"];
+
});
+
buildFromSdist = pkg: lib.overrideDerivation pkg (drv: {
unpackPhase = let src = sdistTarball pkg; tarname = "${pkg.pname}-${pkg.version}"; in ''
echo "Source tarball is at ${src}/${tarname}.tar.gz"
tar xf ${src}/${tarname}.tar.gz
+22 -8
pkgs/development/haskell-modules/make-package-set.nix
···
# This expression takes a file like `hackage-packages.nix` and constructs
# a full package set out of that.
-
# required dependencies:
-
{ pkgs, stdenv, all-cabal-hashes }:
-
# arguments:
-
# * ghc package to use
-
# * package-set: a function that takes { pkgs, stdenv, callPackage } as first arg and `self` as second
-
# * extensible-self: the final, fully overriden package set usable with the nixpkgs fixpoint overriding functionality
-
{ ghc, package-set, extensible-self }:
# return value: a function from self to the package set
self: let
inherit (stdenv.lib) fix' extends makeOverridable;
-
inherit (import ./lib.nix { inherit pkgs; }) overrideCabal;
mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
inherit stdenv;
···
# This expression takes a file like `hackage-packages.nix` and constructs
# a full package set out of that.
+
{ # package-set used for non-haskell dependencies (all of nixpkgs)
+
pkgs
+
, # stdenv to use for building haskell packages
+
stdenv
+
+
, haskellLib
+
+
, # hashes for downloading Hackage packages
+
all-cabal-hashes
+
+
, # compiler to use
+
ghc
+
+
, # A function that takes `{ pkgs, stdenv, callPackage }` as the first arg and `self`
+
# as second, and returns a set of haskell packages
+
package-set
+
+
, # The final, fully overriden package set usable with the nixpkgs fixpoint
+
# overriding functionality
+
extensible-self
+
}:
# return value: a function from self to the package set
self: let
inherit (stdenv.lib) fix' extends makeOverridable;
+
inherit (haskellLib) overrideCabal;
mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
inherit stdenv;
+2 -2
pkgs/development/tools/haskell/lambdabot/default.nix
···
-
{ lib, haskell-lib, fetchpatch, makeWrapper, haskellPackages
, mueval
, withDjinn ? true
, aspell ? null
···
modulesStr = lib.replaceChars ["\n"] [" "] modules;
configStr = lib.replaceChars ["\n"] [" "] configuration;
-
in haskell-lib.overrideCabal haskellPackages.lambdabot (self: {
patches = (self.patches or []) ++ [ ./custom-config.patch ];
postPatch = (self.postPatch or "") + ''
substituteInPlace src/Main.hs \
···
+
{ lib, haskellLib, fetchpatch, makeWrapper, haskellPackages
, mueval
, withDjinn ? true
, aspell ? null
···
modulesStr = lib.replaceChars ["\n"] [" "] modules;
configStr = lib.replaceChars ["\n"] [" "] configuration;
+
in haskellLib.overrideCabal haskellPackages.lambdabot (self: {
patches = (self.patches or []) ++ [ ./custom-config.patch ];
postPatch = (self.postPatch or "") + ''
substituteInPlace src/Main.hs \
+1 -1
pkgs/top-level/all-packages.nix
···
readosm = callPackage ../development/libraries/readosm { };
lambdabot = callPackage ../development/tools/haskell/lambdabot {
-
haskell-lib = haskell.lib;
};
lambda-mod-zsh-theme = callPackage ../shells/lambda-mod-zsh-theme/default.nix { };
···
readosm = callPackage ../development/libraries/readosm { };
lambdabot = callPackage ../development/tools/haskell/lambdabot {
+
haskellLib = haskell.lib;
};
lambda-mod-zsh-theme = callPackage ../shells/lambda-mod-zsh-theme/default.nix { };
+27 -19
pkgs/top-level/haskell-packages.nix
···
-
{ pkgs, callPackage, stdenv, buildPlatform, targetPlatform }:
-
let # These are attributes in compiler and packages that don't support integer-simple.
-
integerSimpleExcludes = [
-
"ghc6102Binary"
-
"ghc704Binary"
-
"ghc742Binary"
-
"ghc6104"
-
"ghc6123"
-
"ghc704"
-
"ghc763"
-
"ghcjs"
-
"ghcjsHEAD"
-
"ghcCross"
-
"jhc"
-
"uhc"
-
"integer-simple"
-
];
-
in rec {
-
lib = import ../development/haskell-modules/lib.nix { inherit pkgs; };
compiler = {
···
+
{ pkgs, lib, newScope, stdenv, buildPlatform, targetPlatform }:
+
let
+
# These are attributes in compiler and packages that don't support integer-simple.
+
integerSimpleExcludes = [
+
"ghc6102Binary"
+
"ghc704Binary"
+
"ghc742Binary"
+
"ghc6104"
+
"ghc6123"
+
"ghc704"
+
"ghc763"
+
"ghcjs"
+
"ghcjsHEAD"
+
"ghcCross"
+
"jhc"
+
"uhc"
+
"integer-simple"
+
];
+
+
haskellLib = import ../development/haskell-modules/lib.nix {
+
inherit (pkgs) lib;
+
inherit pkgs;
+
};
+
callPackage = newScope { inherit haskellLib; };
+
+
in rec {
+
lib = haskellLib;
compiler = {