about summary refs log tree commit diff stats
path: root/hm/soispha/pkgs/scripts.nix
blob: 57aff326263a5e7fa9b8160f4bb516b9b48987a3 (plain) (blame)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
{
  pkgs,
  lib,
  sysLib,
  config,
  ...
}: let
  write_shell = {
    name,
    path,
    dependencies ? [],
    keepPath ? false,
    completions ? false,
  }:
    sysLib.writeShellScript {
      inherit name keepPath;
      src = ./scripts/${path}/${name};
      dependencies = dependencies ++ [pkgs.dash];
      generateCompletions = completions;
    };
  write_python = {
    name,
    path,
    dependencies_system ? [],
    dependencies_python ? _: [],
    keepPath ? false,
  }: let
    src = ./scripts/${path}/${name};
    dependencies =
      [(pkgs.python3.withPackages dependencies_python)]
      ++ dependencies_system;
    path_setting =
      if keepPath
      then "--prefix PATH :"
      else "--set PATH";
  in
    pkgs.runCommandLocal name {
      nativeBuildInputs = [pkgs.makeWrapper] ++ dependencies;
    }
    ''
      install -m755 ${src} -D "$out/bin/${name}"
      patchShebangs "$out/bin/${name}"
      wrapProgram "$out/bin/${name}" ${path_setting} ${pkgs.lib.makeBinPath dependencies};
    '';

  ## Begin of shell scripts

  aumo-scr = write_shell {
    name = "aumo";
    path = "apps";
    dependencies = builtins.attrValues {inherit (pkgs) udisks gawk gnused gnugrep sudo;};
  };

  con2pdf-scr = sysLib.writeShellScript {
    name = "con2pdf";
    src = ./scripts/apps/con2pdf;
    dependencies = builtins.attrValues {inherit (pkgs) sane-backends imagemagick coreutils fd;};
    generateCompletions = true;
    replacementStrings = {
      DEVICE_FUNCTION =
        # This is here, because escaping the whole function, to use it in the shell script
        # directly just isn't possible
        pkgs.writeText "DEVICE_FUNCTION"
        /*
        bash
        */
        ''
          scanimage -L | awk 'BEGIN { FS = "`" } { gsub(/'.*/, "", $2); print $2 }'
        '';
    };
  };

  description-scr = write_shell {
    name = "description";
    path = "specific/ytcc";
    dependencies = builtins.attrValues {
      inherit (pkgs) jq fmt less locale;
    };
  };

  fupdate-scr = write_shell {
    name = "fupdate";
    path = "apps";
    keepPath = true;
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        dash
        nix
        gnugrep
        fd
        coreutils
        bat # used by batgrep
        gnused # required by batgrep
        git # needed to fetch through git
        git-crypt # needed to unlock git-crypted repos
        ;
      inherit (pkgs.bat-extras) batgrep;
    };
  };

  hibernate-scr = write_shell {
    name = "hibernate";
    path = "wrappers";
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        systemd
        taskwarrior
        ;
    };
  };

  ll-scr = sysLib.writeShellScript {
    name = "ll";
    src = ./scripts/wrappers/ll;
    wrap = false;
  };

  # TODO: this need to be replaced with a wayland alternative
  #  llp-scr = write_shell {
  #     name = "llp";
  #     path = "wrappers";
  #     dependencies = builtins.attrValues {inherit (pkgs) lf ueberzug;};
  #   };

  lock-scr = write_shell {
    name = "lock";
    path = "wrappers";
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        taskwarrior
        swaylock
        ;
    };
  };

  lyrics-scr = write_shell {
    name = "lyrics";
    path = "wrappers";
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        exiftool
        mpc-cli
        jq
        less
        locale # dependency of less
        ;
    };
  };

  mpc-fav-scr = write_shell {
    name = "mpc-fav";
    path = "wrappers";
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        mpc-cli
        ;
    };
  };

  mpc-rm-scr = write_shell {
    name = "mpc-rm";
    path = "wrappers";
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        mpc-cli
        trash-cli
        ;
    };
  };

  nato-scr = write_python {
    name = "nato";
    path = "small_functions";
    dependencies_python = ps: [];
  };

  neorg-scr = sysLib.writeShellScriptMultiPart {
    name = "neorg";
    keepPath = true;
    src = ./scripts/specific/neorg/sh;
    baseName = "main";
    cmdPrefix = "functions";
    cmdNames = [
      "add"
      "context"
      "dmenu"
      "f_start"
      "f_stop"
      "list"
      "project"
      "utils"
      "workspace"
    ];
    dependencies = with pkgs; [
      cocogitto
      git-crypt
      rofi
      libnotify
    ];
    generateCompletions = true;
    replacementStrings = {
      DEFAULT_NEORG_PROJECT_DIR =
        config.programs.nixvim.plugins.neorg.modules."core.dirman".config.workspaces.projects;
      HOME_TASKRC = "${config.xdg.configHome}/task/home-manager-taskrc";
      ALL_PROJECTS_NEWLINE = "${config.soispha.taskwarrior.projects.projects_newline}";
      ALL_PROJECTS_COMMA = "${config.soispha.taskwarrior.projects.projects_comma}";
      ALL_PROJECTS_PIPE = "${config.soispha.taskwarrior.projects.projects_pipe}";
      ALL_WORKSPACES = "${lib.strings.concatStringsSep "|" (builtins.attrNames config.programs.nixvim.plugins.neorg.modules."core.dirman".config.workspaces)}";
      ID_GENERATION_FUNCTION = "${sysLib.writeShellScript {
        name = "neorg_id_function";
        src = ./scripts/specific/neorg/neorg_id_function.sh;
        dependencies = with pkgs; [
          taskwarrior
          gawk
          findutils # xargs
        ];
      }}/bin/neorg_id_function";

      # TODO: Replace the hard-coded path here with some reference <2023-10-20>
      TASK_PROJECT_FILE = "/home/soispha/repos/nix/nixos-config/hm/soispha/conf/taskwarrior/projects/default.nix";
    };
  };

  screenshot_persistent-scr = write_shell {
    name = "screenshot_persistent";
    path = "small_functions";
    keepPath = true;
    dependencies = builtins.attrValues {
      inherit
        (pkgs)
        grim
        slurp
        alacritty
        rofi
        libnotify
        lf # TODO: add llp
        ;
    };
  };

  screenshot_temporary-scr = write_shell {
    name = "screenshot_temporary";
    path = "small_functions";
    dependencies = builtins.attrValues {inherit (pkgs) grim slurp wl-clipboard;};
  };

  show-scr = write_shell {
    name = "show";
    path = "wrappers";
    keepPath = true; # I might want to use nvim in less (and shell escapes)
    dependencies = builtins.attrValues {inherit (pkgs) less locale;};
  };

  sort_song-src = write_shell {
    name = "sort_song";
    path = "wrappers";
    dependencies = builtins.attrValues {inherit (pkgs) mediainfo jq gawk;};
  };

  spodi-scr = write_shell {
    name = "spodi";
    path = "wrappers";
    dependencies = builtins.attrValues {inherit (pkgs) gawk expect spotdl fd coreutils;};
  };

  update-sys-scr = write_shell {
    name = "update-sys";
    path = "small_functions";
    dependencies = builtins.attrValues {inherit (pkgs) git git-crypt nixos-rebuild sudo openssh coreutils mktemp gnugrep gnused;};
  };

  virsh-del-scr = write_shell {
    name = "virsh-del";
    path = "wrappers";
    dependencies = builtins.attrValues {inherit (pkgs) libvirt;};
  };

  yti-scr = write_shell {
    name = "yti";
    path = "wrappers";
    dependencies = builtins.attrValues {inherit (pkgs) gawk expect yt-dlp;};
  };
in [
  # llp-scr # TODO: see above
  aumo-scr
  con2pdf-scr
  description-scr
  fupdate-scr
  hibernate-scr
  ll-scr
  lock-scr
  lyrics-scr
  mpc-fav-scr
  mpc-rm-scr
  nato-scr
  neorg-scr
  screenshot_persistent-scr
  screenshot_temporary-scr
  show-scr
  sort_song-src
  spodi-scr
  update-sys-scr
  virsh-del-scr
  yti-scr
]