Compare commits
5 Commits
20b2dfac7c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fb279eca0 | |||
| 0c8db23a3b | |||
| 14526f5419 | |||
| c767762ee0 | |||
| ba07678b31 |
10
default.nix
10
default.nix
@@ -1,4 +1,9 @@
|
||||
{ stdenv, direnv, term-test }:
|
||||
{ stdenv
|
||||
, direnv
|
||||
, term-test ? null
|
||||
, doCheck ? true
|
||||
}:
|
||||
assert doCheck -> term-test != null;
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "direnv-cache";
|
||||
@@ -8,6 +13,7 @@ stdenv.mkDerivation {
|
||||
make install PREFIX=$out
|
||||
'';
|
||||
checkInputs = [ term-test ];
|
||||
doCheck = true;
|
||||
inherit doCheck;
|
||||
passthru = { direnvrc = ./direnvrc; };
|
||||
preferLocalBuild = true;
|
||||
}
|
||||
|
||||
20
direnv-cache
20
direnv-cache
@@ -70,9 +70,23 @@ getCacheFilePath() {
|
||||
echo "${cacheDir}/$(pwd | sha1sum | tr -d ' -')"
|
||||
}
|
||||
|
||||
switchToDirenvDir() {
|
||||
# Find directory that contains the current .envrc. Allows direnv-cache to
|
||||
# be called from subdirectories.
|
||||
wd="$(pwd)"
|
||||
|
||||
if [[ -n $DIRENV_DIR ]]; then
|
||||
wd="${DIRENV_DIR#-}"
|
||||
fi
|
||||
|
||||
cd "$wd"
|
||||
}
|
||||
|
||||
cmd="$1"
|
||||
|
||||
if ! [[ -e .envrc ]]; then
|
||||
switchToDirenvDir
|
||||
|
||||
if ! [[ -e ".envrc" ]]; then
|
||||
echo "Error, no .envrc found in current directory"
|
||||
exit 1
|
||||
fi
|
||||
@@ -84,15 +98,15 @@ case $cmd in
|
||||
if [[ -n $DIRENV_DIR ]]; then
|
||||
# run self in clean environment (i.e. outside of the current direnv
|
||||
# environment)
|
||||
echo "Switching to clean environment"
|
||||
exec direnv exec /proc "${BASH_SOURCE[0]}" "$@"
|
||||
fi
|
||||
echo "Re-creating cache"
|
||||
mkdir -p "$(dirname ${cacheFile})"
|
||||
dumpEnv > "${cacheFile}.pre"
|
||||
source <(direnv stdlib)
|
||||
if [[ .envrc -nt ${cacheFile}.recipe ]]; then
|
||||
echo "Re-creating recipe"
|
||||
direnv exec . true > /dev/null
|
||||
fi
|
||||
source "${cacheFile}.recipe"
|
||||
dumpEnv > "${cacheFile}.post"
|
||||
diffEnvs "${cacheFile}.pre" "${cacheFile}.post" > "$cacheFile"
|
||||
|
||||
Reference in New Issue
Block a user