Is there a standard way to put opinionated devShell dependencies into a separate flake from required ones?

flake.nix lets you place dependencies in a dev shell:

{
  ...
  outputs = {
      ...
      devShells.default = pkgs.mkShell {
        packages = [
          pkgs.sometool
        ];
      };
    };
}

But there are often “dependencies” that don’t belong there (soft dependencies, we’ll call them). For instance, you wouldn’t add language servers there because different dev’s are likely to prefer different dev environments–so it’s not polite to enforce yours as a strict dependency.

Because of this, we leave it to each dev to configure that stuff, so maybe it ends up in ~/.config/nixpkgs/home.nix or some such place. The problem I’m trying to solve is that when somebody asks “Hey, how do you have your dev env configured?” sending them to my home.nix is too much info. They’ll find tools for a variety of projects in a variety of languages, plus remnants of failed experiments and other weird things.

I’d rather send them to something small and focused. For instance if it’s a python project, then I’d like to send them to a flake.nix that contains only the tools that I like to use for python development.

So my question is: Is there a recommended way to put “these are my favoried python tools” and “these are the tools for specifically this project” in separate flakes and still have them both be available in the devShell, while also keeping them separate from the system config?

I’ve found that I can create .envrc files (for use with direnv) like this:

# ~/src/somepythonproj/.envrc
source_env_if_exists ~/dev/python/.envrc
use flake

Which seems to work ok: it lets me have a separate flake for soft dependencies and yet still have everything together in one shell while I’m developing, and without mixing together configs for separate ecosystems. But I want to know if I’m reinventing a wheel before I continue with the reinventing.

Thanks.

3 Likes

Maybe have your favorite Python tools in one flake in a devShell, then in your project, have the default devShell just contain the necessary dependencies and have a second “comfort” devShell that merges them both using inputsFrom:

https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell

You’d still need to have your favorite Python tools flake as an input, but it’s only actually built if the “comfort” devShell is being used.

1 Like