at 21.11-pre 2.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let cfg = config.services.gogoclient; 6in 7 8{ 9 10 ###### interface 11 12 options = { 13 services.gogoclient = { 14 enable = mkOption { 15 default = false; 16 type = types.bool; 17 description = '' 18 Enable the gogoCLIENT IPv6 tunnel. 19 ''; 20 }; 21 autorun = mkOption { 22 type = types.bool; 23 default = true; 24 description = '' 25 Whether to automatically start the tunnel. 26 ''; 27 }; 28 29 username = mkOption { 30 default = ""; 31 type = types.str; 32 description = '' 33 Your Gateway6 login name, if any. 34 ''; 35 }; 36 37 password = mkOption { 38 default = ""; 39 type = types.str; 40 description = '' 41 Path to a file (as a string), containing your gogoNET password, if any. 42 ''; 43 }; 44 45 server = mkOption { 46 type = types.str; 47 default = "anonymous.freenet6.net"; 48 example = "broker.freenet6.net"; 49 description = "The Gateway6 server to be used."; 50 }; 51 }; 52 }; 53 54 ###### implementation 55 56 config = mkIf cfg.enable { 57 boot.kernelModules = [ "tun" ]; 58 59 networking.enableIPv6 = true; 60 61 systemd.services.gogoclient = { 62 description = "ipv6 tunnel"; 63 64 after = [ "network.target" ]; 65 requires = [ "network.target" ]; 66 67 unitConfig.RequiresMountsFor = "/var/lib/gogoc"; 68 69 script = let authMethod = if cfg.password == "" then "anonymous" else "any"; in '' 70 mkdir -p -m 700 /var/lib/gogoc 71 cat ${pkgs.gogoclient}/share/${pkgs.gogoclient.name}/gogoc.conf.sample | \ 72 ${pkgs.gnused}/bin/sed \ 73 -e "s|^userid=|&${cfg.username}|" \ 74 -e "s|^passwd=|&${optionalString (cfg.password != "") "$(cat ${cfg.password})"}|" \ 75 -e "s|^server=.*|server=${cfg.server}|" \ 76 -e "s|^auth_method=.*|auth_method=${authMethod}|" \ 77 -e "s|^#log_file=|log_file=1|" > /var/lib/gogoc/gogoc.conf 78 cd /var/lib/gogoc 79 exec ${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf 80 ''; 81 } // optionalAttrs cfg.autorun { 82 wantedBy = [ "multi-user.target" ]; 83 }; 84 85 }; 86 87}