2012-03-04 13:58:22 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let cfg = config.services.gogoclient;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.gogoclient = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enable the gogoclient ipv6 tunnel.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
autorun = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "
|
|
|
|
Switch to false to create upstart-job and configuration,
|
|
|
|
but not run it automatically
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Your Gateway6 login name, if any.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
|
|
|
description = "
|
|
|
|
Path to a file (as a string), containing your gogonet password, if any.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
default = "anonymous.freenet6.net";
|
|
|
|
example = "broker.freenet6.net";
|
|
|
|
description = "
|
|
|
|
Used Gateway6 server.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "tun" ];
|
|
|
|
|
2012-03-04 19:44:47 +01:00
|
|
|
networking.enableIPv6 = true;
|
2012-03-04 13:58:22 +01:00
|
|
|
|
2012-12-26 23:49:22 +01:00
|
|
|
boot.systemd.services.gogoclient = {
|
2012-03-04 13:58:22 +01:00
|
|
|
description = "ipv6 tunnel";
|
2012-12-26 23:49:22 +01:00
|
|
|
|
|
|
|
after = [ "network.target" ];
|
2012-12-27 13:38:37 +01:00
|
|
|
requires = [ "network.target" ];
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/gogoc";
|
2012-12-26 23:49:22 +01:00
|
|
|
|
2012-12-27 13:38:37 +01:00
|
|
|
script = let authMethod = if cfg.password == "" then "anonymous" else "any"; in ''
|
2012-12-26 23:49:22 +01: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 13:38:37 +01:00
|
|
|
cd /var/lib/gogoc
|
|
|
|
exec ${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf
|
2012-07-31 20:00:58 +02:00
|
|
|
'';
|
2012-12-26 23:49:22 +01:00
|
|
|
} // optionalAttrs cfg.autorun {
|
|
|
|
wantedBy = [ "ip-up.target" ];
|
|
|
|
partOf = [ "ip-up.target" ];
|
2012-03-04 13:58:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|