about summary refs log tree commit diff
path: root/home/packages/default.nix
blob: fbf258fdb455d9619c8162bd9e21ec2040e47ede (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
{ config, lib, pkgs, ... }:
let
  cfg = config.my.home.packages;
  album-to-nas = pkgs.writeShellScriptBin "album-to-nas" ''
    set -euo pipefail

    ALBUM_PATH="''${1}"
    ALBUM_NAME=$(basename "''${ALBUM_PATH}")
    NAS=$(${pkgs.tailscale}/bin/tailscale status --json | ${pkgs.jq}/bin/jq -r '.Peer | map(select(.HostName == "tahoe"))[0].TailscaleIPs[0]')

    scp "''${ALBUM_PATH}" "''${NAS}:~/import/album.zip"
    ssh "''${NAS}" bc-to-beet ~/import/album.zip
  '';

  restic-nas = pkgs.writeShellApplication
    {
      name = "restic-nas";
      runtimeInputs = [ pkgs.restic pkgs.tailscale pkgs.jq ];
      text = ''
        NAS=$(tailscale status --json | jq -r '.Peer | map(select(.HostName == "tahoe"))[0].TailscaleIPs[0]')

        RESTIC_REPOSITORY="sftp:''${NAS}:/$(hostname)"
        export RESTIC_REPOSITORY
        export RESTIC_PASSWORD_FILE=/run/agenix/restic/repo-users

        sudo -E restic -o sftp.command="ssh backup@''${NAS} -i /run/agenix/restic/ssh-key -s sftp" "$@"
      '';
    };
in
{
  options.my.home.packages = with lib; {
    enable = mkEnableOption "user packages";
    additionalPackages = mkOption {
      type = with types; listOf package;
      default = [ ];
      example = literalExample ''
        with pkgs; [
          pavucontrol
        ]
      '';
    };
  };
  config.home.packages = with pkgs;
    lib.mkIf cfg.enable
      ([
        dive # explore layers in docker images
        jq
        restic # in order to interact with my backups
        ripgrep
        util-linux

        # custom tools
        album-to-nas
        restic-nas

        # tools inside the tools directory
        tools.gha-billing
        tools.git-blame-stats
        tools.git-broom
        tools.ipconverter
        tools.seqstat

        # tools from external repositories
        # x509-info
        # gh-ssh-keys
        # masked-emails
      ]
      ++ cfg.additionalPackages);
}