mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 04:43:09 +03:00
Merge pull request #21592 from joachifm/cjdns-optional-extraHosts
cjdns service: optional extraHosts
This commit is contained in:
commit
9e0dc9fa7c
@ -19,21 +19,30 @@ let
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
description = "Public key at the opposite end of the tunnel.";
|
description = "Public key at the opposite end of the tunnel.";
|
||||||
};
|
};
|
||||||
|
hostname = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "foobar.hype";
|
||||||
|
type = types.str;
|
||||||
|
description = "Optional hostname to add to /etc/hosts; prevents reverse lookup failures.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# check for the required attributes, otherwise
|
# Additional /etc/hosts entries for peers with an associated hostname
|
||||||
# permit attributes not undefined here
|
cjdnsExtraHosts = import (pkgs.runCommand "cjdns-hosts" {}
|
||||||
checkPeers = x:
|
# Generate a builder that produces an output usable as a Nix string value
|
||||||
x // {
|
''
|
||||||
connectTo = mapAttrs
|
exec >$out
|
||||||
(name: value:
|
echo \'\'
|
||||||
if !hasAttr "publicKey" value then abort "cjdns peer ${name} missing a publicKey" else
|
${concatStringsSep "\n" (mapAttrsToList (k: v:
|
||||||
if !hasAttr "password" value then abort "cjdns peer ${name} missing a password" else
|
optionalString (v.hostname != "")
|
||||||
value
|
"echo $(${pkgs.cjdns}/bin/publictoip6 ${v.publicKey}) ${v.hostname}")
|
||||||
)
|
(cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo))}
|
||||||
x.connectTo;
|
echo \'\'
|
||||||
};
|
'');
|
||||||
|
|
||||||
|
parseModules = x:
|
||||||
|
x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
|
||||||
|
|
||||||
# would be nice to merge 'cfg' with a //,
|
# would be nice to merge 'cfg' with a //,
|
||||||
# but the json nesting is wacky.
|
# but the json nesting is wacky.
|
||||||
@ -44,8 +53,8 @@ let
|
|||||||
};
|
};
|
||||||
authorizedPasswords = map (p: { password = p; }) cfg.authorizedPasswords;
|
authorizedPasswords = map (p: { password = p; }) cfg.authorizedPasswords;
|
||||||
interfaces = {
|
interfaces = {
|
||||||
ETHInterface = if (cfg.ETHInterface.bind != "") then [ (checkPeers cfg.ETHInterface) ] else [ ];
|
ETHInterface = if (cfg.ETHInterface.bind != "") then [ (parseModules cfg.ETHInterface) ] else [ ];
|
||||||
UDPInterface = if (cfg.UDPInterface.bind != "") then [ (checkPeers cfg.UDPInterface) ] else [ ];
|
UDPInterface = if (cfg.UDPInterface.bind != "") then [ (parseModules cfg.UDPInterface) ] else [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
privateKey = "@CJDNS_PRIVATE_KEY@";
|
privateKey = "@CJDNS_PRIVATE_KEY@";
|
||||||
@ -125,11 +134,11 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
connectTo = mkOption {
|
connectTo = mkOption {
|
||||||
type = types.attrsOf (types.attrsOf types.str);
|
type = types.attrsOf ( types.submodule ( connectToSubmodule ) );
|
||||||
default = { };
|
default = { };
|
||||||
example = {
|
example = {
|
||||||
"192.168.1.1:27313" = {
|
"192.168.1.1:27313" = {
|
||||||
user = "foobar";
|
hostname = "homer.hype";
|
||||||
password = "5kG15EfpdcKNX3f2GSQ0H1HC7yIfxoCoImnO5FHM";
|
password = "5kG15EfpdcKNX3f2GSQ0H1HC7yIfxoCoImnO5FHM";
|
||||||
publicKey = "371zpkgs8ss387tmr81q04mp0hg1skb51hw34vk1cq644mjqhup0.k";
|
publicKey = "371zpkgs8ss387tmr81q04mp0hg1skb51hw34vk1cq644mjqhup0.k";
|
||||||
};
|
};
|
||||||
@ -170,11 +179,11 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
connectTo = mkOption {
|
connectTo = mkOption {
|
||||||
type = types.attrsOf (types.attrsOf types.str);
|
type = types.attrsOf ( types.submodule ( connectToSubmodule ) );
|
||||||
default = { };
|
default = { };
|
||||||
example = {
|
example = {
|
||||||
"01:02:03:04:05:06" = {
|
"01:02:03:04:05:06" = {
|
||||||
user = "foobar";
|
hostname = "homer.hype";
|
||||||
password = "5kG15EfpdcKNX3f2GSQ0H1HC7yIfxoCoImnO5FHM";
|
password = "5kG15EfpdcKNX3f2GSQ0H1HC7yIfxoCoImnO5FHM";
|
||||||
publicKey = "371zpkgs8ss387tmr81q04mp0hg1skb51hw34vk1cq644mjqhup0.k";
|
publicKey = "371zpkgs8ss387tmr81q04mp0hg1skb51hw34vk1cq644mjqhup0.k";
|
||||||
};
|
};
|
||||||
@ -186,6 +195,16 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
addExtraHosts = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to add cjdns peers with an associated hostname to
|
||||||
|
<filename>/etc/hosts</filename>. Beware that enabling this
|
||||||
|
incurs heavy eval-time costs.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -248,6 +267,8 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
networking.extraHosts = mkIf cfg.addExtraHosts cjdnsExtraHosts;
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
|
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
|
||||||
message = "Neither cjdns.ETHInterface.bind nor cjdns.UDPInterface.bind defined.";
|
message = "Neither cjdns.ETHInterface.bind nor cjdns.UDPInterface.bind defined.";
|
||||||
|
Loading…
Reference in New Issue
Block a user