at 16.09-beta 1.5 kB view raw
1{ config, stdenv, pkgs, lib, ... }: 2 3with lib; 4 5{ 6 options = { 7 services.toxvpn = { 8 enable = mkEnableOption "enable toxvpn running on startup"; 9 10 localip = mkOption { 11 type = types.string; 12 default = "10.123.123.1"; 13 description = "your ip on the vpn"; 14 }; 15 16 port = mkOption { 17 type = types.int; 18 default = 33445; 19 description = "udp port for toxcore, port-forward to help with connectivity if you run many nodes behind one NAT"; 20 }; 21 }; 22 }; 23 24 config = mkIf config.services.toxvpn.enable { 25 systemd.services.toxvpn = { 26 description = "toxvpn daemon"; 27 28 requires = [ "network-online.target" ]; # consider replacing by NetworkManager-wait-online.service 29 wantedBy = [ "multi-user.target" ]; 30 31 preStart = '' 32 mkdir -p /run/toxvpn || true 33 chown toxvpn /run/toxvpn 34 ''; 35 36 serviceConfig = { 37 ExecStart = "${pkgs.toxvpn}/bin/toxvpn -i ${config.services.toxvpn.localip} -l /run/toxvpn/control -u toxvpn -p ${toString config.services.toxvpn.port}"; 38 KillMode = "process"; 39 Restart = "on-success"; 40 Type = "notify"; 41 }; 42 43 restartIfChanged = false; # Likely to be used for remote admin 44 }; 45 46 users.extraUsers = { 47 toxvpn = { 48 uid = config.ids.uids.toxvpn; 49 home = "/var/lib/toxvpn"; 50 createHome = true; 51 }; 52 }; 53 }; 54}