Skip to content

Commit f78e186

Browse files
hamishmackangerman
authored andcommitted
Add context back to repo url strings (input-output-hk#2261)
* 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 = __substring 0 (__stringLength p.pkg-src-sha256 - 6) p.pkg-src-sha256 + "000000"; ``` * Update lib/load-cabal-plan.nix Co-authored-by: Moritz Angermann <[email protected]> * Bump test `repository` blocks --------- Co-authored-by: Moritz Angermann <[email protected]>
1 parent 706698d commit f78e186

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

lib/load-cabal-plan.nix

Lines changed: 15 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
@@ -100,7 +106,15 @@ in {
100106
} // pkgs.lib.optionalAttrs (p.pkg-src.type or "" == "source-repo") {
101107
# Replace the source repository packages with versions created when
102108
# parsing the `cabal.project` file.
103-
src = pkgs.lib.lists.elemAt callProjectResults.sourceRepos (pkgs.lib.strings.toInt p.pkg-src.source-repo.location) + "/${p.pkg-src.source-repo.subdir}";
109+
src = pkgs.lib.lists.elemAt callProjectResults.sourceRepos (pkgs.lib.strings.toInt p.pkg-src.source-repo.location)
110+
+ pkgs.lib.optionalString (p.pkg-src.source-repo.subdir != ".") "/${p.pkg-src.source-repo.subdir}";
111+
} // pkgs.lib.optionalAttrs (p.pkg-src.type or "" == "repo-tar") {
112+
src = pkgs.lib.mkDefault (pkgs.fetchurl {
113+
# repo.uri might look like file:/nix/store/xxx; using addContext, we let nix know about the dependency on
114+
# /nix/store/xxx. Otherwise we can run into the situation where nix won't be able to access the dependencies needed to build. (e.g. the /nix/store/xxx path).
115+
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";
116+
sha256 = p.pkg-src-sha256;
117+
});
104118
} // pkgs.lib.optionalAttrs (cabal2nix ? package-description-override && p.pkg-version == cabal2nix.package.identifier.version) {
105119
# Use the `.cabal` file from the `Cabal2Nix` if it for the matching
106120
# version of the package (the one in the plan).

test/cabal.project.local

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
if impl(ghc>=9.8)
1+
if impl(ghc>=9.10.1)
22
-- allow newer packages, that are bound to be newer due to
33
-- being shipped with a newer compiler. If you extend this
44
-- be very careful to only extend it for absolutely necessary packages
55
-- otherwise we risk running into broken build-plans down the line.
66
allow-newer: *:base, *:template-haskell, *:bytestring, *:text, *:ghc-prim, *:deepseq, *:Cabal
7-
if impl(ghc > 9.9)
8-
allow-newer: *:containers
7+
if impl(ghc > 9.11)
8+
allow-newer: *:containers, *:time
9+
constraints: base-compat >=0.14.0, aeson >=2.2.1.0
10+
-- From https://ghc.gitlab.haskell.org/head.hackage/cabal.constraints
11+
constraints: extra ==1.7.14
912

1013
-- This prevents hsc2hs from causing old versions of packages from being added to plan.json
1114
allow-newer: hsc2hs:*
1215

16+
if impl(ghc >=9.10.1)
17+
extra-packages: process
18+
1319
repository head.hackage.ghc.haskell.org
1420
url: https://ghc.gitlab.haskell.org/head.hackage/
1521
secure: True
@@ -18,23 +24,27 @@ repository head.hackage.ghc.haskell.org
1824
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
1925
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
2026
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
21-
--sha256: sha256-h/vbKTUdGVdkt2ogJer2d+gRuHkayiblQ7oFRqpj14c=
27+
--sha256: sha256-Z6cqRAlbV1WNbK4fKdcWHQcLA8CGpzfnTOd8QxcOy+c=
2228

2329
repository ghcjs-overlay
24-
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/91f4ce9bea0e7f739b7495647c3f72a308ed1c6f
30+
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/56cd424e8529e7a1fc29c6126abdc66f09467306
2531
secure: True
2632
root-keys:
2733
key-threshold: 0
28-
--sha256: sha256-mZT7c+xR5cUTjLdCqOxpprjYL3kr/+9rmumtXvWAQlM=
34+
--sha256: sha256-nU0/HKy4Om1GohCcU+gUWCDPgyclYdFzAgzfXe0tgf0=
35+
36+
if os(ghcjs)
37+
extra-packages: ghci
38+
constraints: ghci installed
2939

30-
if !impl(ghc>=9.8) && !os(ghcjs)
40+
if !impl(ghc>=9.11) && !os(ghcjs)
3141
active-repositories: hackage.haskell.org
3242

33-
if impl(ghc>=9.8) && !os(ghcjs)
34-
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override
43+
if impl(ghc>=9.11) && !os(ghcjs)
44+
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org
3545

36-
if !impl(ghc>=9.8) && os(ghcjs)
46+
if !impl(ghc>=9.11) && os(ghcjs)
3747
active-repositories: hackage.haskell.org, ghcjs-overlay:override
3848

39-
if impl(ghc>=9.8) && os(ghcjs)
40-
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override, ghcjs-overlay:override
49+
if impl(ghc>=9.11) && os(ghcjs)
50+
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org, ghcjs-overlay:override

0 commit comments

Comments
 (0)