home/neovim: add half-finished swapfile remover

This commit is contained in:
Oystein Kristoffer Tveit 2024-08-12 17:36:15 +02:00
parent 3c1ad746ef
commit c8678105c6
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 61 additions and 1 deletions

View File

@ -17,7 +17,7 @@ in {
./programs/git
./programs/gpg
./programs/less.nix
./programs/neovim.nix
./programs/neovim
./programs/nix-index
./programs/tealdeer
./programs/tmux.nix

View File

@ -0,0 +1,56 @@
{ config, pkgs, lib, ... }:
let
daysBeforeDeletion = 2;
in
{
config = {
systemd.user.services.clean-neovim-swap-files = {
Unit = {
Description = "Clean old swap files for neovim";
};
Service = {
Type = "oneshot";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = lib.getExe (pkgs.writeShellApplication {
name = "clean-neovim-swap-files";
runtimeInputs = with pkgs; [ findutils ];
text = ''
echo "Cleaning old swap files for neovim"
OLD_SWAPFILES=$(find "${config.xdg.stateHome}/nvim/swap" -type f -name '*.swp' -mtime +${toString daysBeforeDeletion})
if [ -z "$OLD_SWAPFILES" ]; then
echo "No old swap files found"
exit 0
fi
for swapfile in $OLD_SWAPFILES; do
echo "Removing $swapfile"
rm -- "$swapfile"
done
echo "Done"
'';
});
};
};
systemd.user.timers.clean-neovim-swap-files = {
Unit = {
Description = "Clean old swap files for neovim";
};
Timer = {
Unit = "clean-neovim-swap-files.service";
OnCalendar = "daily";
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}

View File

@ -1,5 +1,9 @@
{ pkgs, home, ... }:
{
imports = [
./auto-clean-swapfiles.nix
];
programs.neovim = {
enable = true;