From a15aad897c0fab17f7a632c60a69fb3a26a9cd24 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 16 Oct 2024 16:41:43 +1300 Subject: [PATCH 1/3] 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"; ``` --- lib/load-cabal-plan.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/load-cabal-plan.nix b/lib/load-cabal-plan.nix index adf3a6898d..09e85caada 100644 --- a/lib/load-cabal-plan.nix +++ b/lib/load-cabal-plan.nix @@ -5,6 +5,12 @@ let plan-json = builtins.fromJSON ( builtins.unsafeDiscardStringContext ( builtins.readFile (callProjectResults.projectNix + "/plan.json"))); + # Function to add context back to the strings we get from `plan.json` + addContext = s: + let storeDirMatch = builtins.match ".*(${builtins.storeDir}/[^/]+).*" s; + in if storeDirMatch == null + then s + else builtins.appendContext s { ${builtins.head storeDirMatch} = { path = true; }; }; # All the units in the plan indexed by unit ID. by-id = pkgs.lib.listToAttrs (map (x: { name = x.id; value = x; }) plan-json.install-plan); # Find the names of all the pre-existing packages used by a list of dependencies @@ -104,7 +110,7 @@ in { + pkgs.lib.optionalString (p.pkg-src.source-repo.subdir != ".") "/${p.pkg-src.source-repo.subdir}"; } // pkgs.lib.optionalAttrs (p.pkg-src.type or "" == "repo-tar") { src = pkgs.lib.mkDefault (pkgs.fetchurl { - 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"; + 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"; sha256 = p.pkg-src-sha256; }); } // pkgs.lib.optionalAttrs (cabal2nix ? package-description-override && p.pkg-version == cabal2nix.package.identifier.version) { From 6bdd99fa75bd774753895c70e3c82f7cc7837fc1 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 16 Oct 2024 17:04:43 +1300 Subject: [PATCH 2/3] Update lib/load-cabal-plan.nix Co-authored-by: Moritz Angermann --- lib/load-cabal-plan.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/load-cabal-plan.nix b/lib/load-cabal-plan.nix index 09e85caada..2c9ac23867 100644 --- a/lib/load-cabal-plan.nix +++ b/lib/load-cabal-plan.nix @@ -110,6 +110,8 @@ in { + pkgs.lib.optionalString (p.pkg-src.source-repo.subdir != ".") "/${p.pkg-src.source-repo.subdir}"; } // pkgs.lib.optionalAttrs (p.pkg-src.type or "" == "repo-tar") { src = pkgs.lib.mkDefault (pkgs.fetchurl { + # repo.uri might look like file:/nix/store/xxx; using addContext, we let nix know about the dependency on + # /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). 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"; sha256 = p.pkg-src-sha256; }); From 996b99b8007f3aa1536354f6293508703b624126 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 16 Oct 2024 17:16:18 +1300 Subject: [PATCH 3/3] Bump test `repository` blocks --- test/cabal.project.local | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cabal.project.local b/test/cabal.project.local index db3a1f6521..e3bba2b48f 100644 --- a/test/cabal.project.local +++ b/test/cabal.project.local @@ -24,14 +24,14 @@ repository head.hackage.ghc.haskell.org f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89 26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329 7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d - --sha256: sha256-VFRuIfs3k6nyLVvT445wFRDy+bpcy1LVmLCMg1Oo/uE= + --sha256: sha256-Z6cqRAlbV1WNbK4fKdcWHQcLA8CGpzfnTOd8QxcOy+c= repository ghcjs-overlay - url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/01ecad22c0a72e3c5a49262357cf0b062892d87f + url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/56cd424e8529e7a1fc29c6126abdc66f09467306 secure: True root-keys: key-threshold: 0 - --sha256: sha256-BjyXYh6oS4wE1iHlY/7as7vkmjxFOXzK6nOYzbzjQrM= + --sha256: sha256-nU0/HKy4Om1GohCcU+gUWCDPgyclYdFzAgzfXe0tgf0= if os(ghcjs) extra-packages: ghci