summary refs log tree commit diff
path: root/nixos/modules/services/networking/iodined.nix
blob: 1b3473ee0ee1b2c33dfa7f24c4f294b1cd519f8e (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
# NixOS module for iodine, ip over dns daemon

{ config, pkgs, ... }:

with pkgs.lib;

let
  cfg = config.services.iodined;

  iodinedUser = "iodined";

in

{

  ### configuration

  options = {

    services.iodined = {

      enable = mkOption {
        type = types.uniq types.bool;
        default = false;
        description = "Enable iodine, ip over dns daemon";
      };

      client = mkOption {
        type = types.uniq types.bool;
        default = false;
        description = "Start iodine in client mode";
      };

      ip = mkOption {
        type = types.uniq types.string;
        default = "";
        description = "Assigned ip address or ip range";
        example = "172.16.10.1/24";
      };

      domain = mkOption {
        type = types.uniq types.string;
        default = "";
        description = "Domain or subdomain of which nameservers point to us";
        example = "tunnel.mydomain.com";
      };

      extraConfig = mkOption {
        type = types.uniq types.string;
        default = "";
        description = "Additional command line parameters";
        example = "-P mysecurepassword -l 192.168.1.10 -p 23";
      };

    };

  };

  ### implementation

  config = mkIf cfg.enable {
    environment.systemPackages = [ pkgs.iodine ];
    boot.kernelModules = [ "tun" ];

    systemd.services.iodined = {
      description = "iodine, ip over dns daemon";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig.ExecStart = "${pkgs.iodine}/sbin/iodined -f -u ${iodinedUser} ${cfg.extraConfig} ${cfg.ip} ${cfg.domain}";
    };


    users.extraUsers = singleton {
      name = iodinedUser;
      uid = config.ids.uids.iodined;
      description = "Iodine daemon user";
    };
    users.extraGroups.iodined.gid = config.ids.gids.iodined;

    assertions = [{ assertion = if !cfg.client then cfg.ip != "" else true;
                    message = "cannot start iodined without ip set";}
                  { assertion = cfg.domain != "";
                    message = "cannot start iodined without domain name set";}];

  };

}