cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.04k stars 303 forks source link

Adding commands to devenv #117

Open domenkozar opened 1 year ago

domenkozar commented 1 year ago

It would be interesting if there was a way to extend devenv commands. This would allow for some kind of concept of plugins.

{ ... }:
{
  subcommands.mysubcommand.exec = ''
    echo hello
  '';
}

And running it:

$ devenv mysubcommand
hello

Could be used with #103 for cli parsing.

karantan commented 1 year ago

I think this feature would completely eliminate the need for a Makefile.

thenonameguy commented 1 year ago

What is the benefit of the subcommand over the already existing script support?

It seems the only difference is whether the script is on the PATH vs. the subcommand is built-in the devenv script.

sayanarijit commented 1 year ago

I think I'd prefer it to be a global config in configuration.nix or home.nix.

I'd use it like devenv someplugin someargument.

E.g.

devenv bettersearch mypackage

sayanarijit commented 1 year ago

Inspiration: gh.

bobvanderlinden commented 1 year ago

I do like that something like up can become a subcommands this way. I also found that a setup command is often useful, which currently is a script.

I also like that this makes the configuration less dependent on the devenv executable. Being able to run some of these commands without devenv will allow better usage of them when using devenv in a flake.

That said, the distinction between subcommands and scripts is not clear. There probably needs to be docs on when to use one or the other.

@sayanarijit having them configurable globally will make the the environment not reproducible anymore. You'd have to communicate to any users which plugins they need to install/enable.

rickynils commented 1 year ago

I've been using this approach successfully for years, using infranix. infranix is using the same module-based approach as climod, but it is generating a Makefile behind the scenes while climod is just generating bash code.

Anyway, I just wanted to say that the "plugin experience" you get from this (especially when you're using the module system directly, I don't know if end users will do that in devenv) is really nice. I also gave a talk about this at NixCon London 2018.

If you haven't seen just, I recommend you look into it. It is a very nice alternative to Makefiles, and could either be useful behind the scenes in devenv, or even exposed directly to users.

Also, if you ever find yourself implementing auto completion, compleat is a very useful DSL for it.

domenkozar commented 1 month ago

See https://github.com/cachix/devenv/issues/1362