home/modules: add automation for direnv

This commit is contained in:
2025-03-24 14:23:43 +01:00
parent f09a1ee2d0
commit 7189c245b5
4 changed files with 55 additions and 4 deletions

View File

@@ -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

View File

@@ -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" ];
};
};
};
}

View File

@@ -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;
};
}