Open bobvanderlinden opened 1 year ago
I'll think about this one a bit more, since it needs to be carefully crafted.
The proposed solution is mostly adopted from the mkDerivation phases (unpack, build, configure, install). There it works alright. I'm interested in any other solutions.
In devshell there is a mechanism to declare dependencies between startup commands.
A config which defines greet
and check
startup steps, where greet
should be executed after check
could look like this:
{
devshell.startup = {
check = { text = "echo checking stuff..."; };
greet = {
deps = ["check"];
text = "echo hello there!";
};
};
}
See the option definition here and here
The setup commands (which are bash snippets) are ordered using textClosureMap function from nixpkgs.
startup
is of type attrsOf submodule
so arbitrarily named phases could be added
I'd be happy to port this to devenv
. @domenkozar I guess this would need to be added as an additional top-level option as we'd want enterShell
to remain as it is for backwards compatibility?
I'd say all the included module should define their enterShell
script in the above way, so that for example, one could ensure that ones custom startup command executes after files have been generated.
Additionally, we could add an enable
option (true
by default in most cases) to the startup
submodule to allow selectively disabling of different startup scripts. Then, for example, if the files
module added it's startup command via startup.files
, the use could decide if they wanted the files created when entering the shell or not, by togging startup.files.enable
.
Currently I'm running into limitations of scripts and enterShell when extending devenv with modules.
For instance, I'd like to add some 'assertions' to enterShell from a module. Assertions are runtime checks like:
~/.npmrc
have the authorization tokens?~/.m2/settings.xml
refer to the local repository that the project is presuming to use?/etc/hosts
contain the entry that the project presumes?I'd also like to automatically run
bundle
.I also want to show a welcome message explaining some of the standard commands for the project (general setup, db setup, run the application, run the tests).
The order of these actions is important. Assertions must be run first. Welcome message must come last.
When adding these to enterShell it'll be added in the order that the modules are loaded, which is quite error-prone. In addition, when the project devenv.nix defines enterShell, those lines will always come last.
When adding these to a (setup) script using
scripts.setup.exec
it'll not be possible because the type isstr
, which doesn't append automatically likelines
does.I'm thinking of some kind of phases:
which should result in
Is some form of this useful? Are there others ways of tackling the problem?