aboutsummaryrefslogtreecommitdiff
path: root/modules/services/sftpgo/default.nix
blob: ae0af24eb7b4ae3660933afeacecc13f9c59ff05 (plain)
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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib;
let
  cfg = config.modules.services.sftpgo;
in
{
  options.modules.services.sftpgo = {
    enable = mkEnableOption "sftpgo";
    port = mkOption {
      default = 8080;
      type = types.int;
    };
    url = mkOption {
      default = null;
      type = types.str;
    };
    dataDir = mkOption {
      default = "/var/lib/sftpgo";
      type = types.str;
    };
  };

  config =
    let
      caddy = cfg.url != null;
    in
    mkIf cfg.enable {
      networking.firewall.allowedTCPPorts = mkIf caddy [
        80
        443
      ];

      services.caddy = mkIf caddy {
        enable = true;
        virtualHosts = {
          ${cfg.url}.extraConfig = ''
            root * /web/client
            encode zstd gzip
            reverse_proxy http://localhost:${builtins.toString cfg.port}
          '';
        };
      };

      services.sftpgo = {
        enable = true;
        package = pkgs.sftpgo;
        dataDir = cfg.dataDir;
        settings = {
          httpd.bindings = lib.singleton {
            port = cfg.port;
            address = "0.0.0.0";
            enable_web_client = true;
            enable_web_admin = true;
          };
        };
      };
    };
}