cabal2nix
cabal2nix copied to clipboard
Improving an error message about "zero cabal files found"
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..."
.
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?
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?
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.
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.
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.
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 messageFound 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
Are you using flakes and callCabal2nix
?
Are you using flakes and
callCabal2nix
?
yes
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 add
ed.
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.