{ config, lib, pkgs, ... }:

let
  cfg = config.sydnix.users.crumb.direnv;
in {
  options.sydnix.users.crumb.direnv.enable =
    lib.mkEnableOption "direnv, à la crumb";
  config = lib.mkIf cfg.enable {
    programs.direnv = {
      enable = true;
      nix-direnv.enable = true;
    };

    # Persist allowed directories.
    sydnix.impermanence.directories =
      let xdg-data-home =
        lib.removePrefix "${config.home.homeDirectory}"
          (lib.removePrefix "~"
            config.xdg.dataHome);
      in [ "${xdg-data-home}/direnv" ];
  };
}

