mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 20:55:31 +03:00
nixos/services.iodine: remove with lib;
This commit is contained in:
parent
b610b3cac2
commit
aa27551b00
1 changed files with 35 additions and 39 deletions
|
@ -1,24 +1,20 @@
|
||||||
# NixOS module for iodine, ip over dns daemon
|
# NixOS module for iodine, ip over dns daemon
|
||||||
|
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.iodine;
|
cfg = config.services.iodine;
|
||||||
|
|
||||||
iodinedUser = "iodined";
|
iodinedUser = "iodined";
|
||||||
|
|
||||||
/* is this path made unreadable by ProtectHome = true ? */
|
/* is this path made unreadable by ProtectHome = true ? */
|
||||||
isProtected = x: hasPrefix "/root" x || hasPrefix "/home" x;
|
isProtected = x: lib.hasPrefix "/root" x || lib.hasPrefix "/home" x;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule [ "services" "iodined" "enable" ] [ "services" "iodine" "server" "enable" ])
|
(lib.mkRenamedOptionModule [ "services" "iodined" "enable" ] [ "services" "iodine" "server" "enable" ])
|
||||||
(mkRenamedOptionModule [ "services" "iodined" "domain" ] [ "services" "iodine" "server" "domain" ])
|
(lib.mkRenamedOptionModule [ "services" "iodined" "domain" ] [ "services" "iodine" "server" "domain" ])
|
||||||
(mkRenamedOptionModule [ "services" "iodined" "ip" ] [ "services" "iodine" "server" "ip" ])
|
(lib.mkRenamedOptionModule [ "services" "iodined" "ip" ] [ "services" "iodine" "server" "ip" ])
|
||||||
(mkRenamedOptionModule [ "services" "iodined" "extraConfig" ] [ "services" "iodine" "server" "extraConfig" ])
|
(lib.mkRenamedOptionModule [ "services" "iodined" "extraConfig" ] [ "services" "iodine" "server" "extraConfig" ])
|
||||||
(mkRemovedOptionModule [ "services" "iodined" "client" ] "")
|
(lib.mkRemovedOptionModule [ "services" "iodined" "client" ] "")
|
||||||
];
|
];
|
||||||
|
|
||||||
### configuration
|
### configuration
|
||||||
|
@ -26,7 +22,7 @@ in
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.iodine = {
|
services.iodine = {
|
||||||
clients = mkOption {
|
clients = lib.mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
description = ''
|
description = ''
|
||||||
Each attribute of this option defines a systemd service that
|
Each attribute of this option defines a systemd service that
|
||||||
|
@ -36,7 +32,7 @@ in
|
||||||
where «name» is the name of the
|
where «name» is the name of the
|
||||||
corresponding attribute name.
|
corresponding attribute name.
|
||||||
'';
|
'';
|
||||||
example = literalExpression ''
|
example = lib.literalExpression ''
|
||||||
{
|
{
|
||||||
foo = {
|
foo = {
|
||||||
server = "tunnel.mdomain.com";
|
server = "tunnel.mdomain.com";
|
||||||
|
@ -45,33 +41,33 @@ in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
type = types.attrsOf (
|
type = lib.types.attrsOf (
|
||||||
types.submodule (
|
lib.types.submodule (
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
server = mkOption {
|
server = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Hostname of server running iodined";
|
description = "Hostname of server running iodined";
|
||||||
example = "tunnel.mydomain.com";
|
example = "tunnel.mydomain.com";
|
||||||
};
|
};
|
||||||
|
|
||||||
relay = mkOption {
|
relay = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "DNS server to use as an intermediate relay to the iodined server";
|
description = "DNS server to use as an intermediate relay to the iodined server";
|
||||||
example = "8.8.8.8";
|
example = "8.8.8.8";
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Additional command line parameters";
|
description = "Additional command line parameters";
|
||||||
example = "-l 192.168.1.10 -p 23";
|
example = "-l 192.168.1.10 -p 23";
|
||||||
};
|
};
|
||||||
|
|
||||||
passwordFile = mkOption {
|
passwordFile = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Path to a file containing the password.";
|
description = "Path to a file containing the password.";
|
||||||
};
|
};
|
||||||
|
@ -82,35 +78,35 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
server = {
|
server = {
|
||||||
enable = mkOption {
|
enable = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "enable iodined server";
|
description = "enable iodined server";
|
||||||
};
|
};
|
||||||
|
|
||||||
ip = mkOption {
|
ip = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "The assigned ip address or ip range";
|
description = "The assigned ip address or ip range";
|
||||||
example = "172.16.10.1/24";
|
example = "172.16.10.1/24";
|
||||||
};
|
};
|
||||||
|
|
||||||
domain = mkOption {
|
domain = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Domain or subdomain of which nameservers point to us";
|
description = "Domain or subdomain of which nameservers point to us";
|
||||||
example = "tunnel.mydomain.com";
|
example = "tunnel.mydomain.com";
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Additional command line parameters";
|
description = "Additional command line parameters";
|
||||||
example = "-l 192.168.1.10 -p 23";
|
example = "-l 192.168.1.10 -p 23";
|
||||||
};
|
};
|
||||||
|
|
||||||
passwordFile = mkOption {
|
passwordFile = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = "File that contains password";
|
description = "File that contains password";
|
||||||
};
|
};
|
||||||
|
@ -121,7 +117,7 @@ in
|
||||||
|
|
||||||
### implementation
|
### implementation
|
||||||
|
|
||||||
config = mkIf (cfg.server.enable || cfg.clients != {}) {
|
config = lib.mkIf (cfg.server.enable || cfg.clients != {}) {
|
||||||
environment.systemPackages = [ pkgs.iodine ];
|
environment.systemPackages = [ pkgs.iodine ];
|
||||||
boot.kernelModules = [ "tun" ];
|
boot.kernelModules = [ "tun" ];
|
||||||
|
|
||||||
|
@ -132,7 +128,7 @@ in
|
||||||
description = "iodine client - ${name}";
|
description = "iodine client - ${name}";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
script = "exec ${pkgs.iodine}/bin/iodine -f -u ${iodinedUser} ${cfg.extraConfig} ${optionalString (cfg.passwordFile != "") "< \"${builtins.toString cfg.passwordFile}\""} ${cfg.relay} ${cfg.server}";
|
script = "exec ${pkgs.iodine}/bin/iodine -f -u ${iodinedUser} ${cfg.extraConfig} ${lib.optionalString (cfg.passwordFile != "") "< \"${builtins.toString cfg.passwordFile}\""} ${cfg.relay} ${cfg.server}";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
RestartSec = "30s";
|
RestartSec = "30s";
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
|
@ -157,16 +153,16 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
listToAttrs (
|
lib.listToAttrs (
|
||||||
mapAttrsToList
|
lib.mapAttrsToList
|
||||||
(name: value: nameValuePair "iodine-${name}" (createIodineClientService name value))
|
(name: value: lib.nameValuePair "iodine-${name}" (createIodineClientService name value))
|
||||||
cfg.clients
|
cfg.clients
|
||||||
) // {
|
) // {
|
||||||
iodined = mkIf (cfg.server.enable) {
|
iodined = lib.mkIf (cfg.server.enable) {
|
||||||
description = "iodine, ip over dns server daemon";
|
description = "iodine, ip over dns server daemon";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
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}";
|
script = "exec ${pkgs.iodine}/bin/iodined -f -u ${iodinedUser} ${cfg.server.extraConfig} ${lib.optionalString (cfg.server.passwordFile != "") "< \"${builtins.toString cfg.server.passwordFile}\""} ${cfg.server.ip} ${cfg.server.domain}";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
# Filesystem access
|
# Filesystem access
|
||||||
ProtectSystem = "strict";
|
ProtectSystem = "strict";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue