mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-20 03:43:45 +00:00
nixos/services.hans: remove with lib;
This commit is contained in:
parent
a811ef8255
commit
f30e72ffbb
@ -1,9 +1,5 @@
|
||||
# NixOS module for hans, ip over icmp daemon
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.hans;
|
||||
|
||||
@ -17,7 +13,7 @@ in
|
||||
options = {
|
||||
|
||||
services.hans = {
|
||||
clients = mkOption {
|
||||
clients = lib.mkOption {
|
||||
default = {};
|
||||
description = ''
|
||||
Each attribute of this option defines a systemd service that
|
||||
@ -27,7 +23,7 @@ in
|
||||
where «name» is the name of the
|
||||
corresponding attribute name.
|
||||
'';
|
||||
example = literalExpression ''
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
foo = {
|
||||
server = "192.0.2.1";
|
||||
@ -35,25 +31,25 @@ in
|
||||
}
|
||||
}
|
||||
'';
|
||||
type = types.attrsOf (types.submodule (
|
||||
type = lib.types.attrsOf (lib.types.submodule (
|
||||
{
|
||||
options = {
|
||||
server = mkOption {
|
||||
type = types.str;
|
||||
server = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "IP address of server running hans";
|
||||
example = "192.0.2.1";
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.str;
|
||||
extraConfig = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "Additional command line parameters";
|
||||
example = "-v";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.str;
|
||||
passwordFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "File that contains password";
|
||||
};
|
||||
@ -63,34 +59,34 @@ in
|
||||
};
|
||||
|
||||
server = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "enable hans server";
|
||||
};
|
||||
|
||||
ip = mkOption {
|
||||
type = types.str;
|
||||
ip = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "The assigned ip range";
|
||||
example = "198.51.100.0";
|
||||
};
|
||||
|
||||
respondToSystemPings = mkOption {
|
||||
type = types.bool;
|
||||
respondToSystemPings = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Force hans respond to ordinary pings";
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.str;
|
||||
extraConfig = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "Additional command line parameters";
|
||||
example = "-v";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.str;
|
||||
passwordFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "File that contains password";
|
||||
};
|
||||
@ -101,8 +97,8 @@ in
|
||||
|
||||
### implementation
|
||||
|
||||
config = mkIf (cfg.server.enable || cfg.clients != {}) {
|
||||
boot.kernel.sysctl = optionalAttrs cfg.server.respondToSystemPings {
|
||||
config = lib.mkIf (cfg.server.enable || cfg.clients != {}) {
|
||||
boot.kernel.sysctl = lib.optionalAttrs cfg.server.respondToSystemPings {
|
||||
"net.ipv4.icmp_echo_ignore_all" = 1;
|
||||
};
|
||||
|
||||
@ -115,23 +111,23 @@ in
|
||||
description = "hans client - ${name}";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
script = "${pkgs.hans}/bin/hans -f -u ${hansUser} ${cfg.extraConfig} -c ${cfg.server} ${optionalString (cfg.passwordFile != "") "-p $(cat \"${cfg.passwordFile}\")"}";
|
||||
script = "${pkgs.hans}/bin/hans -f -u ${hansUser} ${cfg.extraConfig} -c ${cfg.server} ${lib.optionalString (cfg.passwordFile != "") "-p $(cat \"${cfg.passwordFile}\")"}";
|
||||
serviceConfig = {
|
||||
RestartSec = "30s";
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
in
|
||||
listToAttrs (
|
||||
mapAttrsToList
|
||||
(name: value: nameValuePair "hans-${name}" (createHansClientService name value))
|
||||
lib.listToAttrs (
|
||||
lib.mapAttrsToList
|
||||
(name: value: lib.nameValuePair "hans-${name}" (createHansClientService name value))
|
||||
cfg.clients
|
||||
) // {
|
||||
hans = mkIf (cfg.server.enable) {
|
||||
hans = lib.mkIf (cfg.server.enable) {
|
||||
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} ${optionalString cfg.server.respondToSystemPings "-r"} ${optionalString (cfg.server.passwordFile != "") "-p $(cat \"${cfg.server.passwordFile}\")"}";
|
||||
script = "${pkgs.hans}/bin/hans -f -u ${hansUser} ${cfg.server.extraConfig} -s ${cfg.server.ip} ${lib.optionalString cfg.server.respondToSystemPings "-r"} ${lib.optionalString (cfg.server.passwordFile != "") "-p $(cat \"${cfg.server.passwordFile}\")"}";
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user