2016-03-26 16:02:00 +00:00
|
|
|
# NixOS module for iodine, ip over dns daemon
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.iodine;
|
|
|
|
|
|
|
|
iodinedUser = "iodined";
|
|
|
|
|
2020-02-02 12:00:00 +00:00
|
|
|
/* is this path made unreadable by ProtectHome = true ? */
|
|
|
|
isProtected = x: hasPrefix "/root" x || hasPrefix "/home" x;
|
2016-03-26 16:02:00 +00:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "iodined" "enable" ] [ "services" "iodine" "server" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "iodined" "domain" ] [ "services" "iodine" "server" "domain" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "iodined" "ip" ] [ "services" "iodine" "server" "ip" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "iodined" "extraConfig" ] [ "services" "iodine" "server" "extraConfig" ])
|
|
|
|
(mkRemovedOptionModule [ "services" "iodined" "client" ] "")
|
|
|
|
];
|
2016-03-26 16:02:00 +00:00
|
|
|
|
|
|
|
### configuration
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.iodine = {
|
|
|
|
clients = mkOption {
|
|
|
|
default = {};
|
2022-08-03 21:46:41 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-03-26 16:02:00 +00:00
|
|
|
Each attribute of this option defines a systemd service that
|
|
|
|
runs iodine. Many or none may be defined.
|
|
|
|
The name of each service is
|
2022-08-03 21:46:41 +01:00
|
|
|
`iodine-«name»`
|
2022-08-03 00:57:59 +01:00
|
|
|
where «name» is the name of the
|
2016-03-26 16:02:00 +00:00
|
|
|
corresponding attribute name.
|
|
|
|
'';
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-02-02 12:00:00 +00:00
|
|
|
{
|
|
|
|
foo = {
|
|
|
|
server = "tunnel.mdomain.com";
|
|
|
|
relay = "8.8.8.8";
|
|
|
|
extraConfig = "-v";
|
|
|
|
}
|
2016-03-26 16:02:00 +00:00
|
|
|
}
|
|
|
|
'';
|
2020-02-02 12:00:00 +00:00
|
|
|
type = types.attrsOf (
|
|
|
|
types.submodule (
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
server = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Hostname of server running iodined";
|
2020-02-02 12:00:00 +00:00
|
|
|
example = "tunnel.mydomain.com";
|
|
|
|
};
|
|
|
|
|
|
|
|
relay = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "DNS server to use as an intermediate relay to the iodined server";
|
2020-02-02 12:00:00 +00:00
|
|
|
example = "8.8.8.8";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Additional command line parameters";
|
2020-02-02 12:00:00 +00:00
|
|
|
example = "-l 192.168.1.10 -p 23";
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Path to a file containing the password.";
|
2020-02-02 12:00:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2016-03-26 16:02:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
server = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "enable iodined server";
|
2016-03-26 16:02:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The assigned ip address or ip range";
|
2016-03-26 16:02:00 +00:00
|
|
|
example = "172.16.10.1/24";
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Domain or subdomain of which nameservers point to us";
|
2016-03-26 16:02:00 +00:00
|
|
|
example = "tunnel.mydomain.com";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Additional command line parameters";
|
2018-03-27 20:42:37 +01:00
|
|
|
example = "-l 192.168.1.10 -p 23";
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "File that contains password";
|
2016-03-26 16:02:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
### implementation
|
|
|
|
|
|
|
|
config = mkIf (cfg.server.enable || cfg.clients != {}) {
|
|
|
|
environment.systemPackages = [ pkgs.iodine ];
|
|
|
|
boot.kernelModules = [ "tun" ];
|
|
|
|
|
|
|
|
systemd.services =
|
2020-02-02 12:00:00 +00:00
|
|
|
let
|
|
|
|
createIodineClientService = name: cfg:
|
|
|
|
{
|
|
|
|
description = "iodine client - ${name}";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-02-13 12:00:00 +00:00
|
|
|
script = "exec ${pkgs.iodine}/bin/iodine -f -u ${iodinedUser} ${cfg.extraConfig} ${optionalString (cfg.passwordFile != "") "< \"${builtins.toString cfg.passwordFile}\""} ${cfg.relay} ${cfg.server}";
|
2020-02-02 12:00:00 +00:00
|
|
|
serviceConfig = {
|
|
|
|
RestartSec = "30s";
|
|
|
|
Restart = "always";
|
2020-02-02 12:00:00 +00:00
|
|
|
|
|
|
|
# hardening :
|
|
|
|
# Filesystem access
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = if isProtected cfg.passwordFile then "read-only" else "true" ;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ReadWritePaths = "/dev/net/tun";
|
|
|
|
PrivateDevices = false;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
# Caps
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
# Misc.
|
|
|
|
LockPersonality = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
2020-02-02 12:00:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
listToAttrs (
|
|
|
|
mapAttrsToList
|
|
|
|
(name: value: nameValuePair "iodine-${name}" (createIodineClientService name value))
|
|
|
|
cfg.clients
|
|
|
|
) // {
|
|
|
|
iodined = mkIf (cfg.server.enable) {
|
|
|
|
description = "iodine, ip over dns server daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-02-13 12:00:00 +00:00
|
|
|
script = "exec ${pkgs.iodine}/bin/iodined -f -u ${iodinedUser} ${cfg.server.extraConfig} ${optionalString (cfg.server.passwordFile != "") "< \"${builtins.toString cfg.server.passwordFile}\""} ${cfg.server.ip} ${cfg.server.domain}";
|
2020-02-02 12:00:00 +00:00
|
|
|
serviceConfig = {
|
|
|
|
# Filesystem access
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = if isProtected cfg.server.passwordFile then "read-only" else "true" ;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ReadWritePaths = "/dev/net/tun";
|
|
|
|
PrivateDevices = false;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
# Caps
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
# Misc.
|
|
|
|
LockPersonality = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
};
|
2020-02-02 12:00:00 +00:00
|
|
|
};
|
2016-03-26 16:02:00 +00:00
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users.${iodinedUser} = {
|
2016-03-26 16:02:00 +00:00
|
|
|
uid = config.ids.uids.iodined;
|
2021-08-08 13:00:00 +01:00
|
|
|
group = "iodined";
|
2016-03-26 16:02:00 +00:00
|
|
|
description = "Iodine daemon user";
|
|
|
|
};
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.iodined.gid = config.ids.gids.iodined;
|
2016-03-26 16:02:00 +00:00
|
|
|
};
|
|
|
|
}
|