Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created March 1, 2022 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/891cdff1912670f71f8df7a4e9b811c9 to your computer and use it in GitHub Desktop.
Save Mic92/891cdff1912670f71f8df7a4e9b811c9 to your computer and use it in GitHub Desktop.
diff --git a/.envrc b/.envrc
index 8aaa78e..1d47631 100644
--- a/.envrc
+++ b/.envrc
@@ -7,6 +7,17 @@ watch_dir nix
watch_file default.nix BUILD.nix
# Build and load the devshell
-out=$(nix-build -A shell --no-out-link)
+layout_dir=$(direnv_layout_dir)
+[[ -d "$layout_dir" ]] || mkdir -p "$layout_dir"
+if [[ ! -f "$layout_dir/last-build"
+ || "$layout_dir/last-build" -ot BUILD.nix
+ || "$layout_dir/last-build" -ot default.nix
+ || "$layout_dir/last-build" -ot nix/sources.json
+ || "$layout_dir/last-build" -ot nix/sources.nix
+ || "$layout_dir/last-build" -ot nix/default.nix
+ ]]; then
+ nix-build --builders '' -A shell --out-link "$layout_dir/shell"
+ touch "$layout_dir/last-build"
+fi
# shellcheck disable=SC1091
-source "$out/env.bash"
+source "$layout_dir/shell/env.bash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment