1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-20 00:19:25 +03:00
nixpkgs/nixos/modules/services/networking/hans.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
4 KiB
Nix
Raw Normal View History

2018-03-27 19:43:11 +03:00
# NixOS module for hans, ip over icmp daemon
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.hans;
hansUser = "hans";
in
{
### configuration
options = {
services.hans = {
clients = lib.mkOption {
2018-03-27 19:43:11 +03:00
default = { };
description = ''
Each attribute of this option defines a systemd service that
runs hans. Many or none may be defined.
The name of each service is
`hans-«name»`
where «name» is the name of the
2018-03-27 19:43:11 +03:00
corresponding attribute name.
'';
example = lib.literalExpression ''
2018-03-27 19:43:11 +03:00
{
foo = {
server = "192.0.2.1";
2018-03-27 22:23:36 +03:00
extraConfig = "-v";
}
2018-03-27 19:43:11 +03:00
}
'';
type = lib.types.attrsOf (
lib.types.submodule ({
2018-03-27 19:43:11 +03:00
options = {
server = lib.mkOption {
type = lib.types.str;
2018-03-27 19:43:11 +03:00
default = "";
description = "IP address of server running hans";
example = "192.0.2.1";
};
extraConfig = lib.mkOption {
type = lib.types.str;
2018-03-27 22:23:36 +03:00
default = "";
2018-03-27 19:43:11 +03:00
description = "Additional command line parameters";
2018-03-27 22:23:36 +03:00
example = "-v";
};
passwordFile = lib.mkOption {
type = lib.types.str;
2018-03-27 22:23:36 +03:00
default = "";
2022-12-17 19:31:14 -05:00
description = "File that contains password";
2018-03-27 19:43:11 +03:00
};
};
})
);
};
server = {
enable = lib.mkOption {
type = lib.types.bool;
2018-03-27 19:43:11 +03:00
default = false;
description = "enable hans server";
};
ip = lib.mkOption {
type = lib.types.str;
2018-03-27 19:43:11 +03:00
default = "";
description = "The assigned ip range";
example = "198.51.100.0";
};
respondToSystemPings = lib.mkOption {
type = lib.types.bool;
2018-03-27 19:43:11 +03:00
default = false;
2018-03-28 09:13:09 +03:00
description = "Force hans respond to ordinary pings";
2018-03-27 19:43:11 +03:00
};
extraConfig = lib.mkOption {
type = lib.types.str;
2018-03-27 19:43:11 +03:00
default = "";
description = "Additional command line parameters";
2018-03-27 22:23:36 +03:00
example = "-v";
};
passwordFile = lib.mkOption {
type = lib.types.str;
2018-03-27 22:23:36 +03:00
default = "";
2022-12-17 19:31:14 -05:00
description = "File that contains password";
2018-03-27 19:43:11 +03:00
};
};
};
};
### implementation
config = lib.mkIf (cfg.server.enable || cfg.clients != { }) {
boot.kernel.sysctl = lib.optionalAttrs cfg.server.respondToSystemPings {
2018-03-27 19:43:11 +03:00
"net.ipv4.icmp_echo_ignore_all" = 1;
};
boot.kernelModules = [ "tun" ];
systemd.services =
let
createHansClientService = name: cfg: {
description = "hans client - ${name}";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = "${pkgs.hans}/bin/hans -f -u ${hansUser} ${cfg.extraConfig} -c ${cfg.server} ${
lib.optionalString (cfg.passwordFile != "") "-p $(cat \"${cfg.passwordFile}\")"
}";
2018-03-27 19:43:11 +03:00
serviceConfig = {
RestartSec = "30s";
Restart = "always";
};
};
in
lib.listToAttrs (
lib.mapAttrsToList (
name: value: lib.nameValuePair "hans-${name}" (createHansClientService name value)
2018-03-27 19:43:11 +03:00
) cfg.clients
)
// {
hans = lib.mkIf (cfg.server.enable) {
2018-03-27 19:43:11 +03:00
description = "hans, ip over icmp server daemon";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = "${pkgs.hans}/bin/hans -f -u ${hansUser} ${cfg.server.extraConfig} -s ${cfg.server.ip} ${lib.optionalString cfg.server.respondToSystemPings "-r"} ${
2018-03-27 19:43:11 +03:00
lib.optionalString (cfg.server.passwordFile != "") "-p $(cat \"${cfg.server.passwordFile}\")"
}";
};
};
users.users.${hansUser} = {
2018-03-27 19:43:11 +03:00
description = "Hans daemon user";
2019-10-12 22:25:28 +02:00
isSystemUser = true;
2018-03-27 19:43:11 +03:00
};
};
meta.maintainers = [ ];
2018-03-27 19:43:11 +03:00
}