numtide / devshell

Per project developer environments
https://numtide.github.io/devshell/
MIT License
1.23k stars 88 forks source link

Unwanted assertion "cannot be set to both the `name` and the `command` attributes" #312

Closed zmrocze closed 4 months ago

zmrocze commented 4 months ago

Hey,

is this assertion really correct or needed?

How to reproduce

Because I have such a case:

devshells.default = {
  devshell = {
    name = "Tidal + haskell shell";
    packagesFrom = [
      config.devShells.haskell
    ];
  };
  commands = [
    {
      category = "Tidal";
      name = "ghci";
      help = "Start ghci";
      command = "ghci";
    }
  ];
};

First this results in error:

       error: [[commands]]: ghci cannot be set to both the `name` and the `command` attributes. Did you mean to use the `package` attribute?

But if I did name = "my-ghci" it would work, because the command ghci is provided by the included packagesFrom = [ config.devShells.haskell ]. So the assertion really bites me.

Alternatives tried

I've tried combinations:

package = "ghci"

doesn't work because package "ghci" not found. I don't have direct access to the package, because I don't have a reference to it, it's included in the haskell shell created by a library function.

Specifying only of command/name fails with either:

       error: [[commands]]: some command is missing both a `name` or `package` attribute.

or

       error: [[commands]]: ghci expected either a command or package attribute.

Finally, naming the command differently works like described above.

Why do I care?

because id like the command to appear in the nice menu.

Summary and realization

OK. I realized the problem. In my case the ghci command would overwrite the ghci command that's already in scope. Ill close this issue as dumb. Open a new feature request for displaying in menu commands originating from packagesFrom (this ties to issue #311). Refer to here to show how naive solution fails.