Merge pull request #19875 from joachifm/cjdns-for-upstream

Cjdns module enhancments
This commit is contained in:
Joachim F 2016-10-28 13:01:58 +02:00 committed by GitHub
commit 1da6dd3eee
2 changed files with 28 additions and 38 deletions

View File

@ -1,11 +0,0 @@
pubs=($pubs)
hosts=($hosts)
lines="''\n"
for ((i = 0; i < ${#pubs[*]}; i++)); do
addr=$($cjdns/bin/publictoip6 ${pubs[i]})
lines="${lines}$addr ${hosts[i]}\n"
done
lines="${lines}''"
echo -ne $lines > $out

View File

@ -28,21 +28,18 @@ let
};
};
peers = mapAttrsToList (n: v: v) (cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo);
pubs = toString (map (p: if p.hostname == "" then "" else p.publicKey) peers);
hosts = toString (map (p: if p.hostname == "" then "" else p.hostname) peers);
cjdnsHosts =
if hosts != "" then
import (pkgs.stdenv.mkDerivation {
name = "cjdns-hosts";
builder = ./cjdns-hosts.sh;
inherit (pkgs) cjdns;
inherit pubs hosts;
})
else "";
# Additional /etc/hosts entries for peers with an associated hostname
cjdnsExtraHosts = import (pkgs.runCommand "cjdns-hosts" {}
# Generate a builder that produces an output usable as a Nix string value
''
exec >$out
echo \'\'
${concatStringsSep "\n" (mapAttrsToList (k: v:
optionalString (v.hostname != "")
"echo $(${pkgs.cjdns}/bin/publictoip6 ${x.key}) ${x.host}")
(cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo))}
echo \'\'
'');
parseModules = x:
x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
@ -95,8 +92,8 @@ in
};
confFile = mkOption {
type = types.str;
default = "";
type = types.nullOr types.path;
default = null;
example = "/etc/cjdroute.conf";
description = ''
Ignore all other cjdns options and load configuration from this file.
@ -112,14 +109,14 @@ in
"49275fut6tmzu354pq70sr5b95qq0vj"
];
description = ''
Any remote cjdns nodes that offer these passwords on
Any remote cjdns nodes that offer these passwords on
connection will be allowed to route through this node.
'';
};
admin = {
bind = mkOption {
type = types.string;
type = types.str;
default = "127.0.0.1:11234";
description = ''
Bind the administration port to this address and port.
@ -129,7 +126,7 @@ in
UDPInterface = {
bind = mkOption {
type = types.string;
type = types.str;
default = "";
example = "192.168.1.32:43211";
description = ''
@ -154,6 +151,7 @@ in
ETHInterface = {
bind = mkOption {
type = types.str;
default = "";
example = "eth0";
description =
@ -201,7 +199,7 @@ in
};
config = mkIf config.services.cjdns.enable {
config = mkIf cfg.enable {
boot.kernelModules = [ "tun" ];
@ -212,7 +210,7 @@ in
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
preStart = if cfg.confFile != "" then "" else ''
preStart = if cfg.confFile != null then "" else ''
[ -e /etc/cjdns.keys ] && source /etc/cjdns.keys
if [ -z "$CJDNS_PRIVATE_KEY" ]; then
@ -228,13 +226,13 @@ in
fi
if [ -z "$CJDNS_ADMIN_PASSWORD" ]; then
echo "CJDNS_ADMIN_PASSWORD=$(${pkgs.coreutils}/bin/head -c 96 /dev/urandom | ${pkgs.coreutils}/bin/tr -dc A-Za-z0-9)" \
echo "CJDNS_ADMIN_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 96)" \
>> /etc/cjdns.keys
fi
'';
script = (
if cfg.confFile != "" then "${pkg}/bin/cjdroute < ${cfg.confFile}" else
if cfg.confFile != null then "${pkg}/bin/cjdroute < ${cfg.confFile}" else
''
source /etc/cjdns.keys
echo '${cjdrouteConf}' | sed \
@ -247,13 +245,16 @@ in
serviceConfig = {
Type = "forking";
Restart = "on-failure";
ProtectHome = true;
PrivateTmp = true;
};
};
networking.extraHosts = "${cjdnsHosts}";
networking.extraHosts = cjdnsExtraHosts;
assertions = [
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != "" );
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
message = "Neither cjdns.ETHInterface.bind nor cjdns.UDPInterface.bind defined.";
}
{ assertion = config.networking.enableIPv6;