add usage example

This commit is contained in:
Jörg Thalheim 2020-08-10 09:56:24 +01:00
parent 9e887c3201
commit d1bf45b1bf
No known key found for this signature in database
GPG key ID: 003F2096411B5F92

View file

@ -104,6 +104,47 @@ Then source the direnvrc from this repository in your own `.direnvrc`
source $HOME/nix-direnv/direnvrc
```
## Usage example
Either add `shell.nix` or a `default.nix` to the same directory:
``` nix
# save this as shell.nix
{ pkgs ? with import <nixpkgs> {}}:
pkgs.mkShell {
nativeBuildInputs = [ pkgs.hello ];
}
```
Then add the line `use nix` to your envrc:
```console
$ echo "use nix" >> .envrc
$ direnv allow
```
## Experimental flakes support
nix-direnv also comes with a flake alternative. The code is tested and works however
since future nix versions might change their api regarding this feature we cannot
guarantee stability after an nix upgrade.
``` nix
{
description = "A very basic flake";
# Provides abstraction to boiler-code when specifying multi-platform outputs.
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.hello ];
};
});
}
```
## Storing .direnv outside the project directory
A `.direnv` directory will be created in each `use_nix` project, which might