Triple oh
·
2025-09-08
clean-tmp.nix
1{pkgs, ...}: {
2 systemd.services.clean-tmp2 = {
3 description = "Clean /tmp at boot";
4 wantedBy = ["multi-user.target"];
5 path = [
6 pkgs.coreutils
7 # pkgs.odate
8 ];
9 serviceConfig = {
10 Type = "oneshot"; # Run once and exit
11 User = "root"; # Run as root if needed
12 };
13 script = ''
14 set -xe
15 export D=$(date +"%y-%m-%d-%s")
16 mkdir /m/crazy-temp/$D
17 ${pkgs.rsync}/bin/rsync -av --exclude /tmp/tmpfs --remove-source-files /tmp/* /m/crazy-temp/$D/
18 '';
19 };
20
21 # systemd.services.clean-tmp = {
22 # description = "Clean /tmp at boot";
23 # wantedBy = ["multi-user.target"];
24 # before = ["local-fs.target"];
25 # serviceConfig = {
26 # Type = "oneshot";
27 # ExecStart = "/run/current-system/sw/bin/rm -rf /tmp/*";
28 # };
29 # };
30
31 fileSystems."/tmp/tmpfs" = {
32 device = "tmpfs";
33 fsType = "tmpfs";
34 # Adjust size as needed
35 # Technically, we want to expand (This is not ramfs)
36 options = ["mode=1777" "size=2G"];
37 };
38}