nixos-config/modules/home-manager/direnv.nix

32 lines
674 B
Nix
Raw Permalink Normal View History

2024-08-20 13:09:31 +00:00
{ config, lib, ... }:
with lib;
let
cfg = config.custom-hm.direnv;
2024-08-20 13:09:31 +00:00
changeCacheDir = ''
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 "''${XDG_CACHE_HOME}/direnv/layouts/''${hash}''${path}"
)}"
}
'';
in
{
options.custom-hm.direnv = {
enable = mkEnableOption "direnv";
};
config = {
2024-08-20 13:09:31 +00:00
programs = mkIf cfg.enable {
direnv = {
enable = true;
2024-08-20 13:09:31 +00:00
stdlib = changeCacheDir;
nix-direnv.enable = true;
};
};
};
2024-08-20 13:09:31 +00:00
}