diff --git a/flake.nix b/flake.nix index 98d8782..c68879d 100644 --- a/flake.nix +++ b/flake.nix @@ -147,6 +147,7 @@ gpg = ./home/modules/programs/gpg; neovim-auto-clean-swapfiles = ./home/modules/programs/neovim/auto-clean-swapfiles.nix; nix-index-auto-update-database = ./home/modules/programs/nix-index/auto-update-database.nix; + direnv-auto-prune = ./home/modules/programs/direnv/auto-prune.nix; }; homeConfigurations = { diff --git a/home/home.nix b/home/home.nix index 0807eda..65caadd 100644 --- a/home/home.nix +++ b/home/home.nix @@ -52,6 +52,7 @@ in { ./modules/programs/gpg ./modules/programs/neovim/auto-clean-swapfiles.nix ./modules/programs/nix-index/auto-update-database.nix + ./modules/programs/direnv/auto-prune.nix ] ++ (optionals graphics [ ./config/gtk.nix diff --git a/home/modules/programs/direnv/auto-prune.nix b/home/modules/programs/direnv/auto-prune.nix new file mode 100644 index 0000000..b45b13f --- /dev/null +++ b/home/modules/programs/direnv/auto-prune.nix @@ -0,0 +1,51 @@ +{ config, pkgs, lib, ... }: +let + cfg = config.programs.direnv; +in +{ + options.programs.direnv.auto-prune-allowed-dirs = { + enable = lib.mkEnableOption "automatic pruning of direnv dirs"; + + onCalendar = lib.mkOption { + type = lib.types.str; + default = "daily"; + example = "weekly"; + # TODO: link to systemd manpage for format. + description = "How often to prune dirs."; + }; + }; + + config = lib.mkIf cfg.auto-prune-allowed-dirs.enable { + systemd.user.services.direnv-auto-prune-allowed-dirs = { + Unit = { + Description = "Prune unused allowed directories for direnv"; + Documentation = [ "man:direnv(1)" ]; + ConditionPathExists = "${config.xdg.dataHome}/direnv/allow"; + }; + + Service = { + Type = "oneshot"; + CPUSchedulingPolicy = "idle"; + IOSchedulingClass = "idle"; + ExecStart = "${lib.getExe cfg.package} prune"; + }; + }; + + systemd.user.timers.direnv-auto-prune-allowed-dirs = { + Unit = { + Description = "Prune unused allowed directories for direnv"; + Documentation = [ "man:direnv(1)" ]; + }; + + Timer = { + Unit = "direnv-auto-prune-allowed-dirs.service"; + OnCalendar = cfg.auto-prune-allowed-dirs.onCalendar; + Persistent = true; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; + }; +} diff --git a/home/programs/direnv/default.nix b/home/programs/direnv/default.nix index 53405d1..11094eb 100644 --- a/home/programs/direnv/default.nix +++ b/home/programs/direnv/default.nix @@ -1,13 +1,11 @@ { config, ... }: { - imports = [ - ./auto-prune.nix - ]; - programs.direnv = { enable = true; enableZshIntegration = true; nix-direnv.enable = true; enableNushellIntegration = config.programs.nushell.enable; + + auto-prune-allowed-dirs.enable = true; }; }