mirror of
https://gitlab.com/rensa-nix/devshell.git
synced 2025-12-11 22:00:08 +01:00
86 lines
1.4 KiB
Markdown
86 lines
1.4 KiB
Markdown
# Usage
|
|
|
|
## Basic Shell
|
|
|
|
The absolute minimum to get started:
|
|
|
|
```nix
|
|
let
|
|
# make sure to add
|
|
# inputs.devshell.url = "gitlab:rensa-nix/devshell?dir=lib";
|
|
# to your inputs
|
|
devshell = inputs.devshell.lib { inherit pkgs; };
|
|
in
|
|
devshell.mkShell {}
|
|
```
|
|
|
|
That's it. You've got yourself a shell. Not very exciting, but it works.
|
|
|
|
## Adding Packages
|
|
|
|
Want some tools? Throw them in:
|
|
|
|
```nix
|
|
devshell.mkShell {
|
|
packages = [ pkgs.hello pkgs.git pkgs.nodejs ];
|
|
}
|
|
```
|
|
|
|
## Environment Variables
|
|
|
|
Set some env vars (because who doesn't love those):
|
|
|
|
```nix
|
|
devshell.mkShell {
|
|
env = {
|
|
HELLO.value = "world";
|
|
};
|
|
}
|
|
```
|
|
|
|
## Shell Hooks
|
|
|
|
Run stuff when entering the shell:
|
|
|
|
```nix
|
|
devshell.mkShell {
|
|
enterShellCommands."hello".text = ''
|
|
echo "Welcome to the devshell!"
|
|
echo "Current directory: $PWD"
|
|
'';
|
|
}
|
|
```
|
|
|
|
## Putting It All Together
|
|
|
|
A more realistic example:
|
|
|
|
```nix
|
|
devshell.mkShell {
|
|
packages = [ pkgs.nodejs pkgs.yarn pkgs.git ];
|
|
|
|
env = {
|
|
NODE_ENV.value = "development";
|
|
API_URL.value = "http://localhost:3000";
|
|
};
|
|
|
|
enterShellCommands."enter".text = ''
|
|
echo "🚀 Development environment ready!"
|
|
node --version
|
|
'';
|
|
}
|
|
```
|
|
|
|
## Need More Features?
|
|
|
|
For additional functionality, import modules:
|
|
|
|
```nix
|
|
devshell.mkShell {
|
|
imports = [ some-module.devshellModule ];
|
|
# your config...
|
|
}
|
|
```
|
|
|
|
Check out [available modules](./integrations.md) for things like automatic file
|
|
generation, dev tools and more.
|