mirror of
https://github.com/simplex-chat/haskell.nix.git
synced 2026-06-03 09:17:32 +00:00
When trying to build haskell packages from local source using nix ( source code you have used `git clone` to retrieve and have modified) it is often annoying that small changes can trigger a lot of components to be built unnecessarily. For instance if you change the code for a test in a package it will often trigger builds of the library and all its dependencies. To avoid this problem we could manually set up `cleanSourceWith` calls in nix to filter out files that are not need, but to do this every component would be difficult and error prone. This change automates this process using the information in the packages `.cabal` file to filter the source of each component automatically when using `callCabalPlanToNix` (we should be able to add it to `callStackToNix` too). ## How does it work? * A new version on `cleanSourceWith` is used that adds a `subDir` argument. It allows descending into a subdirectory to compose with cleaning the source. * A new `--full` argument is passed to `plan-to-nix` by `callCabalPlanToNix` telling it to output extra information about the cabal packages in the plan (directories and filenames). * `callCabalProjectToNix` uses the new `subDir` argument of `cleanSourceWith` when setting the packageSrc. * `comp-builder.nix` and `setup-builder.nix` use a new `cleanCabalComponent` function to further clean the packageSrc using the new information in the `package` and `component`. ## hpack wildcards `package.yaml` files can include wild cards and these are not handled yet (they do not map to anything in the `.cabal` file and so are lost). They will need to be added manually to the appropriate field (eg. `packages.xyz.package.dataFiles`) If your hpack file does not contain wildcards or if you are willing to add the wildcards entries manually in nix it is still useful to enable cleaning on hpack. For example: ``` packages.ghc-toolkit.package.cleanHpack = true; packages.ghc-toolkit.components.library.extraSrcFiles = [ "genapply/**/**" "boot-libs/**/**" "ghc-libdir/**/**" ]; ```
67 lines
1.8 KiB
Nix
67 lines
1.8 KiB
Nix
{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }:
|
|
|
|
{ setup-depends, package, name, src, flags }:
|
|
|
|
let
|
|
component = {
|
|
depends = setup-depends;
|
|
libs = [];
|
|
frameworks = [];
|
|
doExactConfig = false;
|
|
# We have to set hsSourceDirs or cleanCabalComponent will
|
|
# include everything (and as a result all the components of
|
|
# the package will depend on eveything in the package).
|
|
# TODO find a better way
|
|
hsSourceDirs = ["setup-src"];
|
|
includeDirs = [];
|
|
asmSources = [];
|
|
cSources = [];
|
|
cmmSources = [];
|
|
cxxSources = [];
|
|
jsSources = [];
|
|
extraSrcFiles = [ "Setup.hs" "Setup.lhs" ];
|
|
};
|
|
cleanSrc = haskellLib.cleanCabalComponent package component src;
|
|
|
|
fullName = "${name}-setup";
|
|
|
|
includeGhcPackage = lib.any (p: p.identifier.name == "ghc") setup-depends;
|
|
|
|
configFiles = makeSetupConfigFiles {
|
|
inherit (package) identifier;
|
|
inherit fullName flags component;
|
|
};
|
|
|
|
in
|
|
stdenv.lib.fix (drv:
|
|
stdenv.mkDerivation {
|
|
name = "${fullName}";
|
|
src = cleanSrc;
|
|
nativeBuildInputs = [ghc];
|
|
|
|
passthru = {
|
|
inherit (package) identifier;
|
|
config = component;
|
|
inherit configFiles cleanSrc;
|
|
};
|
|
|
|
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 -threaded '' + (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
|
|
'';
|
|
})
|