nixos-config/modules/home-manager/direnv.nix
xinyangli e702d503b9
home-manager/direnv: enable evalutaion cache through nix-direnv
(Forgot to enable nix-direnv all this time. How dumb am I.)
2024-08-25 16:56:38 +08:00

31 lines
674 B
Nix

{ config, lib, ... }:
with lib;
let
cfg = config.custom-hm.direnv;
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 = {
programs = mkIf cfg.enable {
direnv = {
enable = true;
stdlib = changeCacheDir;
nix-direnv.enable = true;
};
};
};
}