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

Extra modules from other flakes #223

Open
bobvanderlinden opened this issue Sep 21, 2022 · 2 comments
Open

Extra modules from other flakes #223

bobvanderlinden opened this issue Sep 21, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@bobvanderlinden
Copy link

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 🤷
  2. Leaving my custom modules non-reusable. Adding them all to my personal devshell repository where I can do imports = [ ./mymodule.nix ] in Nix.
@bobvanderlinden bobvanderlinden added the enhancement New feature or request label Sep 21, 2022
@hugosenari
Copy link

hugosenari commented Nov 26, 2022

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
Copy link

Looking at old issues, there is also #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants