on iko/ghcjs-patch-master help sign in
Add support for cabal.project.local (#632)

Running `cabal v2-configure` overwrites the `cabal.project.local` file so this change adds the contents onto the end of the `cabal.project` file before running `cabal v2-configure`. You can override this behavior passing `cabalProjectLocal = ""` Treats cabal.project.feeze the same way as `cabal.project` and `cabal.project.local` in that it will still use it if it is filtered by cleanGit. This change also adds `cabalProjectFileName` arg so that we can override the default `cabal.project` name.

commite5a052243b25003adabc7e046caff72a40a2c5d7 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateMon 1 Jun 2020, 23:12 (6 years ago) parentc474dce
1 file changed+29−11
lib/call-cabal-project-to-nix.nix+29−11
lib/call-cabal-project-to-nix.nix+29−11
@@ -1,4 +1,11 @@
11{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes, haskellLib, materialize }@defaults:
2+let readIfExists = src: fileName:
3+ let origSrcDir = src.origSrcSubDir or src;
4+ in
5+ if ((__readDir origSrcDir)."${fileName}" or "") == "regular"
6+ then __readFile (origSrcDir + "/${fileName}")
7+ else null;
8+in
29{ name ? src.name or null # optional name for better error messages
310, src
411, index-state ? null # Hackage index-state, eg. "2019-10-10T00:00:00Z"
@@ -6,7 +13,10 @@
613, plan-sha256 ? null # The hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation)
714, materialized ? null # Location of a materialized copy of the nix files
815, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
9−, cabalProject ? null # Cabal project file (when null uses "${src}/cabal.project")
16+, cabalProjectFileName ? "cabal.project"
17+, cabalProject ? readIfExists src cabalProjectFileName
18+, cabalProjectLocal ? readIfExists src "${cabalProjectFileName}.local"
19+, cabalProjectFreeze ? readIfExists src "${cabalProjectFileName}.freeze"
1020, compiler-nix-name ? null # Nix name of the ghc compiler as a string eg. "ghc883"
1121, ghc ? null # Deprecated in favour of `compiler-nix-name`
1222, ghcOverride ? null # Used when we need to set ghc explicitly during bootstrapping
@@ -63,20 +73,24 @@ let
6373 src = src.origSrc;
6474 filter = path: type: src.filter path type && (
6575 type == "directory" ||
66− pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" ".freeze" "package.yaml" ]); })
76+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".cabal" "package.yaml" ]); })
6777 else src.origSrc or src;
6878
6979 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
7080 # access to the store is restricted. If origSrc was already in the store
7181 # you can pass the project in as a string.
7282 rawCabalProject =
73− let origSrcDir = (maybeCleanedSource.origSrcSubDir or maybeCleanedSource) + subDir';
74− in if cabalProject != null
75− then cabalProject
76− else
77− if ((builtins.readDir origSrcDir)."cabal.project" or "") == "regular"
78− then builtins.readFile (origSrcDir + "/cabal.project")
79− else null;
83+ if cabalProject != null
84+ then cabalProject + (
85+ if cabalProjectLocal != null
86+ then ''
87+
88+ -- Added from cabalProjectLocal argument to cabalProject
89+ ${cabalProjectLocal}
90+ ''
91+ else ""
92+ )
93+ else null;
8094
8195 # Look for a index-state: field in the cabal.project file
8296 parseIndexState = rawCabalProject:
@@ -107,7 +121,7 @@ let
107121
108122in
109123 assert (if index-state-found == null
110− then throw "No index state passed and none found in cabal.project" else true);
124+ then throw "No index state passed and none found in ${cabalProjectFileName}" else true);
111125 assert (if index-sha256-found == null
112126 then throw "provided sha256 for index-state ${index-state-found} is null!" else true);
113127
@@ -144,7 +158,7 @@ let
144158 ref = repo.tag;
145159 };
146160 in __trace "WARNING: No sha256 found for source-repository-package ${repo.location} ${repo.tag} download may fail in restricted mode (hydra)"
147− (__trace "Consider adding `--sha256: ${hashPath drv}` to the cabal.project file or passing in a lookupSha256 argument"
161+ (__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a lookupSha256 argument"
148162 drv)
149163 ) + (if repo.subdir or "" == "" then "" else "/" + repo.subdir);
150164
@@ -359,6 +373,10 @@ let
359373 find . -name package.yaml -exec hpack "{}" \;
360374 ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
361375 ${fixedProject.makeFixedProjectFile}
376+ ${pkgs.lib.optionalString (cabalProjectFreeze != null) ''
377+ cp ${pkgs.evalPackages.writeText "cabal.project.freeze" cabalProjectFreeze} \
378+ cabal.project.freeze
379+ ''}
362380 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
363381 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
364382 HOME=${dotCabal {