1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-24 19:08:30 +00:00
nixpkgs/nixos/modules/services/networking/gogoclient.nix

85 lines
2.1 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let cfg = config.services.gogoclient;
in
{
###### interface
options = {
services.gogoclient = {
enable = mkOption {
default = false;
type = types.bool;
description = ''
2013-10-31 12:26:06 +00:00
Enable the gogoCLIENT IPv6 tunnel.
'';
};
autorun = mkOption {
default = true;
2013-10-31 12:26:06 +00:00
description = ''
Whether to automatically start the tunnel.
'';
};
username = mkOption {
default = "";
2013-10-31 12:26:06 +00:00
description = ''
Your Gateway6 login name, if any.
2013-10-31 12:26:06 +00:00
'';
};
password = mkOption {
default = "";
type = types.string;
2013-10-31 12:26:06 +00:00
description = ''
Path to a file (as a string), containing your gogoNET password, if any.
'';
};
server = mkOption {
default = "anonymous.freenet6.net";
example = "broker.freenet6.net";
2013-10-31 12:26:06 +00:00
description = "The Gateway6 server to be used.";
};
};
};
###### implementation
config = mkIf cfg.enable {
boot.kernelModules = [ "tun" ];
networking.enableIPv6 = true;
systemd.services.gogoclient = {
description = "ipv6 tunnel";
after = [ "network.target" ];
requires = [ "network.target" ];
unitConfig.RequiresMountsFor = "/var/lib/gogoc";
script = let authMethod = if cfg.password == "" then "anonymous" else "any"; in ''
mkdir -p -m 700 /var/lib/gogoc
cat ${pkgs.gogoclient}/share/${pkgs.gogoclient.name}/gogoc.conf.sample | \
${pkgs.gnused}/bin/sed \
-e "s|^userid=|&${cfg.username}|" \
-e "s|^passwd=|&${optionalString (cfg.password != "") "$(cat ${cfg.password})"}|" \
-e "s|^server=.*|server=${cfg.server}|" \
-e "s|^auth_method=.*|auth_method=${authMethod}|" \
-e "s|^#log_file=|log_file=1|" > /var/lib/gogoc/gogoc.conf
cd /var/lib/gogoc
exec ${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf
'';
} // optionalAttrs cfg.autorun {
2014-11-26 19:19:31 +00:00
wantedBy = [ "multi-user.target" ];
};
};
}