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

cabal file in project root is not detected #49

Closed
roberth opened this issue Dec 1, 2022 · 5 comments · Fixed by #75
Closed

cabal file in project root is not detected #49

roberth opened this issue Dec 1, 2022 · 5 comments · Fixed by #75
Labels
DX Developer Experience

Comments

@roberth
Copy link
Collaborator

roberth commented Dec 1, 2022

Encountered this in https://github.com/hercules-ci/arion

haskellPathsInDir only scans subdirectories: "${x}/${x}.cabal"

We should also try ${x}.cabal (regardless of parent directory name, which is impure; store path or lazy tree).

@srid srid added the DX Developer Experience label Jan 31, 2023
@srid
Copy link
Owner

srid commented Feb 9, 2023

[Trying to describe this issue in detail]

The haskellProjects.foo.packages option currently uses the haskellPathsInDir function from nipxkgs to determine its default value:

default =
lib.mapAttrs
(_: value: { root = value; })
(lib.filesystem.haskellPathsInDir self);

This works for projects with multiple local packages (like https://github.com/srid/haskell-multi-nix) where cabal files live at */*.cabal. However, we want the default value to also work for single-package haskell projects (like https://github.com/srid/haskell-template), such that the three lines here can be removed and the flake still works, because the default will recognize it.

@roberth
Copy link
Collaborator Author

roberth commented Feb 9, 2023

haskellPathsInDir didn't really work for hercules-ci-agent either, because that project has an integration test driver in a sub-subdirectory; depth 2, which, like depth 0, isn't depth 1.

https://github.com/hercules-ci/hercules-ci-agent/blob/40d5243b4ea4ecedbf021b50272dc0937a2ad4df/flake.nix#L293-L296

So my workaround was to use lib.mkOptionDefault, to extend the default, which is quite a fragile solution that I think most users won't be able to figure out, and shouldn't have to.

The package was listed in a cabal.project file, so if we could support that, I think we could have a fairly robust solution without having to scan deeply, which could be slow in monorepos.

The algorithm would then be roughly: check for cabal.project or stack.yaml or *.cabal in the root and use that to set the packages option; if not present, require the user to set that option (or some helper option that sets it, for instance an option that specifies the location of a cabal.project file).
This change breaks projects that don't have a cabal.project and rely on the */*.cabal behavior that we have now. They'll be in the same spot that new users are who haven't really configured their haskellProjects.x yet: an empty packages, which we can handle by presenting an error message that explains which options can be used to set packages.

@srid
Copy link
Owner

srid commented Feb 9, 2023

The algorithm would then be roughly: check for cabal.project or stack.yaml or *.cabal in the root and use that to set the packages option; if not present, require the user to set that option (or some helper option that sets it, for instance an option that specifies the location of a cabal.project file).

This sounds good to me.

  • Is there a cabal.project parser for Nix already?
  • For now, I think, we could just make the default recognize *.cabal in addition to */*.cabal before getting to implementing this idea (unless the parser is already available?), as it would help Expose two templates: default and example #69

@roberth
Copy link
Collaborator Author

roberth commented Feb 9, 2023

Haskell.nix has one, but I don't know how easily reused it is. Maybe the relevant paths can be found without much effort, I don't know.
Dream2nix works with different files it seems. Maybe those contain all the needed info, but I don't think we should require them.

@roberth
Copy link
Collaborator Author

roberth commented Feb 9, 2023

  • For now, I think, we could just make the default recognize *.cabal in addition to */*.cabal before getting to implementing this idea

Yeah, one step at a time. We want to support this case anyway, regardless of cabal.project plans.

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

Successfully merging a pull request may close this issue.

2 participants