Skip to content

Commit c6a5aad

Browse files
committed
Fix callCabalProjectToNix without cabal.project
1 parent 08e843d commit c6a5aad

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

lib/call-cabal-project-to-nix.nix

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ let
2424
# you can pass the project in as a string.
2525
rawCabalProject = if cabalProject != null
2626
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;
2831

2932
span = pred: list:
3033
let n = pkgs.lib.lists.foldr (x: acc: if pred x then acc + 1 else 0) 0 list;
@@ -69,14 +72,39 @@ let
6972
initialText = pkgs.lib.lists.take 1 blocks;
7073
repoBlocks = builtins.map parseBlock (pkgs.lib.lists.drop 1 blocks);
7174
sourceRepos = pkgs.lib.lists.concatMap (x: x.sourceRepo) repoBlocks;
72-
in {
73-
otherText = pkgs.lib.strings.concatStringsSep "\n" (
75+
otherText = pkgs.writeText "cabal.project" (pkgs.lib.strings.concatStringsSep "\n" (
7476
initialText
75-
++ (builtins.map (x: x.otherText) repoBlocks));
77+
++ (builtins.map (x: x.otherText) repoBlocks)));
78+
in {
7679
inherit sourceRepos;
80+
makeFixedProjectFile = ''
81+
cp -f ${otherText} ./cabal.project
82+
chmod +w -R ./cabal.project
83+
echo "packages:" >> ./cabal.project
84+
mkdir -p ./.source-repository-packages
85+
'' +
86+
( pkgs.lib.strings.concatStrings (
87+
pkgs.lib.lists.zipListsWith (n: f: ''
88+
mkdir -p ./.source-repository-packages/${builtins.toString n}
89+
rsync -a --prune-empty-dirs \
90+
--include '*/' --include '*.cabal' --include 'package.yaml' \
91+
--exclude '*' \
92+
"${f}/" "./.source-repository-packages/${builtins.toString n}/"
93+
echo " ./.source-repository-packages/${builtins.toString n}" >> ./cabal.project
94+
'')
95+
(pkgs.lib.lists.range 0 ((builtins.length fixedProject.sourceRepos) - 1))
96+
sourceRepos
97+
)
98+
);
7799
};
78100

79-
fixedProject = replaceSoureRepos rawCabalProject;
101+
fixedProject =
102+
if rawCabalProject == null
103+
then {
104+
sourceRepos = [];
105+
makeFixedProjectFile = "";
106+
}
107+
else replaceSoureRepos rawCabalProject;
80108

81109
# Deal with source-repository-packages in a way that will work on
82110
# hydra build agents (as long as a sha256 is included).
@@ -89,24 +117,7 @@ let
89117
cd $tmp
90118
cp -r ${cabalFiles}/* .
91119
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-
) + ''
120+
${fixedProject.makeFixedProjectFile}
110121
# warning: this may not generate the proper cabal file.
111122
# hpack allows globbing, and turns that into module lists
112123
# without the source available (we cleaneSourceWith'd it),

0 commit comments

Comments
 (0)