Skip to content

Commit 42b740a

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

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

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

Lines changed: 36 additions & 27 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;
@@ -61,6 +64,8 @@ let
6164
otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd;
6265
};
6366

67+
# Deal with source-repository-packages in a way that will work on
68+
# hydra build agents (as long as a sha256 is included).
6469
# Replace source-repository-package blocks that have a sha256 with
6570
# packages: block containing nix sotre paths of the fetched repos.
6671
replaceSoureRepos = projectFile:
@@ -69,44 +74,48 @@ let
6974
initialText = pkgs.lib.lists.take 1 blocks;
7075
repoBlocks = builtins.map parseBlock (pkgs.lib.lists.drop 1 blocks);
7176
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" (
7478
initialText
75-
++ (builtins.map (x: x.otherText) repoBlocks));
79+
++ (builtins.map (x: x.otherText) repoBlocks)));
80+
in {
7681
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+
);
77101
};
78102

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

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-
85111
plan = runCommand "plan-to-nix-pkgs" {
86112
nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ];
87113
} (''
88114
tmp=$(mktemp -d)
89115
cd $tmp
90116
cp -r ${cabalFiles}/* .
91117
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}
110119
# warning: this may not generate the proper cabal file.
111120
# hpack allows globbing, and turns that into module lists
112121
# without the source available (we cleaneSourceWith'd it),

test/cabal-source-repo/default.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ let
88
index-state = "2019-04-30T00:00:00Z";
99
# reuse the cabal-simple test project
1010
src = ./.;
11-
# Hydra currently has issues reading from files in the store
12-
cabalProject = builtins.readFile ./cabal.project;
1311
});
1412
};
1513
packages = pkgSet.config.hsPkgs;

test/call-cabal-project-to-nix/default.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ let
88
index-state = "2019-04-30T00:00:00Z";
99
# reuse the cabal-simple test project
1010
src = ../cabal-simple;
11-
# Hydra currently has issues reading from files in the store
12-
cabalProject = builtins.readFile ../cabal-simple/cabal.project;
1311
});
1412
};
1513
packages = pkgSet.config.hsPkgs;

0 commit comments

Comments
 (0)