on iko/ghcjs-patch-master help sign in
Remove `canCleanSource` (#1409)

In recent nix, builtins.path works in restricted eval mode. Therefore canCleanSource is not required anymore. follow up on #1403 * add comment on hydra overlay * throw error on outdated nix version

commita385241331a3b627da214a458372aa2bb339ccc8 authorDavHau <hsngrmpf+github@gmail.com> dateFri 25 Mar 2022, 06:57 (5 years ago) parent7ae4953
8 files changed+48−70
build.nix+5−1 lib/call-stack-to-nix.nix+9−12 lib/clean-cabal-component.nix+2−2 lib/clean-source-with.nix+4−8 lib/default.nix+5−22 lib/import-and-filter-project.nix+5−8 lib/stack-cache-generator.nix+14−17 overlays/hydra.nix+4
build.nix+5−1
@@ -68,7 +68,11 @@ in rec {
6868 ];
6969 };
7070 check-materialization-concurrency = pkgs.buildPackages.callPackage ./scripts/check-materialization-concurrency/check.nix {};
71− check-path-support = pkgs.buildPackages.callPackage ./scripts/check-path-support.nix {};
71+ check-path-support = pkgs.buildPackages.callPackage ./scripts/check-path-support.nix {
72+ # TODO remove this when nixpkgs-2205 is released and used for `pkgs`
73+ # check-path-support fails unless we have nix 2.4 or newer.
74+ inherit (import haskellNix.sources.nixpkgs-unstable {}) nix;
75+ };
7276 };
7377
7478 # These are pure parts of maintainer-script so they can be built by hydra
lib/call-stack-to-nix.nix+9−12
@@ -24,15 +24,12 @@ let
2424
2525 subDir' = src.origSubDir or "";
2626 subDir = pkgs.lib.strings.removePrefix "/" subDir';
27− maybeCleanedSource =
28− if haskellLib.canCleanSource src
29− then (haskellLib.cleanSourceWith {
30− name = if name != null then "${name}-root-cabal-files" else "source-root-cabal-files";
31− src = src.origSrc or src;
32− filter = path: type: (!(src ? filter) || src.filter path type) && (
33− type == "directory" ||
34− pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ stackYaml ".cabal" "package.yaml" ]); })
35− else src.origSrc or src;
27+ cleanedSource = (haskellLib.cleanSourceWith {
28+ name = if name != null then "${name}-root-cabal-files" else "source-root-cabal-files";
29+ src = src.origSrc or src;
30+ filter = path: type: (!(src ? filter) || src.filter path type) && (
31+ type == "directory" ||
32+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ stackYaml ".cabal" "package.yaml" ]); });
3633
3734 stackToNixArgs = builtins.concatStringsSep " " [
3835 "--full"
@@ -59,14 +56,14 @@ let
5956 mkdir -p $out${subDir'}
6057 SRC=$(mktemp -d)
6158 cd $SRC
62− # if maybeCleanedSource is empty, this means it's a new
59+ # if cleanedSource is empty, this means it's a new
6360 # project where the files haven't been added to the git
6461 # repo yet. We fail early and provide a useful error
6562 # message to prevent headaches (#290).
66− if [ -z "$(ls -A ${maybeCleanedSource})" ]; then
63+ if [ -z "$(ls -A ${cleanedSource})" ]; then
6764 echo "cleaned source is empty. Did you forget to 'git add -A'?"; exit 1;
6865 fi
69− lndir -silent "${maybeCleanedSource}/." $SRC
66+ lndir -silent "${cleanedSource}/." $SRC
7067 ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
7168 ${
7269 # If a resolver was fetched use the it instead of the original stack.yaml
lib/clean-cabal-component.nix+2−2
@@ -1,6 +1,6 @@
11# Use cleanSourceWith to filter just the files needed for a particular
22# component of the package
3−{ lib, cleanSourceWith, canCleanSource }: package: component: componentName: src:
3+{ lib, cleanSourceWith }: package: component: componentName: src:
44let
55 srcStr' = src.origSrc or null;
66 subDir = if src.origSubDir or "" == ""
@@ -56,7 +56,7 @@ let
5656 then p
5757 else p + "/";
5858in
59− if srcStr' == null || package.detailLevel != "FullDetails" || !canCleanSource src
59+ if srcStr' == null || package.detailLevel != "FullDetails"
6060 then src
6161 else
6262 let
lib/clean-source-with.nix+4−8
@@ -2,7 +2,10 @@
22# https://github.com/NixOS/nixpkgs/blob/1d9d31a0eb8e8358830528538a391df52f6a075a/lib/sources.nix#L41
33# It adds a subDir argument in a way that allows descending into a subdirectory
44# to compose with cleaning the source with a filter.
5−{ lib }: rec {
5+{ lib }:
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 {
69
710 # Like `builtins.filterSource`, except it will compose with itself,
811 # allowing you to chain multiple calls together without any
@@ -113,11 +116,4 @@
113116 _isLibCleanSourceWith = origSubDir == "";
114117 name = name';
115118 };
116−
117− pathHasContext = builtins.hasContext or (lib.hasPrefix builtins.storeDir);
118−
119− canCleanSource = src:
120− src ? _isLibCleanSourceWithEx
121− || src ? _isLibCleanSourceWith
122− || !(pathHasContext (toString src));
123119}
lib/default.nix+5−22
@@ -192,11 +192,11 @@ in {
192192 collectChecks' = collectChecks (_: true);
193193
194194 # Replacement for lib.cleanSourceWith that has a subDir argument.
195− inherit (import ./clean-source-with.nix { inherit lib; }) cleanSourceWith canCleanSource;
195+ inherit (import ./clean-source-with.nix { inherit lib; }) cleanSourceWith;
196196
197197 # Use cleanSourceWith to filter just the files needed for a particular
198198 # component of a package
199− cleanCabalComponent = import ./clean-cabal-component.nix { inherit lib cleanSourceWith canCleanSource; };
199+ cleanCabalComponent = import ./clean-cabal-component.nix { inherit lib cleanSourceWith; };
200200
201201 # Clean git directory based on `git ls-files --recurse-submodules`
202202 cleanGit = import ./clean-git.nix {
@@ -290,26 +290,9 @@ in {
290290 if subDir == ""
291291 then src
292292 else
293− if haskellLib.canCleanSource src
294− then haskellLib.cleanSourceWith {
295− inherit src subDir includeSiblings;
296− }
297− else let name = src.name or "source" + "-" + __replaceStrings ["/"] ["-"] subDir;
298− in if includeSiblings
299− then rec {
300− # Keep `src.origSrc` so it can be used to allow references
301− # to other parts of that root.
302− inherit name;
303− origSrc = src.origSrc or src;
304− origSubDir = src.origSubDir or "" + "/" + subDir;
305− outPath = origSrc + origSubDir;
306− }
307− else {
308− # We are not going to need other parts of `origSrc` if there
309− # was one and we can ignore it
310− inherit name;
311− outPath = src + "/" + subDir;
312− };
293+ haskellLib.cleanSourceWith {
294+ inherit src subDir includeSiblings;
295+ };
313296
314297 # Givin a `src` split it into a `root` path (based on `src.origSrc` if
315298 # present) and `subDir` (based on `src.origSubDir). The
lib/import-and-filter-project.nix+5−8
@@ -6,14 +6,11 @@
66let
77 # Full source including possible relative paths form the
88 # project directory.
9− srcRoot =
10− if haskellLib.canCleanSource src
11− then haskellLib.cleanSourceWith {
12− name = if src ? name then "${src.name}-root" else "source-root";
13− src = src.origSrc or src;
14− filter = src.filter or (_: _: true);
15− }
16− else src.origSrc or src;
9+ srcRoot = haskellLib.cleanSourceWith {
10+ name = if src ? name then "${src.name}-root" else "source-root";
11+ src = src.origSrc or src;
12+ filter = src.filter or (_: _: true);
13+ };
1714 # The sub directory containing the cabal.project or stack.yaml file
1815 projectSubDir' = src.origSubDir or ""; # With leading /
1916 projectSubDir = pkgs.lib.strings.removePrefix "/" projectSubDir'; # Without /
lib/stack-cache-generator.nix+14−17
@@ -30,25 +30,22 @@ let
3030 }) resolver fetchedResolver;
3131
3232 # Filter just the stack yaml file and any resolver yaml file it points to.
33− maybeCleanedSource =
34− if haskellLib.canCleanSource src
35− then haskellLib.cleanSourceWith {
36− inherit src;
37− filter = path: type:
38− let
39− origSrc = if src ? _isLibCleanSourceWith then src.origSrc else src;
40− origSubDir = if src ? _isLibCleanSourceWithEx then src.origSubDir else "";
41− relPath = pkgs.lib.removePrefix (toString origSrc + origSubDir + "/") path;
33+ maybeCleanedSource = haskellLib.cleanSourceWith {
34+ inherit src;
35+ filter = path: type:
36+ let
37+ origSrc = if src ? _isLibCleanSourceWith then src.origSrc else src;
38+ origSubDir = if src ? _isLibCleanSourceWithEx then src.origSubDir else "";
39+ relPath = pkgs.lib.removePrefix (toString origSrc + origSubDir + "/") path;
4240
43− # checks if path1 is a parent directory for path2
44− isParent = path1: path2: pkgs.lib.hasPrefix "${path1}/" path2;
41+ # checks if path1 is a parent directory for path2
42+ isParent = path1: path2: pkgs.lib.hasPrefix "${path1}/" path2;
4543
46− in
47− (relPath == stackYaml)
48− || (resolver != null && (relPath == resolver || isParent relPath resolver))
49− ;
50− }
51− else src;
44+ in
45+ (relPath == stackYaml)
46+ || (resolver != null && (relPath == resolver || isParent relPath resolver))
47+ ;
48+ };
5249
5350 # All repos served via ssh or git protocols are usually private
5451 private = url: pkgs.lib.substring 0 4 url != "http";
overlays/hydra.nix+4
@@ -1,4 +1,8 @@
11{ sources, ...}:
2+# This hydra overlay is required to circumvent problems with builtins.path
3+# in restricted eval mode.
4+# This can be removed once hydra in nixpkgs is based on a recent enough nix,
5+# which contains this fix: https://github.com/NixOS/nix/pull/5163
26
37final: prev: {
48 hydra-unstable = sources.hydra.defaultPackage.${prev.system};