Files
nix/hosts/common/configs/user/console/nix-direnv/default.nix
Nikolaos Karaolidis 6d913c2ff0 Add nix shell aliases
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
2024-12-29 11:25:33 +02:00

52 lines
1.2 KiB
Nix

{
user ? throw "user argument is required",
home ? throw "home argument is required",
}:
{ inputs, ... }:
{
home-manager.users.${user} = {
programs = {
direnv = {
enable = true;
silent = true;
nix-direnv.enable = true;
enableZshIntegration = true;
};
zsh = {
shellAliases.nde = "nix-direnv";
initExtra = ''
nix-direnv() {
if [ -z "$1" ]; then
echo "Usage: nix-direnv <shell>"
return 1
fi
echo "use $1" > .envrc
direnv allow
}
'';
};
};
# https://github.com/direnv/direnv/wiki/Customizing-cache-location
xdg.configFile."direnv/direnvrc".text = ''
declare -A direnv_layout_dirs
direnv_layout_dir() {
local hash path
echo "''${direnv_layout_dirs[$PWD]:=$(
hash="$(sha1sum - <<< "$PWD" | head -c40)"
path="''${PWD//[^a-zA-Z0-9]/-}"
echo "${home}/.cache/direnv/layouts/''${hash}''${path}"
)}"
}
'';
};
environment.persistence = {
"/persist"."${home}/.local/share/direnv/allow" = { };
"/cache"."${home}/.cache/direnv" = { };
};
}