summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/networking/dante.nix
blob: 3cb08a6c23a953e2b809e1c804093ce4c620d6ee (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
64
65
66
67
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.services.dante;
  confFile = pkgs.writeText "dante-sockd.conf" ''
    user.privileged: root
    user.unprivileged: dante
    logoutput: syslog

    ${cfg.config}
  '';
in

{
  meta = {
    maintainers = with lib.maintainers; [ arobyn ];
  };

  options = {
    services.dante = {
      enable = lib.mkEnableOption "Dante SOCKS proxy";

      config = lib.mkOption {
        type = lib.types.lines;
        description = ''
          Contents of Dante's configuration file.
          NOTE: user.privileged, user.unprivileged and logoutput are set by the service.
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    assertions = [
      {
        assertion = cfg.config != "";
        message = "please provide Dante configuration file contents";
      }
    ];

    users.users.dante = {
      description = "Dante SOCKS proxy daemon user";
      isSystemUser = true;
      group = "dante";
    };
    users.groups.dante = { };

    systemd.services.dante = {
      description = "Dante SOCKS v4 and v5 compatible proxy server";
      wants = [ "network-online.target" ];
      after = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        Type = "simple";
        ExecStart = "${pkgs.dante}/bin/sockd -f ${confFile}";
        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
        # Can crash sometimes; see https://github.com/NixOS/nixpkgs/pull/39005#issuecomment-381828708
        Restart = "on-failure";
      };
    };
  };
}