nixos/cjdns: add extraConfig option (#53502)

This commit is contained in:
Eric Litak 2019-08-18 09:47:56 -07:00 committed by Marek Mahut
parent e6fb350cf6
commit ccf3557015

View File

@ -44,9 +44,7 @@ let
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; };
# would be nice to merge 'cfg' with a //, cjdrouteConf = builtins.toJSON ( recursiveUpdate {
# but the json nesting is wacky.
cjdrouteConf = builtins.toJSON ( {
admin = { admin = {
bind = cfg.admin.bind; bind = cfg.admin.bind;
password = "@CJDNS_ADMIN_PASSWORD@"; password = "@CJDNS_ADMIN_PASSWORD@";
@ -71,7 +69,7 @@ let
security = [ { exemptAngel = 1; setuser = "nobody"; } ]; security = [ { exemptAngel = 1; setuser = "nobody"; } ];
}); } cfg.extraConfig);
in in
@ -91,6 +89,16 @@ in
''; '';
}; };
extraConfig = mkOption {
type = types.attrs;
default = {};
example = { router.interface.tunDevice = "tun10"; };
description = ''
Extra configuration, given as attrs, that will be merged recursively
with the rest of the JSON generated by this module, at the root node.
'';
};
confFile = mkOption { confFile = mkOption {
type = types.nullOr types.path; type = types.nullOr types.path;
default = null; default = null;
@ -246,7 +254,10 @@ in
if cfg.confFile != null then "${pkg}/bin/cjdroute < ${cfg.confFile}" else if cfg.confFile != null then "${pkg}/bin/cjdroute < ${cfg.confFile}" else
'' ''
source /etc/cjdns.keys source /etc/cjdns.keys
echo '${cjdrouteConf}' | sed \ (cat <<'EOF'
${cjdrouteConf}
EOF
) | sed \
-e "s/@CJDNS_ADMIN_PASSWORD@/$CJDNS_ADMIN_PASSWORD/g" \ -e "s/@CJDNS_ADMIN_PASSWORD@/$CJDNS_ADMIN_PASSWORD/g" \
-e "s/@CJDNS_PRIVATE_KEY@/$CJDNS_PRIVATE_KEY/g" \ -e "s/@CJDNS_PRIVATE_KEY@/$CJDNS_PRIVATE_KEY/g" \
| ${pkg}/bin/cjdroute | ${pkg}/bin/cjdroute