on iko/ghcjs-patch-master help sign in
Add cleanSourceHaskell and use it on nix-tools (#144)

Currently if you override nix-tools using `-I nix-tools` to point to a local directory that has build output directories like `dist-newstyle` those directories are hashed and copied to the nix store if they have changes. This change adds the `cleanHaskellSource` function from `iohk-nix` and runs it on nix-tools.

commit3d1c8afcde88a91c5d4d4011f74b977dddefc922 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateWed 22 May 2019, 15:14 (7 years ago) parent1f4730f
3 files changed+35−4
default.nix+7−1 lib/clean-source-haskell.nix+25 nix-tools/default.nix+3−3
default.nix+7−1
@@ -38,6 +38,9 @@ let
3838 # overridden with NIX_PATH.
3939 fetchExternal = import ./lib/fetch-external.nix;
4040
41+ # Function for cleaning haskell source directories pulled from iohk-nix
42+ cleanSourceHaskell = pkgs.callPackage ./lib/clean-source-haskell.nix {};
43+
4144 # All packages from Hackage as Nix expressions
4245 hackage = import (fetchExternal {
4346 name = "hackage-exprs-source";
@@ -108,7 +111,7 @@ let
108111 # Programs for generating Nix expressions from Cabal and Stack
109112 # files. We need to make sure we build this from the buildPackages,
110113 # we never want to actually cross compile nix-tools on it's own.
111− nix-tools = pkgs.buildPackages.callPackage ./nix-tools { inherit fetchExternal; inherit (self) mkCabalProjectPkgSet; };
114+ nix-tools = pkgs.buildPackages.callPackage ./nix-tools { inherit fetchExternal cleanSourceHaskell; inherit (self) mkCabalProjectPkgSet; };
112115
113116 # Function to call stackToNix
114117 callStackToNix = self.callPackage ./call-stack-to-nix.nix {};
@@ -127,6 +130,9 @@ let
127130 # Make this handy overridable fetch function available.
128131 inherit fetchExternal;
129132
133+ # Function for cleaning haskell source diretories.
134+ inherit cleanSourceHaskell;
135+
130136 # Produce a fixed output derivation from a moving target (hackage index tarball)
131137 hackageTarball = { index-state, sha256 }:
132138 pkgs.runCommand "01-index.tar.gz-at-${builtins.replaceStrings [":"] [""] index-state}" {
lib/clean-source-haskell.nixnew file+25
@@ -0,0 +1,25 @@
1+# This function cleans common build products and files not needed to do a
2+# haskell build from a source directory.
3+# This can avoid unecessary builds when these files change.
4+# It has been copied from iohk-nix so that it can be used internally in
5+# haskell.nix and made available to projects that do not use iohk-nix.
6+# The original version is here:
7+# https://github.com/input-output-hk/iohk-nix/blob/c01bbd4e0c55a4101e2078d24046e0b2a731f871/clean-source-haskell.nix
8+{ pkgs }: src:
9+ let lib = pkgs.lib;
10+ in if (builtins.typeOf src) == "path"
11+ then lib.cleanSourceWith {
12+ filter = with pkgs.stdenv;
13+ name: type: let baseName = baseNameOf (toString name); in ! (
14+ # Filter out cabal build products.
15+ baseName == "dist" || baseName == "dist-newstyle" ||
16+ baseName == "cabal.project.local" ||
17+ lib.hasPrefix ".ghc.environment" baseName ||
18+ # Filter out stack build products.
19+ lib.hasPrefix ".stack-work" baseName ||
20+ # Filter out files which are commonly edited but don't
21+ # affect the cabal build.
22+ lib.hasSuffix ".nix" baseName
23+ );
24+ src = lib.cleanSource src;
25+ } else src
nix-tools/default.nix+3−3
@@ -1,11 +1,11 @@
1−{ symlinkJoin, fetchExternal, mkCabalProjectPkgSet }:
1+{ symlinkJoin, fetchExternal, cleanSourceHaskell, mkCabalProjectPkgSet }:
22
33let
4− src = fetchExternal {
4+ src = cleanSourceHaskell (fetchExternal {
55 name = "nix-tools-src";
66 specJSON = ./nix-tools-src.json;
77 override = "nix-tools";
8− };
8+ });
99
1010 pkgSet = mkCabalProjectPkgSet {
1111 plan-pkgs = import ./pkgs.nix;