2017-08-01 19:44:08 +03:00
|
|
|
# TODO(@Ericson2314): Remove `pkgs` param, which is only used for
|
2017-08-30 15:40:54 +03:00
|
|
|
# `buildStackProject`, `justStaticExecutables` and `checkUnusedPackages`
|
2017-08-01 19:44:08 +03:00
|
|
|
{ pkgs, lib }:
|
2015-01-10 22:26:08 +03:00
|
|
|
|
|
|
|
rec {
|
2017-08-01 19:44:08 +03:00
|
|
|
makePackageSet = import ./make-package-set.nix;
|
2015-01-07 22:31:32 +03:00
|
|
|
|
2015-01-12 20:20:42 +03:00
|
|
|
overrideCabal = drv: f: (drv.override (args: args // {
|
2017-02-10 08:04:17 +03:00
|
|
|
mkDerivation = drv: (args.mkDerivation drv).override f;
|
2015-01-12 20:20:42 +03:00
|
|
|
})) // {
|
2015-01-12 20:18:46 +03:00
|
|
|
overrideScope = scope: overrideCabal (drv.overrideScope scope) f;
|
2015-01-12 20:20:42 +03:00
|
|
|
};
|
2015-01-07 22:31:32 +03:00
|
|
|
|
2017-02-14 18:17:40 +03:00
|
|
|
doCoverage = drv: overrideCabal drv (drv: { doCoverage = true; });
|
|
|
|
dontCoverage = drv: overrideCabal drv (drv: { doCoverage = false; });
|
|
|
|
|
2015-01-18 13:04:38 +03:00
|
|
|
doHaddock = drv: overrideCabal drv (drv: { doHaddock = true; });
|
|
|
|
dontHaddock = drv: overrideCabal drv (drv: { doHaddock = false; });
|
2015-01-10 22:26:08 +03:00
|
|
|
|
|
|
|
doJailbreak = drv: overrideCabal drv (drv: { jailbreak = true; });
|
|
|
|
dontJailbreak = drv: overrideCabal drv (drv: { jailbreak = false; });
|
|
|
|
|
2015-01-12 03:28:15 +03:00
|
|
|
doCheck = drv: overrideCabal drv (drv: { doCheck = true; });
|
2015-01-10 22:26:08 +03:00
|
|
|
dontCheck = drv: overrideCabal drv (drv: { doCheck = false; });
|
|
|
|
|
2017-09-19 16:55:16 +03:00
|
|
|
doBenchmark = drv: overrideCabal drv (drv: { doBenchmark = true; });
|
|
|
|
dontBenchmark = drv: overrideCabal drv (drv: { doBenchmark = false; });
|
|
|
|
|
2015-09-15 16:02:39 +03:00
|
|
|
doDistribute = drv: overrideCabal drv (drv: { hydraPlatforms = drv.platforms or ["i686-linux" "x86_64-linux" "x86_64-darwin"]; });
|
2015-01-10 22:26:08 +03:00
|
|
|
dontDistribute = drv: overrideCabal drv (drv: { hydraPlatforms = []; });
|
|
|
|
|
2015-01-12 03:28:15 +03:00
|
|
|
appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; });
|
2017-08-01 19:44:08 +03:00
|
|
|
removeConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = lib.remove x (drv.configureFlags or []); });
|
2015-01-10 22:26:08 +03:00
|
|
|
|
2015-01-19 16:59:04 +03:00
|
|
|
addBuildTool = drv: x: addBuildTools drv [x];
|
|
|
|
addBuildTools = drv: xs: overrideCabal drv (drv: { buildTools = (drv.buildTools or []) ++ xs; });
|
|
|
|
|
2015-02-03 14:24:13 +03:00
|
|
|
addExtraLibrary = drv: x: addExtraLibraries drv [x];
|
|
|
|
addExtraLibraries = drv: xs: overrideCabal drv (drv: { extraLibraries = (drv.extraLibraries or []) ++ xs; });
|
|
|
|
|
2015-01-21 01:50:38 +03:00
|
|
|
addBuildDepend = drv: x: addBuildDepends drv [x];
|
|
|
|
addBuildDepends = drv: xs: overrideCabal drv (drv: { buildDepends = (drv.buildDepends or []) ++ xs; });
|
|
|
|
|
2015-08-06 13:37:46 +03:00
|
|
|
addPkgconfigDepend = drv: x: addPkgconfigDepends drv [x];
|
2015-12-16 23:49:33 +03:00
|
|
|
addPkgconfigDepends = drv: xs: overrideCabal drv (drv: { pkgconfigDepends = (drv.pkgconfigDepends or []) ++ xs; });
|
2015-08-06 13:37:46 +03:00
|
|
|
|
2017-03-25 07:23:01 +03:00
|
|
|
addSetupDepend = drv: x: addSetupDepends drv [x];
|
|
|
|
addSetupDepends = drv: xs: overrideCabal drv (drv: { setupHaskellDepends = (drv.setupHaskellDepends or []) ++ xs; });
|
|
|
|
|
2015-01-10 22:26:08 +03:00
|
|
|
enableCabalFlag = drv: x: appendConfigureFlag (removeConfigureFlag drv "-f-${x}") "-f${x}";
|
|
|
|
disableCabalFlag = drv: x: appendConfigureFlag (removeConfigureFlag drv "-f${x}") "-f-${x}";
|
|
|
|
|
2015-01-23 12:47:55 +03:00
|
|
|
markBroken = drv: overrideCabal drv (drv: { broken = true; });
|
|
|
|
markBrokenVersion = version: drv: assert drv.version == version; markBroken drv;
|
2015-01-12 18:12:33 +03:00
|
|
|
|
2015-01-13 14:28:17 +03:00
|
|
|
enableLibraryProfiling = drv: overrideCabal drv (drv: { enableLibraryProfiling = true; });
|
|
|
|
disableLibraryProfiling = drv: overrideCabal drv (drv: { enableLibraryProfiling = false; });
|
|
|
|
|
2015-02-06 14:10:56 +03:00
|
|
|
enableSharedExecutables = drv: overrideCabal drv (drv: { enableSharedExecutables = true; });
|
|
|
|
disableSharedExecutables = drv: overrideCabal drv (drv: { enableSharedExecutables = false; });
|
2015-01-13 14:28:17 +03:00
|
|
|
|
|
|
|
enableSharedLibraries = drv: overrideCabal drv (drv: { enableSharedLibraries = true; });
|
|
|
|
disableSharedLibraries = drv: overrideCabal drv (drv: { enableSharedLibraries = false; });
|
|
|
|
|
2017-01-02 19:19:28 +03:00
|
|
|
enableDeadCodeElimination = drv: overrideCabal drv (drv: { enableDeadCodeElimination = true; });
|
|
|
|
disableDeadCodeElimination = drv: overrideCabal drv (drv: { enableDeadCodeElimination = false; });
|
2015-01-13 14:28:17 +03:00
|
|
|
|
|
|
|
enableStaticLibraries = drv: overrideCabal drv (drv: { enableStaticLibraries = true; });
|
|
|
|
disableStaticLibraries = drv: overrideCabal drv (drv: { enableStaticLibraries = false; });
|
|
|
|
|
2015-01-23 12:47:55 +03:00
|
|
|
appendPatch = drv: x: appendPatches drv [x];
|
|
|
|
appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; });
|
|
|
|
|
2015-04-01 17:42:52 +03:00
|
|
|
doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; });
|
|
|
|
dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; });
|
|
|
|
|
2016-09-14 19:58:46 +03:00
|
|
|
disableHardening = drv: flags: overrideCabal drv (drv: { hardeningDisable = flags; });
|
|
|
|
|
2017-09-01 17:49:50 +03:00
|
|
|
# Controls if Nix should strip the binary files (removes debug symbols)
|
|
|
|
doStrip = drv: overrideCabal drv (drv: { dontStrip = false; });
|
|
|
|
dontStrip = drv: overrideCabal drv (drv: { dontStrip = true; });
|
|
|
|
|
2017-09-19 16:55:50 +03:00
|
|
|
# Useful for debugging segfaults with gdb.
|
2017-09-01 17:49:50 +03:00
|
|
|
# -g: enables debugging symbols
|
|
|
|
# --disable-*-stripping: tell GHC not to strip resulting binaries
|
|
|
|
# dontStrip: see above
|
|
|
|
enableDWARFDebugging = drv:
|
|
|
|
appendConfigureFlag (dontStrip drv) "--ghc-options=-g --disable-executable-stripping --disable-library-stripping";
|
|
|
|
|
2017-08-01 19:44:08 +03:00
|
|
|
sdistTarball = pkg: lib.overrideDerivation pkg (drv: {
|
2015-06-02 14:58:57 +03:00
|
|
|
name = "${drv.pname}-source-${drv.version}";
|
2017-08-10 09:47:07 +03:00
|
|
|
# Since we disable the haddock phase, we also need to override the
|
|
|
|
# outputs since the separate doc output will not be produced.
|
|
|
|
outputs = ["out"];
|
2015-06-02 14:58:57 +03:00
|
|
|
buildPhase = "./Setup sdist";
|
|
|
|
haddockPhase = ":";
|
|
|
|
checkPhase = ":";
|
2015-08-30 16:18:15 +03:00
|
|
|
installPhase = "install -D dist/${drv.pname}-*.tar.gz $out/${drv.pname}-${drv.version}.tar.gz";
|
2015-06-02 14:58:57 +03:00
|
|
|
fixupPhase = ":";
|
|
|
|
});
|
|
|
|
|
2017-04-07 02:28:44 +03:00
|
|
|
linkWithGold = drv : appendConfigureFlag drv
|
|
|
|
"--ghc-option=-optl-fuse-ld=gold --ld-option=-fuse-ld=gold --with-ld=ld.gold";
|
|
|
|
|
2017-03-07 20:13:59 +03:00
|
|
|
# link executables statically against haskell libs to reduce closure size
|
|
|
|
justStaticExecutables = drv: overrideCabal drv (drv: {
|
|
|
|
enableSharedExecutables = false;
|
|
|
|
isLibrary = false;
|
|
|
|
doHaddock = false;
|
|
|
|
postFixup = "rm -rf $out/lib $out/nix-support $out/share/doc";
|
2017-08-01 19:44:08 +03:00
|
|
|
} // lib.optionalAttrs (pkgs.hostPlatform.isDarwin) {
|
2017-06-14 17:41:00 +03:00
|
|
|
configureFlags = (drv.configureFlags or []) ++ ["--ghc-option=-optl=-dead_strip"];
|
2017-08-01 19:44:08 +03:00
|
|
|
});
|
2017-03-07 20:13:59 +03:00
|
|
|
|
2017-08-01 19:44:08 +03:00
|
|
|
buildFromSdist = pkg: lib.overrideDerivation pkg (drv: {
|
2015-06-02 14:58:57 +03:00
|
|
|
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
|
2015-08-30 16:18:15 +03:00
|
|
|
cd ${pkg.pname}-*
|
2015-06-02 14:58:57 +03:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2017-09-10 14:09:52 +03:00
|
|
|
buildStrictly = pkg: buildFromSdist (failOnAllWarnings pkg);
|
|
|
|
|
|
|
|
failOnAllWarnings = drv: appendConfigureFlag drv "--ghc-option=-Wall --ghc-option=-Werror";
|
2015-06-02 14:58:57 +03:00
|
|
|
|
2017-08-30 15:40:54 +03:00
|
|
|
checkUnusedPackages =
|
|
|
|
{ ignoreEmptyImports ? false
|
|
|
|
, ignoreMainModule ? false
|
|
|
|
, ignorePackages ? []
|
|
|
|
} : drv :
|
|
|
|
overrideCabal (appendConfigureFlag drv "--ghc-option=-ddump-minimal-imports") (_drv: {
|
|
|
|
postBuild = with lib;
|
|
|
|
let args = concatStringsSep " " (
|
|
|
|
optional ignoreEmptyImports "--ignore-empty-imports" ++
|
|
|
|
optional ignoreMainModule "--ignore-main-module" ++
|
|
|
|
map (pkg: "--ignore-package ${pkg}") ignorePackages
|
|
|
|
);
|
|
|
|
in "${pkgs.haskellPackages.packunused}/bin/packunused" +
|
|
|
|
optionalString (args != "") " ${args}";
|
|
|
|
});
|
|
|
|
|
2016-03-06 12:35:25 +03:00
|
|
|
buildStackProject = pkgs.callPackage ./generic-stack-builder.nix { };
|
2016-03-04 23:24:42 +03:00
|
|
|
|
2015-06-07 01:05:17 +03:00
|
|
|
triggerRebuild = drv: i: overrideCabal drv (drv: { postUnpack = ": trigger rebuild ${toString i}"; });
|
|
|
|
|
2017-04-08 23:21:57 +03:00
|
|
|
overrideSrc = drv: { src, version ? drv.version }:
|
|
|
|
overrideCabal drv (_: { inherit src version; editedCabalFile = null; });
|
|
|
|
|
2015-01-07 22:31:32 +03:00
|
|
|
}
|