Add a suffix to allow multiple calls to use_nix

This change permits to make multiple calls to use_nix, with different
arguments passed to it. It will generate a cache file for each distinct
"argument list" rather than based solely on the nixpkgs version.
This commit is contained in:
Ismaël Bouya 2021-08-12 11:54:03 +02:00
parent 34613e1e10
commit 9544919b4c
No known key found for this signature in database
GPG key ID: FD1D4EF57FA95902

View file

@ -86,6 +86,13 @@ _nix_add_gcroot() {
ln -fsn "$symlink" "/nix/var/nix/gcroots/per-user/$USER/$escaped_pwd"
}
_argsum_suffix() {
if [ -n "$1" ]; then
echo -n "-"
echo "$1" | shasum | cut -d' ' -f1
fi
}
use_flake() {
flake_expr="${1:-.}"
flake_dir="${flake_expr%#*}"
@ -94,7 +101,7 @@ use_flake() {
local layout_dir
layout_dir=$(direnv_layout_dir)
local profile="${layout_dir}/flake-profile"
local profile="${layout_dir}/flake-profile$(_argsum_suffix "$flake_expr")"
local flake_inputs="${layout_dir}/flake-inputs/"
local profile_rc="${profile}.rc"
@ -209,7 +216,7 @@ use_nix() {
version="${version_prefix}-${path:11:16}"
fi
local cache="${layout_dir}/cache-${version:-unknown}"
local cache="${layout_dir}/cache-${version:-unknown}$(_argsum_suffix "$*")"
local update_drv=0
if [[ ! -e "$cache"