naitokosuke · dotfiles

The user half of gomi, the trash-can rm (the package is in hosts/common/packages.nix): its YAML config generated from Nix, and the weekly prune agent, together in one module (#557).

Trash

Trashed files go to ~/.gomi. forbidden_paths refuses to trash system directories and other trash locations, restores ask for confirmation, and permanent deletion is disabled.

lines 20–48
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48    core = {
      trash = {
        strategy = "auto";
        home_fallback = true;
        gomi_dir = "${config.home.homeDirectory}/.gomi";
        forbidden_paths = [
          "$HOME/.local/share/Trash"
          "$HOME/.trash"
          "$XDG_DATA_HOME/Trash"
          "/tmp/Trash"
          "/var/tmp/Trash"
          "$HOME/.gomi"
          "/"
          "/etc"
          "/usr"
          "/var"
          "/bin"
          "/sbin"
          "/lib"
          "/lib64"
        ];
      };
      restore = {
        confirm = true;
        verbose = true;
      };
      permanent_delete.enable = false;
      trash_dir = "";
    };

History and logging

The restore list covers the past year and skips .DS_Store. Debug logging rotates at 10 MB with three files kept.

lines 98–117
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117    history = {
      include.within_days = 365;
      exclude = {
        files = [ ".DS_Store" ];
        patterns = [ ];
        globs = [ ];
        size = {
          min = "0KB";
          max = "10GB";
        };
      };
    };
    logging = {
      enabled = true;
      level = "debug";
      rotation = {
        max_size = "10MB";
        max_files = 3;
      };
    };

The prune agent

Every Sunday at 03:00, trashed files older than 45 days are pruned, with gomi resolved from the store rather than PATH. No StandardOutPath / StandardErrorPath: gomi records each prune in its own log (~/.local/share/gomi/debug.log), so launchd's copy is discarded (#369).

lines 125–139
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139  launchd.agents.gomi-prune = {
    enable = true;
    config = {
      ProgramArguments = [
        (lib.getExe pkgs.gomi)
        "--prune=45d,orphans"
      ];
      StartCalendarInterval = [
        {
          Weekday = 0;
          Hour = 3;
        }
      ];
    };
  };
View the complete file141 lines · gomi.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141# The user half of gomi, the trash-can `rm` (the package is in
# hosts/common/packages.nix): its YAML config generated from Nix, and the
# weekly prune agent, together in one module (#557).
{
  config,
  lib,
  pkgs,
  ...
}:

let
  yamlFormat = pkgs.formats.yaml { };
in
{
  xdg.configFile."gomi/config.yaml".source = yamlFormat.generate "gomi-config.yaml" {
    ## Trash
    # Trashed files go to ~/.gomi. `forbidden_paths` refuses to trash system
    # directories and other trash locations, restores ask for confirmation,
    # and permanent deletion is disabled.
    core = {
      trash = {
        strategy = "auto";
        home_fallback = true;
        gomi_dir = "${config.home.homeDirectory}/.gomi";
        forbidden_paths = [
          "$HOME/.local/share/Trash"
          "$HOME/.trash"
          "$XDG_DATA_HOME/Trash"
          "/tmp/Trash"
          "/var/tmp/Trash"
          "$HOME/.gomi"
          "/"
          "/etc"
          "/usr"
          "/var"
          "/bin"
          "/sbin"
          "/lib"
          "/lib64"
        ];
      };
      restore = {
        confirm = true;
        verbose = true;
      };
      permanent_delete.enable = false;
      trash_dir = "";
    };

    ui = {
      density = "spacious";
      style = {
        list_view = {
          indent_on_select = true;
          cursor = "#AD58B4";
          selected = "#5FB458";
          filter_match = "#F39C12";
          filter_prompt = "#7AA2F7";
        };
        detail_view = {
          border = "#EEEEDD";
          info_pane = {
            deleted_from = {
              fg = "#EEEEEE";
              bg = "#1C1C1C";
            };
            deleted_at = {
              fg = "#EEEEEE";
              bg = "#1C1C1C";
            };
          };
          preview_pane = {
            border = "#3C3C3C";
            size = {
              fg = "#EEEEDD";
              bg = "#3C3C3C";
            };
            scroll = {
              fg = "#EEEEDD";
              bg = "#3C3C3C";
            };
          };
        };
        deletion_dialog = "#FF007F";
      };
      exit_message = "";
      preview = {
        syntax_highlight = true;
        colorscheme = "nord";
        directory_command = "ls -GF -1 -A --color=always";
      };
      paginator_type = "dots";
    };

    ## History and logging
    # The restore list covers the past year and skips .DS_Store. Debug logging
    # rotates at 10 MB with three files kept.
    history = {
      include.within_days = 365;
      exclude = {
        files = [ ".DS_Store" ];
        patterns = [ ];
        globs = [ ];
        size = {
          min = "0KB";
          max = "10GB";
        };
      };
    };
    logging = {
      enabled = true;
      level = "debug";
      rotation = {
        max_size = "10MB";
        max_files = 3;
      };
    };
  };

  ## The prune agent
  # Every Sunday at 03:00, trashed files older than 45 days are pruned, with
  # gomi resolved from the store rather than PATH. No StandardOutPath /
  # StandardErrorPath: gomi records each prune in its own log
  # (~/.local/share/gomi/debug.log), so launchd's copy is discarded (#369).
  launchd.agents.gomi-prune = {
    enable = true;
    config = {
      ProgramArguments = [
        (lib.getExe pkgs.gomi)
        "--prune=45d,orphans"
      ];
      StartCalendarInterval = [
        {
          Weekday = 0;
          Hour = 3;
        }
      ];
    };
  };
}
141 lines·3,428 chars·NIX