numtide / devshell

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

Extra modules from other flakes #223

Open bobvanderlinden opened 1 year ago

bobvanderlinden commented 1 year ago

Is your feature request related to a problem? Please describe.

Currently it is possible to add modules from the extra/ directory using:

imports = ["locale"]

which corresponds to extra/locale.nix.

However, if I'd like to extend devshell with external flakes it seems not possible or not documented. Other than forking devshell and basing everything on that.

Also using Nix (in flakes) it is unclear how to refer to these module files.

Describe the solution you'd like

Would it be eventually possible to do something like:

imports = ["github:me/myflake#mydevshelmodule"]

It would be cool if it worked the same way as homeManagerModules and nixosModules in flakes:

{
  inputs = { ... };
  ouputs = ...
    devshellModules = {
      locale = import ./extra/locale.nix;
    };
  };
}

That way they are easily referred to from Nix in other flakes.

Describe alternatives you've considered

  1. Forking the project and adding modules to extra/ in there :shrug:
  2. Leaving my custom modules non-reusable. Adding them all to my personal devshell repository where I can do imports = [ ./mymodule.nix ] in Nix.
hugosenari commented 1 year ago

Example:

{
  description = "virtual environments";

  inputs.devshell.url    = "github:numtide/devshell";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.dsf.url         = "github:cruel-intentions/devshell-files";
  inputs.gha.url         = "github:cruel-intentions/gh-actions";

  outputs = { self, flake-utils, devshell, nixpkgs, dsf, gha }:
    flake-utils.lib.eachDefaultSystem (system: {
      devShell = let pkgs = import nixpkgs {  inherit system;   overlays = [ devshell.overlay ];   };   in
        pkgs.devshell.mkShell {
          imports = [
            "${dsf}/modules/files.nix" # create text files for you
            "${dsf}/modules/yaml.nix" # use files to write yaml files from nix
            "${gha}/gha/gh-actions.nix" # use yaml to create .github/workflows/gh-pages.yaml
            # ... :-)
            (pkgs.devshell.importTOML ./devshell.toml)
          ];
        };
    });
}

There is an external lib that help

{
  description = "Dev Environment";

  inputs.nixpkgs.url  = "github:nixos/nixpkgs/22.05";
  inputs.dsf.url      = "github:cruel-intentions/devshell-files";
  inputs.dsf.inputs.nixpkgs.follows = "nixpkgs";
  inputs.gha.url         = "github:cruel-intentions/gh-actions";

  outputs = inputs: inputs.dsf.lib.shell inputs [
    "hello"        # import nix package
    "${inputs.gha}/gh-actions.nix"
    ./project.nix  # import nix module
    (inputs.dsf.lib.importTOML ./devshell.toml)
  ];
}

See also #153

hugosenari commented 1 year ago

Looking at old issues, there is also #136