1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-05 16:36:56 +00:00
flake-parts/examples/shell-environments/README.md

56 lines
1.5 KiB
Markdown
Raw Normal View History

2023-06-15 22:13:02 +02:00
# shell-environment
2023-06-23 19:31:43 +02:00
> **Warning**
> If you copy the flake.nix remember to `git add [-N|--intent-to-add] flake.nix`, otherwise it won't work
2023-06-15 22:13:02 +02:00
This example shows how to create a shell environment which
includes a diverse set of tools:
```sh
2023-06-15 22:13:02 +02:00
terraform
wget
bat
2023-06-26 09:14:11 +02:00
nixpkgs-fmt
2023-06-15 22:13:02 +02:00
```
2023-06-26 09:14:11 +02:00
You can search for more packages in [nix packages](https://search.nixos.org/packages)
2023-06-15 22:13:02 +02:00
## Usage
The [`devShells` option](https://flake.parts/options/flake-parts.html#opt-perSystem.devShells) is used by the following command:
```sh
nix develop
```
You can have as many shells as you want, in this [flake.nix](./flake.nix), you also have
`another_env` which includes `curl`. To open it:
```sh
nix develop .#another_env
```
## Troubleshooting
2023-06-26 09:14:11 +02:00
### I get bash instead of my shell
`nix develop` was designed for Nixpkgs stdenv, which uses bash, so that you can troubleshoot a Nix build with it. If you use a different shell, you'll want to get just the variables instead.
There are 3 possible solutions:
First, using [direnv](https://direnv.net/) to manage your dev environments. See [direnv-guide](https://haskell.flake.page/direnv). This is the recommended approach.
Second is a simple-unreliable hack, which is adding a `shellHook` to `devShells`
```nix
devShells.default = pkgs.mkShell {
2023-06-26 09:14:11 +02:00
shellHook = ''
exec $SHELL
2023-06-26 09:14:11 +02:00
'';
};
```
You might get a lot different issues, use it at your own risk.
2023-06-26 09:14:11 +02:00
Lastly, there's `nix print-dev-env` which returns the variables - in case you're feeling adventurous, because this is far from a complete solution. See `nix print-dev-env --help`.