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

Add ignorePackageYaml support to cabalProject #2094

Merged
merged 2 commits into from
Oct 22, 2023

Conversation

mklca
Copy link
Contributor

@mklca mklca commented Oct 18, 2023

This PR adds a command line flag to plan-to-nix that allows any package.yaml files to be completely ignored.

This implements a workaround for #1923 which is otherwise needed to support hpack local-style defaults. Even if the user explicitly generates the associated foo.cabal files and commits them to the repo (or arranges for Nixago to do that 😏 on their behalf) the presence of the package.yaml files in the source causes plan-to-nix (regardless of the project's supportHpack setting) to read the package.yaml rather than the user generated .cabal file(s) and so consequently the absence of the defaults specified in that package.yaml in the cleaned sources causes plan-to-nix to fail.

To avoid changing the behaviour of projects which already set supportHpack to false but inadvertently rely on plan-to-nix loading the package.yaml files, it seemed wiser to create a new project option entirely.

Comment on lines 142 to 145
ignorePackageYaml = mkOption {
type = bool;
default = false;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied from modules/stack-project.nix. Perhaps these should be merged?

@hamishmack
Copy link
Collaborator

To avoid changing the behaviour of projects which already set supportHpack to false but inadvertently rely on plan-to-nix loading the package.yaml files, it seemed wiser to create a new project option entirely.

I think this only matters if the .cabal and package.yaml differ.

I imagine that can happen when:

  • Someone forgets to update the .cabal file after modifying package.yaml.
  • Someone updates .cabal file unaware there is a package.yaml.
  • Someone updates the .cabal file to test something using a tool that ignores the package.yaml (then forgets to update package.yaml).

Perhaps when the builder runs hpack it should verify that the .cabal file (if it exists) is not modified.

The builder can only do that test if knows to run hpack though, so I think we still need two flags.

@mklca
Copy link
Contributor Author

mklca commented Oct 19, 2023

I think this only matters if the .cabal and package.yaml differ.

I think so as well, but it's an invariant that's almost certainly broken by a non-empty subset of Haskell packages (at least, by Murphy's law of engineering pessimestimation) so it's best to make the new feature that breaks those packages an explicit downstream opt-in rather than impose an explicit downstream opt-out.

I imagine that can happen when…
…Someone forgets to update the .cabal file after modifying package.yaml.

Personally, I think the best way to avoid this is to set up a devshell hook to run hpack when it sees the cabal file is out of date and add it to the git index to keep it from getting out of date. (Getting a list of source directories to monitor for creation/deletion and hooking to an fsnotify service would be a nice project…)

…Someone updates .cabal file unaware there is a package.yaml.

…Someone updates the .cabal file to test something using a tool that ignores the package.yaml (then forgets to update package.yaml).

And then those modifications get checked in, and then one day somebody adds a source file or something and re-reruns hpack and the modifications are clobbered. This is probably a confusing situation for a newcomer to encounter since the trace of the modifications are hidden in the diff of a file that they entrusted a tool to modify.

Perhaps when the builder runs hpack it should verify that the .cabal file (if it exists) is not modified.

Yes, that's a good idea. Does it need to go in this feature?

The builder can only do that test if knows to run hpack though, so I think we still need two flags.

Settled. Should we consolidate the module option somewhere now that it's shared between Stack and Cabal projects?

@mklca
Copy link
Contributor Author

mklca commented Oct 21, 2023

Moved ignorePackageYaml to project-common.nix which seems like a logical place.

The development documentation in docs/dev/nix-tools-pin.md seems stale. Neither the flake input nor the materialized nix-tools seem to exist, but I'm running scripts/check-materializations anyways and will push the results in a little bit.

@hamishmack hamishmack merged commit 58dd973 into input-output-hk:master Oct 22, 2023
30 checks passed
@hamishmack
Copy link
Collaborator

Thanks!

@hamishmack
Copy link
Collaborator

Now this is merged, I think we will need to bump the static nix-tools pin https://github.com/input-output-hk/haskell.nix/blob/master/overlays/default.nix#L37-L38 (used on x86_64-linux systems).

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

Successfully merging this pull request may close these issues.

2 participants