Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haskellSrc2Nix: Use wrapped cabal2nix #108248

Closed
wants to merge 1 commit into from
Closed

Conversation

bgamari
Copy link
Contributor

@bgamari bgamari commented Jan 2, 2021

Motivation for this change

Previously haskellSrc2Nix would inexplicably use the unwrapped cabal2nix
derivation, meaning that nix-prefetch-url wouldn't be present in PATH.

Fixes #108246.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Previously haskellSrc2Nix would inexplicably use the unwrapped cabal2nix
derivation, meaning that nix-prefetch-url wouldn't be present in PATH.
@bgamari
Copy link
Contributor Author

bgamari commented Jan 2, 2021

Cc @peti

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff LGTM

@cdepillabout
Copy link
Member

I mentioned in #108246 (comment), but I don't think this is the correct solution. We explicitly switched to using cabal2nix-unwrapped in #81125.

However, I don't know why @bgamari would be seeing this error.

@madjar
Copy link
Member

madjar commented Jan 3, 2021

I agree with @cdepillabout that it's surprising that cabal2nix calls nix-prefetch-url, and that this solution is not great, since we loose all the benefits of cabal2nix-unwrapped.

I'm wondering what the nix-prefetch-url call is exactly, if it is legitimate, and if so, if it is possible to make another wrapper that has just nix-prefetch-url without the many other prefetch scripts.

@bgamari
Copy link
Contributor Author

bgamari commented Jan 3, 2021

It's unfortunately quite hard to know why cabal2nix falls back to using nix-prefetch-url. However, I can say with pretty good confidence that the relevant logic is https://github.com/NixOS/cabal2nix/blob/88b8edb59ad0076f140e9948f233a43d6dfb842b/src/Distribution/Nixpkgs/Fetch.hs#L103.

That is, the process call at the end of fetchLocal fails for some reason, causing us to fall through to localArchive, which calls nix-prefetch-url.

@cdepillabout
Copy link
Member

@bgamari Thanks for looking into this.

If anyone is willing to debug the process call in fetchLocal, I'd be really interested in what is exactly failing here.

@peti
Copy link
Member

peti commented Jan 22, 2021

It's unfortunately quite hard to know why cabal2nix falls back to using nix-prefetch-url.

cabal2nix uses that external command to download the tarball for some Hackage package in case it needs to determine the SHA512 hash of that tarball to put into the expression. These days, that should no longer be necessary because the cabal-install database contains all that information, so if you've run cabal update at some point, then the necessary hash is known locally already.

There might be other occasions where this command is called, but if I remember correctly then all of those occasions have to do with people trying to generate build instructions for remote git and/or darcs repositories. The code that implements those features is quite complicated, unfortunately, so no-one knows for sure what is going on. :-/

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/hakyll-nix-starter-template/9111/3

@stale
Copy link

stale bot commented Aug 5, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 5, 2021
@cdepillabout
Copy link
Member

@sternenseemann If I remember correctly, we were thinking that this error was originally caused by cabal2nix not correctly showing errors. For instance, not being able to find a .cabal file.

I think recently we got a PR to cabal2nix that made it show more errors (instead of falling back to looking for nix-prefetch-url).

This can probably be closed?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 6, 2021
@sternenseemann
Copy link
Member

This issue should be fixed with cabal2nix 2.18.0 indeed (NixOS/cabal2nix#489). To be precise it was a mistake in the fetching logic where the file “fetcher” would signal it was not applicable to the given URL/path instead of failing because it was able to access the path, but missing the cabal file.

Now the failure looks like this:

nix-repl> :b haskellPackages.haskellSrc2nix { name = "foo"; src = ./.; }
builder for '/nix/store/nlld1psymr14dwldlv2dib8fc7ds1qri-cabal2nix-foo.drv' failed with exit code 1; last 2 log lines:
  installing
  cabal2nix: user error (*** Found neither a .cabal file nor package.yaml. Exiting.)

@cdepillabout
Copy link
Member

Okay great, I'll go ahead and close this PR then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

callCabal2nix is broken on nixos-20.09
7 participants