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

Conflicting definitions for flag overrides for cabal projects #254

Closed
hamishmack opened this issue Oct 11, 2019 · 4 comments
Closed

Conflicting definitions for flag overrides for cabal projects #254

hamishmack opened this issue Oct 11, 2019 · 4 comments

Comments

@hamishmack
Copy link
Collaborator

#253 allows flags to be specified in stack.yaml or cabal.project and haskell.nix will use the values specified as the default. This works well for stack.yaml where we add overrides only for the flags explicitly listed in the stack.yaml file.

For cabal.project we read the plan.json file that includes the values of all the flags (not just the ones that were explicitly set).

For instance if we try to override mypackage flags with:

mkCabalProjectPkgSet {
  plan-pkgs = plan.pkgs;
  modules = [ { packages.mypackage.flags = { flag1 = true; flag2 = false; }; } ];
}

We might get an error that says:

error: The option `packages.mypackage.flags.flag1' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'.

There are two quite good work arounds for this:

We can specify the flag in the cabal.project file instead with:

packages: .

package mypackage
  flags: +flag1 -flag2

Alternatively we can use stdenv.lib.mkOverride

mkCabalProjectPkgSet {
  plan-pkgs = plan.pkgs;
  modules = [ { packages.mypackage.flags = {
    flag1 = mkOverride 10 true;
    flag2 = mkOverride 10 false; }; } ];
}

A possible fix to this might be to patch the cabal to include which flags were explicitly set in cabal.project and which were not in the plan.json.

hamishmack added a commit that referenced this issue Oct 11, 2019
Project flags (from stack.yaml and plan.json) are exported in a modules attribute by stack-to-nix and plan-to-nix, but are not currently used. This change updates `mkStackPkgSet` and `mkCabalProjectPkgSet` so that the modules attribute is used (if present) and includes tests to check they are.

This commit makes `stdenv.lib.mkOverride` necessary for setting flags in `mkCabalProjectPkgSet` modules, however it also means that you can set them in `cabal.project` instead (see #254).
@michaelpj
Copy link
Collaborator

Can't we just use mkDefault on the options that we set? That's the usual idiom for setting options where you want any user setting to take precedence.

@hamishmack
Copy link
Collaborator Author

Oh, that would be nicer. Would it be surprising to anyone that when a flag is set in both cabal.project and modules that modules would quietly take precedence? I think it would be natural.

Should we change stack-to-nix to use mkDefault as well?

@michaelpj
Copy link
Collaborator

Yeah, I think we should do something like:

  • If this option might be set by a user and their setting should just take precedence, use mkDefault.
  • If this option could be set by a user but they had better know what they're doing otherwise things will behave unexpectedly, use a normal setting.

hamishmack added a commit to input-output-hk/nix-tools that referenced this issue Oct 12, 2019
hamishmack added a commit to input-output-hk/nix-tools that referenced this issue Oct 12, 2019
angerman pushed a commit to input-output-hk/nix-tools that referenced this issue Oct 13, 2019
@hamishmack
Copy link
Collaborator Author

This was fixed by #258

andreabedini pushed a commit to andreabedini/haskell.nix that referenced this issue Sep 14, 2022
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

No branches or pull requests

2 participants