Skip to content

Commit a15aad8

Browse files
committed
Add context back to repo url strings
This should fixes a source of errors that look like this: ``` curl: (37) Couldn't open file /nix/store/7g8b1vz8nlai5zkjzfps25jl7fvdjk3s-source/package/contra-tracer-0.1.0.2.tar.gz ``` Reproducing this issue turned out to be difficult because if the `sha256` is in the nix cache there is no error. To reproduce the issue: * Remove the `addContext` call. * Build a project with `repository` in `cabal.project` with an `inputMap`. * Force the `src` derivation to rebuild. We can force the src derivation to rebuild by giving it invalid `sha256` (ignore the hash mismatch errors, if it has a hash then the download worked): ``` # sha256 = p.pkg-src-sha256; sha256 = __substring 0 (__stringLength p.pkg-src-sha256 - 6) p.pkg-src-sha256 + "000000"; ```
1 parent 4035dc4 commit a15aad8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/load-cabal-plan.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ let
55
plan-json = builtins.fromJSON (
66
builtins.unsafeDiscardStringContext (
77
builtins.readFile (callProjectResults.projectNix + "/plan.json")));
8+
# Function to add context back to the strings we get from `plan.json`
9+
addContext = s:
10+
let storeDirMatch = builtins.match ".*(${builtins.storeDir}/[^/]+).*" s;
11+
in if storeDirMatch == null
12+
then s
13+
else builtins.appendContext s { ${builtins.head storeDirMatch} = { path = true; }; };
814
# All the units in the plan indexed by unit ID.
915
by-id = pkgs.lib.listToAttrs (map (x: { name = x.id; value = x; }) plan-json.install-plan);
1016
# Find the names of all the pre-existing packages used by a list of dependencies
@@ -104,7 +110,7 @@ in {
104110
+ pkgs.lib.optionalString (p.pkg-src.source-repo.subdir != ".") "/${p.pkg-src.source-repo.subdir}";
105111
} // pkgs.lib.optionalAttrs (p.pkg-src.type or "" == "repo-tar") {
106112
src = pkgs.lib.mkDefault (pkgs.fetchurl {
107-
url = p.pkg-src.repo.uri + "${pkgs.lib.optionalString (!pkgs.lib.hasSuffix "/" p.pkg-src.repo.uri) "/"}package/${p.pkg-name}-${p.pkg-version}.tar.gz";
113+
url = addContext p.pkg-src.repo.uri + "${pkgs.lib.optionalString (!pkgs.lib.hasSuffix "/" p.pkg-src.repo.uri) "/"}package/${p.pkg-name}-${p.pkg-version}.tar.gz";
108114
sha256 = p.pkg-src-sha256;
109115
});
110116
} // pkgs.lib.optionalAttrs (cabal2nix ? package-description-override && p.pkg-version == cabal2nix.package.identifier.version) {

0 commit comments

Comments
 (0)