Skip to content

Commit f986076

Browse files
authored
Fix string contexts in cabal project parser (#2179)
* Fix cabal pkg-config performance issue The dummy version of `pkg-config` we provide to cabal-install-solver so that it can make an appropriate plan includes an extra blank line at the end of it's output. In more recent versions of cabal-install-solver the following change has been made: haskell/cabal@0b34b4e This change now filters the `null` value from the list of package names. Then when the versions are looked up the output is not the expected length (because there is also a blank line at the end of the version list). This change updates the dummy pkg-config script so that it does not include the extra blank lines at the end of the output. * Fix string contexts in cabal project parser When both `repository` and `source-repository-packages` are included in a `cabal.project` (including `cabalProjectLocal`), the context needed for the `repository` is lost in the cabal project parser. This means nix store path is not included in the dependencies of the plan-nix derivation and it fails with an error like this: ``` /nix/store/x-source/root.json:openBinaryFile: does not exist (No such file or directory) ``` This fix makes sure the context is correct by looking for /nix/store strings in the repository url and appending them to the context.
1 parent 433a6c9 commit f986076

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/cabal-project-parser.nix

+9-8
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ let
138138
if sha256map != null
139139
then sha256map.${attrs.url} or null
140140
else null);
141+
# Find store directory strings and include them in the string context
142+
addContext = s:
143+
let storeDirMatch = builtins.match ".*(${builtins.storeDir}/[^/]+).*" s;
144+
in if storeDirMatch == null
145+
then s
146+
else builtins.appendContext s { ${builtins.head storeDirMatch} = { path = true; }; };
141147
in rec {
142148
# This is `some-name` from the `repository some-name` line in the `cabal.project` file.
143-
name = __head lines;
149+
name = builtins.unsafeDiscardStringContext (__head lines);
144150
# The $HOME/.cabal/packages/${name} after running `cabal v2-update` to download the repository
145151
repoContents = if inputMap ? ${attrs.url}
146152
# If there is an input use it to make `file:` url and create a suitable `.cabal/packages/${name}` directory
@@ -174,7 +180,7 @@ let
174180
mkdir -p $HOME/.cabal/packages/${name}
175181
cat <<EOF > $HOME/.cabal/config
176182
repository ${name}
177-
url: ${attrs.url}
183+
url: ${addContext attrs.url}
178184
${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
179185
${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"}
180186
${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"}
@@ -195,12 +201,7 @@ let
195201
hackage-to-nix $out ${repoContents}/01-index.tar ${attrs.url}
196202
'');
197203
# 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-
};
204+
repo.${name} = repoContents;
204205
};
205206

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

0 commit comments

Comments
 (0)