mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
Merge pull request #13 from nix-community/direnv-layout-dir
Improve documentation.
This commit is contained in:
commit
063d43483e
2 changed files with 23 additions and 8 deletions
18
README.md
18
README.md
|
|
@ -30,13 +30,29 @@ keep-derivations = true
|
|||
keep-outputs = true
|
||||
```
|
||||
|
||||
## Storing .direnv outside the project directory
|
||||
|
||||
`.direnv` might interact badly with backups (i.e. Dropbox) or IDEs.
|
||||
Therefore it's possible to override in `$HOME/.config/direnv/direnvrc` or
|
||||
in own project's `.envrc` a variable called `$direnv_layout_dir`.
|
||||
The following example will create a unique directory name per project
|
||||
in `$HOME/.cache/direnv/layouts/`:
|
||||
|
||||
|
||||
```bash
|
||||
# $HOME/.config/direnv/direnvrc
|
||||
: ${XDG_CACHE_HOME:=$HOME/.cache}
|
||||
pwd_hash=$(echo -n $PWD | shasum | cut -d ' ' -f 1)
|
||||
direnv_layout_dir=$XDG_CACHE_HOME/direnv/layouts/$pwd_hash
|
||||
```
|
||||
|
||||
## Known Bugs
|
||||
|
||||
At the moment nix-direnv depends on gnugrep and a modern bash version.
|
||||
This might lead to [problems](https://github.com/nix-community/nix-direnv/issues/3) on macOS.
|
||||
As a work-around we suggest to install direnv/grep via nix or homebrew.
|
||||
|
||||
## Why not using lorri instead.
|
||||
## Why not using lorri instead?
|
||||
|
||||
Lorri causes large CPU load when `$NIXPKGS` is pointed to a directory, i.e. a
|
||||
git checkout. This is because it tries to watch any referenced nix file and
|
||||
|
|
|
|||
13
direnvrc
13
direnvrc
|
|
@ -1,10 +1,9 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
: "${direnv_layout_dir:=.direnv}"
|
||||
|
||||
use_nix() {
|
||||
local path
|
||||
path="$(nix-instantiate --find-file nixpkgs)"
|
||||
local path direnv_dir
|
||||
path=$(nix-instantiate --find-file nixpkgs)
|
||||
direnv_dir=$(direnv_layout_dir)
|
||||
|
||||
if [[ "${direnv:-}" == "" ]]; then
|
||||
log_status "\$direnv environment variable was not defined. Was this script run inside direnv?"
|
||||
|
|
@ -24,7 +23,7 @@ use_nix() {
|
|||
fi
|
||||
fi
|
||||
|
||||
local cache="${direnv_layout_dir}/cache-${version:-unknown}"
|
||||
local cache="$direnv_dir/cache-${version:-unknown}"
|
||||
|
||||
local update_drv=0
|
||||
if [[ ! -e "$cache" ]] || \
|
||||
|
|
@ -33,7 +32,7 @@ use_nix() {
|
|||
[[ default.nix -nt "$cache" ]] || \
|
||||
[[ shell.nix -nt "$cache" ]];
|
||||
then
|
||||
[[ -d "${direnv_layout_dir}" ]] || mkdir "${direnv_layout_dir}"
|
||||
[[ -d "$direnv_dir" ]] || mkdir "$direnv_dir"
|
||||
local dump_cmd tmp
|
||||
dump_cmd="echo -n _____direnv_____; \"$direnv\" dump bash"
|
||||
tmp=$(nix-shell --show-trace --pure "$@" --run "$dump_cmd" \
|
||||
|
|
@ -79,7 +78,7 @@ use_nix() {
|
|||
|
||||
# This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4
|
||||
if [[ "${out:-}" != "" ]] && (( update_drv )); then
|
||||
local drv_link="${direnv_layout_dir}/drv" drv
|
||||
local drv_link="${direnv_dir}/drv" drv
|
||||
drv=$(nix show-derivation "$out" | grep -E -o -m1 '/nix/store/.*.drv')
|
||||
local stripped_pwd=${PWD/\//}
|
||||
local escaped_pwd=${stripped_pwd//-/--}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue