numtide / devshell

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

How to combine shells #311

Open zmrocze opened 6 months ago

zmrocze commented 6 months ago

Hey,

how would i go about combining shells? I tried the below but it doesn't work, why? Should I use modules?

For example I'd like to do:

devshells = {
  default = {
    devshell = {
      name = "My main shell";
      packagesFrom = [
        config.devShells.haskell
        config.devShells.utils
      ];
    };
  };
  utils = {
    devshell.name = "My subproject shell";
    commands = [
      {
        name = "my-util";
        command = "${pkgs.utils}/bin/my-util";
      }
    ];
  };
}    

defining an utils shell with the devshell module and combining it with a classical derivation based shell config.devShells.haskell that for example is created by some library code and I don't define it by myself. Or combine two or more shells of whatever flavor together, best getting information about conflicts.

In the example above, the resulting default shell indeed has all the commands coming from the haskell shell, but the my-util commad is missing from it. Why?

Given that devshells use module system, it's possible to share devshells by sharing modules. BUT I would like to understand why the above doesn't include my-utils inside shell? Together with #310 where I ask about the packages argument.

zmrocze commented 6 months ago

PS: Ah, also, with traditional devShells I can use mergeShells and merge not only inputs but also shellHooks.

It would be cool to have a matching solution with devshells, so that it's matter of setting a single option instead of the two:

packagesFrom = [other-shell]
startup.sth = other-shell.shellHook;

What do you guys think?

zmrocze commented 6 months ago

PS: Merging by module import is not that straightforward, because on options like name there's always going to be conflicts.

So: how to combine shells?