|
1 | 1 | { dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes }: |
2 | 2 | let defaultGhc = ghc; |
3 | 3 | defaultCabalInstall = cabal-install; |
4 | | -in { index-state, index-sha256 ? index-state-hashes.${index-state} or null, src, ghc ? defaultGhc, cabal-install ? defaultCabalInstall }: |
| 4 | +in { index-state ? null, index-sha256 ? null, src, ghc ? defaultGhc, |
| 5 | + cabal-install ? defaultCabalInstall, cabalProject ? null }: |
5 | 6 |
|
6 | | -# better error message than just assert failed. |
7 | | -assert (if index-sha256 == null then throw "provided sha256 for index-state ${index-state} is null!" else true); |
8 | 7 | # cabal-install versions before 2.4 will generate insufficient plan information. |
9 | 8 | assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0 |
10 | 9 | then throw "cabal-install (current version: ${cabal-install.version}) needs to be at least 2.4 for plan-to-nix to work without cabal-to-nix" |
|
17 | 16 | filter = path: type: |
18 | 17 | type == "directory" || |
19 | 18 | pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]; } |
20 | | - else src; |
| 19 | + else src; |
| 20 | + |
| 21 | + # Using origSrc bypasses any cleanSourceWith so that it will work when |
| 22 | + # access to the store is restricted. If origSrc was already in the store |
| 23 | + # you can pass the project in as a string. |
| 24 | + rawCabalProject = if cabalProject != null |
| 25 | + then cabalProject |
| 26 | + else builtins.readFile ((maybeCleanedSource.origSrc or maybeCleanedSource) + "/cabal.project"); |
| 27 | + |
| 28 | + # Look for a index-state: field in the cabal.project file |
| 29 | + parseIndexState = rawCabalProject: |
| 30 | + let |
| 31 | + indexState = pkgs.lib.lists.concatLists ( |
| 32 | + pkgs.lib.lists.filter (l: l != null) |
| 33 | + (builtins.map (l: builtins.match "^index-state: *(.*)" l) |
| 34 | + (pkgs.lib.splitString "\n" rawCabalProject))); |
| 35 | + in |
| 36 | + pkgs.lib.lists.head (indexState ++ [ null ]); |
| 37 | + |
| 38 | + index-state-found = if index-state != null |
| 39 | + then index-state |
| 40 | + else parseIndexState rawCabalProject; |
| 41 | + |
| 42 | + # Lookup hash for the index state we found |
| 43 | + index-sha256-found = if index-sha256 != null |
| 44 | + then index-sha256 |
| 45 | + else index-state-hashes.${index-state-found} or null; |
| 46 | + |
| 47 | +in |
| 48 | + assert (if index-state-found == null |
| 49 | + then throw "No index state passed and none found in cabal.project" else true); |
| 50 | + assert (if index-sha256-found == null |
| 51 | + then throw "provided sha256 for index-state ${index-state-found} is null!" else true); |
| 52 | + |
| 53 | +let |
21 | 54 | plan = runCommand "plan-to-nix-pkgs" { |
22 | 55 | nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ]; |
23 | 56 | } '' |
|
32 | 65 | find . -name package.yaml -exec hpack "{}" \; |
33 | 66 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt |
34 | 67 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt |
35 | | - HOME=${dotCabal { inherit index-state; sha256 = index-sha256; }} cabal new-configure \ |
| 68 | + HOME=${dotCabal { |
| 69 | + index-state = index-state-found; |
| 70 | + sha256 = index-sha256-found; }} cabal new-configure \ |
36 | 71 | --with-ghc=${ghc.targetPrefix}ghc \ |
37 | 72 | --with-ghc-pkg=${ghc.targetPrefix}ghc-pkg |
38 | 73 |
|
|
0 commit comments