cabal2nix icon indicating copy to clipboard operation
cabal2nix copied to clipboard

Improving an error message about "zero cabal files found"

Open jwiegley opened this issue 6 years ago • 9 comments

I've recently learned that when you run cabal2nix in a directory named foo, the only Cabal file cabal2nix will look for is foo.cabal. If it's not there, and even if there are other .cabal files, cabal2nix will report "Zero cabal files found, trying hpack...".

So, it's not that it couldn't find any cabal files, it just didn't find the one it was looking for. It should say, "Could not find foo.cabal, trying hpack...".

jwiegley avatar May 08 '18 18:05 jwiegley

Looking at https://github.com/NixOS/cabal2nix/blob/master/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs#L186 it seems like it does look for *.cabal and then fails, maybe something else was going on?

domenkozar avatar Jul 10 '18 18:07 domenkozar

Note I have changed how this logic works in https://github.com/NixOS/cabal2nix/pull/360/files

The message is now Found neither a .cabal file nor package.yaml. Exiting. but I guess the original complaint is still valid?

nh2 avatar Aug 22 '18 17:08 nh2

I think that this is still a thing but there's no error message indicating missing cabal file - it would be better if cabal2nix bailed out earlier if it can't find ${name}.cabal.

I'll open another issue due to frequent questions about this and try to fix this.

sorki avatar Dec 03 '20 16:12 sorki

Just a note for people who find this page after experiencing the same error as I did: I used git mv to rename the cabal file (the new name for the file matched the name of the parent directory), and received the error message Found neither a .cabal file nor package.yaml. Exiting.

The fix that worked for me was to commit the changes including the renamed .cabal file.

whittle avatar Nov 30 '21 22:11 whittle

I think in this issue a lot of nixpkgs / Nix related behavior is conflated with cabal2nix. cabal2nix indeed doesn't try to guess the cabal file name (it doesn't need to as Cabal only allows one .cabal file per directory).

The situation with the ifd wrappers in nixpkgs should've improved since https://github.com/NixOS/nixpkgs/pull/143186.

The fix that worked for me was to commit the changes including the renamed .cabal file.

This also must be related to some wrapping stuff, as cabal2nix does not know about git at all.

sternenseemann avatar Nov 30 '21 22:11 sternenseemann

Just a note for people who find this page after experiencing the same error as I did: I used git mv to rename the cabal file (the new name for the file matched the name of the parent directory), and received the error message Found neither a .cabal file nor package.yaml. Exiting.

The fix that worked for me was to commit the changes including the renamed .cabal file.

thank you! this helped me. I ended up just rm -rf .git , git initted again and added all the files.. then nix building worked for me

risingBirdSong avatar May 30 '22 21:05 risingBirdSong

Are you using flakes and callCabal2nix?

sternenseemann avatar May 30 '22 21:05 sternenseemann

Are you using flakes and callCabal2nix?

yes

risingBirdSong avatar Jun 01 '22 23:06 risingBirdSong

I think you and @whittle are running into how flakes treat local git repositories. I don't use flakes myself, so I'm not a hundred percent certain about the details, the only thing in terms of documentation I could come up with is this:

When git+file is used without specifying ref or rev, files are fetched directly from the local path as long as they have been added to the Git repository. If there are uncommitted changes, the reference is treated as dirty and a warning is printed. nix3-flake(1)

Now it's impossible for me to tell from the documentation what “treated as dirty” means precisely, but it seems to me that likely flakes does respect uncommited changes to files in the worktree (as long as the allow-dirty setting is active), but only if the files have been git added.

In any case, this is clearly a case where flakes behave in a confusing way and nothing cabal2nix can do anything about – it does not know about git (unless you give it an URL, but fetching that is also offloaded to nix-prefetch-git) at all and in the case of callCabal2nix it wouldn't even ever see a git repository.

sternenseemann avatar Jun 02 '22 09:06 sternenseemann