on iko/ghcjs-patch-master help sign in
Support Nix <2.4 (#1418)
8eb5d29Hamish Mackenzie
lib/clean-source-with.nix+36−5
@@ -2,10 +2,7 @@
2# https://github.com/NixOS/nixpkgs/blob/1d9d31a0eb8e8358830528538a391df52f6a075a/lib/sources.nix#L41
2# https://github.com/NixOS/nixpkgs/blob/1d9d31a0eb8e8358830528538a391df52f6a075a/lib/sources.nix#L41
3# It adds a subDir argument in a way that allows descending into a subdirectory
3# It adds a subDir argument in a way that allows descending into a subdirectory
4# to compose with cleaning the source with a filter.
4# to compose with cleaning the source with a filter.
5−{ lib }:
5+{ lib }: rec {
6−if lib.versionOlder builtins.nixVersion "2.4"
7−then throw "Nix version 2.4 or higher is required for Haskell.nix"
8−else rec {
9
6
10 # Like `builtins.filterSource`, except it will compose with itself,
7 # Like `builtins.filterSource`, except it will compose with itself,
11 # allowing you to chain multiple calls together without any
8 # allowing you to chain multiple calls together without any
@@ -53,6 +50,33 @@ else rec {
53 # (and forward a `name` argument) can use this to make
50 # (and forward a `name` argument) can use this to make
54 # the message to the use more meaningful.
51 # the message to the use more meaningful.
55 #
52 #
53+ # Nix <2.4 Suport with filterPath
54+ #
55+ # As of Nix >=2.4 filtering is now possible on all paths (including those in the store).
56+ # If you still need to support older versions of Nix and want to maximise cache hits for your project
57+ # you may want to consider using setting the `filterPath` attribute on `src` (must be done on
58+ # the original src not the output of another `cleanSourceWith`).
59+ #
60+ # To disable filtering completely replace:
61+ #
62+ # src = ./.;
63+ #
64+ # with:
65+ #
66+ # src = { outPath = ./.; filterPath = { path, ... }: path; };
67+ #
68+ # To disable filtering only when the path is in the store use (when Nix <2.4 is unable to filter it):
69+ #
70+ # src = {
71+ # outPath = ./.;
72+ # filterPath = { path, ... }@args:
73+ # if builtins.hasContext (toString path) then path else builtins.path args;
74+ # };
75+ #
76+ # Currently `haskell-nix.hackage-project` (used by `hackage-package`, `tool` and `tools`) disables
77+ # filtering. See `overlays/haskell.nix` for details.
78+ #
79+ # For more see https://github.com/input-output-hk/haskell.nix/pull/1418
56 cleanSourceWith = { filter ? _path: _type: true, src, subDir ? "", name ? null
80 cleanSourceWith = { filter ? _path: _type: true, src, subDir ? "", name ? null
57 , caller ? "cleanSourceWith", includeSiblings ? false }:
81 , caller ? "cleanSourceWith", includeSiblings ? false }:
58 let
82 let
@@ -106,10 +130,17 @@ else rec {
106 __trace (
130 __trace (
107 "WARNING: `${caller}` called on ${toString src} without a `name`. "
131 "WARNING: `${caller}` called on ${toString src} without a `name`. "
108 + "Consider adding `name = \"${baseNameOf src}\";`") "source";
132 + "Consider adding `name = \"${baseNameOf src}\";`") "source";
133+ filterPath = origSrc.filterPath or (
134+ if builtins.compareVersions builtins.nixVersion "2.4" >= 0
135+ then builtins.path
136+ else __trace "WARNING: Using nix <2.4 will result in inconsistent filtering of ${toString origSrc} (see lib/clean-source-with.nix)"
137+ (if builtins.hasContext or (lib.hasPrefix builtins.storeDir) (toString origSrc)
138+ then { path, ... }: path
139+ else builtins.path));
109 in {
140 in {
110 inherit origSrc origSubDir origSrcSubDir;
141 inherit origSrc origSubDir origSrcSubDir;
111 filter = filter';
142 filter = filter';
112− outPath = (builtins.path { filter = filter'; path = origSrc; name = name'; }) + origSubDir;
143+ outPath = (filterPath { filter = filter'; path = origSrc; name = name'; }) + origSubDir;
113 _isLibCleanSourceWithEx = true;
144 _isLibCleanSourceWithEx = true;
114 # It is only safe for older cleanSourceWith to filter this one
145 # It is only safe for older cleanSourceWith to filter this one
115 # if the we are still looking at the root of origSrc
146 # if the we are still looking at the root of origSrc
overlays/haskell.nix+8−2
@@ -471,14 +471,20 @@ final: prev: {
471 inherit (rev) sha256;
471 inherit (rev) sha256;
472 };
472 };
473 revSuffix = final.lib.optionalString (rev.revNum > 0) "-r${toString rev.revNum}";
473 revSuffix = final.lib.optionalString (rev.revNum > 0) "-r${toString rev.revNum}";
474− in let src = final.buildPackages.pkgs.runCommand "${name}-${version'}${revSuffix}-src" { } (''
474+ in let src = final.buildPackages.pkgs.runCommand "${name}-${version'}${revSuffix}-src" {} (''
475 tmp=$(mktemp -d)
475 tmp=$(mktemp -d)
476 cd $tmp
476 cd $tmp
477 tar xzf ${tarball}
477 tar xzf ${tarball}
478 mv "${name}-${version'}" $out
478 mv "${name}-${version'}" $out
479 '' + final.lib.optionalString (rev.revNum > 0) ''
479 '' + final.lib.optionalString (rev.revNum > 0) ''
480 cp ${cabalFile} $out/${name}.cabal
480 cp ${cabalFile} $out/${name}.cabal
481− '');
481+ '') // {
482+ # TODO remove once nix >=2.4 is widely adopted (will trigger rebuilds of everything).
483+ # Disable filtering keeps pre ond post nix 2.4 behaviour the same. This means that
484+ # the same `alex`, `happy` and `hscolour` are used to build GHC. It also means that
485+ # that `tools` in the shell will be built the same.
486+ filterPath = { path, ... }: path;
487+ };
482 in cabalProject' (
488 in cabalProject' (
483 (final.haskell-nix.hackageQuirks { inherit name; version = version'; }) //
489 (final.haskell-nix.hackageQuirks { inherit name; version = version'; }) //
484 builtins.removeAttrs args [ "version" "revision" ] // { inherit src; });
490 builtins.removeAttrs args [ "version" "revision" ] // { inherit src; });