cjdns service: refactor cjdns hosts builder
The old version would export two lists to a bash builder and do pairwise processing on the bash side. In the new version we instead generate a logic free builder on the Nix side. This is not only conceptually simpler but reduces the amount of code and intermediate values.
This commit is contained in:
parent
9654e09b5a
commit
8180922d23
|
@ -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
|
|
|
@ -28,21 +28,18 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
peers = mapAttrsToList (n: v: v) (cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo);
|
# Additional /etc/hosts entries for peers with an associated hostname
|
||||||
|
cjdnsExtraHosts = import (pkgs.runCommand "cjdns-hosts" {}
|
||||||
pubs = toString (map (p: if p.hostname == "" then "" else p.publicKey) peers);
|
# Generate a builder that produces an output usable as a Nix string value
|
||||||
hosts = toString (map (p: if p.hostname == "" then "" else p.hostname) peers);
|
''
|
||||||
|
exec >$out
|
||||||
cjdnsHosts =
|
echo \'\'
|
||||||
if hosts != "" then
|
${concatStringsSep "\n" (mapAttrsToList (k: v:
|
||||||
import (pkgs.stdenv.mkDerivation {
|
optionalString (v.hostname != "")
|
||||||
name = "cjdns-hosts";
|
"echo $(${pkgs.cjdns}/bin/publictoip6 ${x.key}) ${x.host}")
|
||||||
builder = ./cjdns-hosts.sh;
|
(cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo))}
|
||||||
|
echo \'\'
|
||||||
inherit (pkgs) cjdns;
|
'');
|
||||||
inherit pubs hosts;
|
|
||||||
})
|
|
||||||
else "";
|
|
||||||
|
|
||||||
parseModules = x:
|
parseModules = x:
|
||||||
x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
|
x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
|
||||||
|
@ -254,7 +251,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.extraHosts = "${cjdnsHosts}";
|
networking.extraHosts = cjdnsExtraHosts;
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
|
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
|
||||||
|
|
Loading…
Reference in New Issue