From 46588dfba3a35cb18197e967edb5f028383b6103 Mon Sep 17 00:00:00 2001 From: Dmitriy Kholkin Date: Sat, 15 Apr 2023 03:21:02 +0300 Subject: [PATCH] add auto-clean downloads folder --- profiles/workspace/xdg.nix | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/profiles/workspace/xdg.nix b/profiles/workspace/xdg.nix index 853edc9..4f6d060 100644 --- a/profiles/workspace/xdg.nix +++ b/profiles/workspace/xdg.nix @@ -4,15 +4,24 @@ xdg.userDirs.enable = true; }; - environment.sessionVariables = { - DE = "generic"; + environment.sessionVariables = { DE = "generic"; }; + + systemd.user.services.cleanup-home-dirs = let + home-conf = config.home-manager.users.${config.mainuser}; + days = "30"; + folders = map (x: home-conf.home.homeDirectory + "/" + x) [ "Downloads" ]; + in { + serviceConfig.Type = "oneshot"; + script = '' + ${builtins.concatStringsSep "\n" (map (x: + "find ${ + lib.escapeShellArg x + } -mtime +${days} -exec rm -rv {} + -depth;") + folders)} + ''; + wantedBy = [ "default.target" ]; }; - persist.state.homeDirectories = [ - "Documents" - "Downloads" - "Music" - "Pictures" - "Videos" - ]; -} \ No newline at end of file + persist.state.homeDirectories = + [ "Documents" "Downloads" "Music" "Pictures" "Videos" ]; +}