Skip to content

Commit fd95990

Browse files
committed
Fix source-repository-package string context
1 parent 92de6c6 commit fd95990

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/cabal-project-parser.nix

+8-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ let
140140
else null);
141141
in rec {
142142
# This is `some-name` from the `repository some-name` line in the `cabal.project` file.
143-
name = __head lines;
143+
name = builtins.unsafeDiscardStringContext (__head lines);
144+
addContext = s:
145+
let storeDirMatch = builtins.match ".*(${builtins.storeDir}/[^/]+).*" s;
146+
in if storeDirMatch == null
147+
then s
148+
else builtins.appendContext s { ${builtins.head storeDirMatch} = { path = true; }; };
144149
# The $HOME/.cabal/packages/${name} after running `cabal v2-update` to download the repository
145150
repoContents = if inputMap ? ${attrs.url}
146151
# If there is an input use it to make `file:` url and create a suitable `.cabal/packages/${name}` directory
@@ -174,7 +179,7 @@ let
174179
mkdir -p $HOME/.cabal/packages/${name}
175180
cat <<EOF > $HOME/.cabal/config
176181
repository ${name}
177-
url: ${attrs.url}
182+
url: ${addContext attrs.url}
178183
${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
179184
${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"}
180185
${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"}
@@ -195,12 +200,7 @@ let
195200
hackage-to-nix $out ${repoContents}/01-index.tar ${attrs.url}
196201
'');
197202
# Directory to `lndir` when constructing a suitable $HOME/.cabal dir
198-
repo = {
199-
# Strings used as attrset keys can't have contet. This can cause problems if the cabal.project file has antiquoted strings
200-
# in it. Discarding the context here works, and because 'name' is used elsewhere, we don't actually lose the string content,
201-
# which can matter!
202-
${builtins.unsafeDiscardStringContext name} = repoContents;
203-
};
203+
repo.${name} = repoContents;
204204
};
205205

206206
parseRepositories = evalPackages: cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: projectFile:

0 commit comments

Comments
 (0)