2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-04 12:58:22 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2012-03-04 12:58:22 +00:00
|
|
|
|
|
|
|
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.
|
2012-03-04 12:58:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
autorun = mkOption {
|
|
|
|
default = true;
|
2013-10-31 12:26:06 +00:00
|
|
|
description = ''
|
|
|
|
Whether to automatically start the tunnel.
|
|
|
|
'';
|
2012-03-04 12:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
2013-10-31 12:26:06 +00:00
|
|
|
description = ''
|
2012-03-04 12:58:22 +00:00
|
|
|
Your Gateway6 login name, if any.
|
2013-10-31 12:26:06 +00:00
|
|
|
'';
|
2012-03-04 12:58:22 +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.
|
|
|
|
'';
|
2012-03-04 12:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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.";
|
2012-03-04 12:58:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "tun" ];
|
|
|
|
|
2012-03-04 18:44:47 +00:00
|
|
|
networking.enableIPv6 = true;
|
2012-03-04 12:58:22 +00:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.gogoclient = {
|
2012-03-04 12:58:22 +00:00
|
|
|
description = "ipv6 tunnel";
|
2012-12-26 22:49:22 +00:00
|
|
|
|
|
|
|
after = [ "network.target" ];
|
2012-12-27 12:38:37 +00:00
|
|
|
requires = [ "network.target" ];
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/gogoc";
|
2012-12-26 22:49:22 +00:00
|
|
|
|
2012-12-27 12:38:37 +00:00
|
|
|
script = let authMethod = if cfg.password == "" then "anonymous" else "any"; in ''
|
2012-12-26 22:49:22 +00:00
|
|
|
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
|
2012-12-27 12:38:37 +00:00
|
|
|
cd /var/lib/gogoc
|
|
|
|
exec ${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf
|
2012-07-31 19:00:58 +01:00
|
|
|
'';
|
2012-12-26 22:49:22 +00:00
|
|
|
} // optionalAttrs cfg.autorun {
|
2014-11-26 19:19:31 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2012-03-04 12:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|