|
24 | 24 | # you can pass the project in as a string. |
25 | 25 | rawCabalProject = if cabalProject != null |
26 | 26 | then cabalProject |
27 | | - else builtins.readFile (cabalFiles.origSrc + "/cabal.project"); |
| 27 | + else |
| 28 | + if ((builtins.readDir cabalFiles.origSrc)."cabal.project" or "") == "regular" |
| 29 | + then builtins.readFile (cabalFiles.origSrc + "/cabal.project") |
| 30 | + else null; |
28 | 31 |
|
29 | 32 | span = pred: list: |
30 | 33 | let n = pkgs.lib.lists.foldr (x: acc: if pred x then acc + 1 else 0) 0 list; |
|
61 | 64 | otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd; |
62 | 65 | }; |
63 | 66 |
|
| 67 | + # Deal with source-repository-packages in a way that will work on |
| 68 | + # hydra build agents (as long as a sha256 is included). |
64 | 69 | # Replace source-repository-package blocks that have a sha256 with |
65 | 70 | # packages: block containing nix sotre paths of the fetched repos. |
66 | 71 | replaceSoureRepos = projectFile: |
|
69 | 74 | initialText = pkgs.lib.lists.take 1 blocks; |
70 | 75 | repoBlocks = builtins.map parseBlock (pkgs.lib.lists.drop 1 blocks); |
71 | 76 | sourceRepos = pkgs.lib.lists.concatMap (x: x.sourceRepo) repoBlocks; |
72 | | - in { |
73 | | - otherText = pkgs.lib.strings.concatStringsSep "\n" ( |
| 77 | + otherText = pkgs.writeText "cabal.project" (pkgs.lib.strings.concatStringsSep "\n" ( |
74 | 78 | initialText |
75 | | - ++ (builtins.map (x: x.otherText) repoBlocks)); |
| 79 | + ++ (builtins.map (x: x.otherText) repoBlocks))); |
| 80 | + in { |
76 | 81 | inherit sourceRepos; |
| 82 | + makeFixedProjectFile = '' |
| 83 | + cp -f ${otherText} ./cabal.project |
| 84 | + chmod +w -R ./cabal.project |
| 85 | + echo "packages:" >> ./cabal.project |
| 86 | + mkdir -p ./.source-repository-packages |
| 87 | + '' + |
| 88 | + ( pkgs.lib.strings.concatStrings ( |
| 89 | + pkgs.lib.lists.zipListsWith (n: f: '' |
| 90 | + mkdir -p ./.source-repository-packages/${builtins.toString n} |
| 91 | + rsync -a --prune-empty-dirs \ |
| 92 | + --include '*/' --include '*.cabal' --include 'package.yaml' \ |
| 93 | + --exclude '*' \ |
| 94 | + "${f}/" "./.source-repository-packages/${builtins.toString n}/" |
| 95 | + echo " ./.source-repository-packages/${builtins.toString n}" >> ./cabal.project |
| 96 | + '') |
| 97 | + (pkgs.lib.lists.range 0 ((builtins.length fixedProject.sourceRepos) - 1)) |
| 98 | + sourceRepos |
| 99 | + ) |
| 100 | + ); |
77 | 101 | }; |
78 | 102 |
|
79 | | - fixedProject = replaceSoureRepos rawCabalProject; |
| 103 | + fixedProject = |
| 104 | + if rawCabalProject == null |
| 105 | + then { |
| 106 | + sourceRepos = []; |
| 107 | + makeFixedProjectFile = ""; |
| 108 | + } |
| 109 | + else replaceSoureRepos rawCabalProject; |
80 | 110 |
|
81 | | - # Deal with source-repository-packages in a way that will work on |
82 | | - # hydra build agents (as long as a sha256 is included). |
83 | | - fixedProjectFile = pkgs.writeText "cabal.project" fixedProject.otherText; |
84 | | - |
85 | 111 | plan = runCommand "plan-to-nix-pkgs" { |
86 | 112 | nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ]; |
87 | 113 | } ('' |
88 | 114 | tmp=$(mktemp -d) |
89 | 115 | cd $tmp |
90 | 116 | cp -r ${cabalFiles}/* . |
91 | 117 | chmod +w -R . |
92 | | - cp -f ${fixedProjectFile} ./cabal.project |
93 | | - chmod +w -R ./cabal.project |
94 | | - echo "packages:" >> ./cabal.project |
95 | | - mkdir -p ./.source-repository-packages |
96 | | - '' + |
97 | | - ( pkgs.lib.strings.concatStrings ( |
98 | | - pkgs.lib.lists.zipListsWith (n: f: '' |
99 | | - mkdir -p ./.source-repository-packages/${builtins.toString n} |
100 | | - rsync -a --prune-empty-dirs \ |
101 | | - --include '*/' --include '*.cabal' --include 'package.yaml' \ |
102 | | - --exclude '*' \ |
103 | | - "${f}/" "./.source-repository-packages/${builtins.toString n}/" |
104 | | - echo " ./.source-repository-packages/${builtins.toString n}" >> ./cabal.project |
105 | | - '') |
106 | | - (pkgs.lib.lists.range 0 ((builtins.length fixedProject.sourceRepos) - 1)) |
107 | | - fixedProject.sourceRepos |
108 | | - ) |
109 | | - ) + '' |
| 118 | + ${fixedProject.makeFixedProjectFile} |
110 | 119 | # warning: this may not generate the proper cabal file. |
111 | 120 | # hpack allows globbing, and turns that into module lists |
112 | 121 | # without the source available (we cleaneSourceWith'd it), |
|
0 commit comments