Created
January 17, 2020 15:40
-
-
Save zimbatm/77bfa0268b5a2a540c4d0d9189bb1ae2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: use nix_shell | |
# | |
# Works like use_nix, except that it's only rebuilt if the shell.nix or | |
# default.nix file changes. This avoids scenarios where the nix-channel is | |
# being updated and all the projects now need to be re-built. | |
# | |
# To force the reload the derivation, run `touch shell.nix` | |
use_nix() { | |
local shellfile=shell.nix | |
local wd=$PWD/.direnv/nix | |
local drvfile=$wd/shell.drv | |
# same heuristic as nix-shell | |
if [[ ! -f $shellfile ]]; then | |
shellfile=default.nix | |
fi | |
if [[ ! -f $shellfile ]]; then | |
fail "use nix_shell: shell.nix or default.nix not found in the folder" | |
fi | |
if [[ -f $drvfile && $(stat -c %Y "$shellfile") -gt $(stat -c %Y "$drvfile") ]]; then | |
log_status "use nix_shell: removing stale drv" | |
rm "$drvfile" | |
fi | |
if [[ ! -f $drvfile ]]; then | |
mkdir -p "$wd" | |
# instanciate the drv like it was in a nix-shell | |
IN_NIX_SHELL=1 nix-instantiate \ | |
--show-trace \ | |
--add-root "$drvfile" --indirect \ | |
"$shellfile" >/dev/null | |
fi | |
direnv_load nix-shell "$drvfile" --run "$(join_args "$direnv" dump)" | |
watch_file "$shellfile" | |
} |
I now use https://github.com/nix-community/nix-direnv/, that I installed on my MacOS like so: https://github.com/nix-community/nix-direnv/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A version that works on MacOS: zupo/dotfiles@8129398#diff-87eeee0cef907adfcb47fef055323a46