modules/hyprspace: revamp config
This commit is contained in:
parent
35aff0e1ce
commit
50ce107cbc
3 changed files with 13 additions and 17 deletions
|
@ -5,19 +5,20 @@ let
|
||||||
hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hypr) hosts;
|
hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hypr) hosts;
|
||||||
peersFormatted = builtins.mapAttrs (_: x: { "${x.hypr.addr}".id = x.hypr.id; }) hyprspaceCapableNodes;
|
peersFormatted = builtins.mapAttrs (_: x: { "${x.hypr.addr}".id = x.hypr.id; }) hyprspaceCapableNodes;
|
||||||
peersFiltered = lib.filterAttrs (name: _: name != hostName) peersFormatted;
|
peersFiltered = lib.filterAttrs (name: _: name != hostName) peersFormatted;
|
||||||
buildHyprspacePeerList = peers: pkgs.writeText "hyprspace-peers.yml" (builtins.toJSON peers);
|
peerList = lib.foldAttrs (n: _: n) null (builtins.attrValues peersFiltered);
|
||||||
peerList = buildHyprspacePeerList (lib.foldAttrs (n: _: n) null (builtins.attrValues peersFiltered));
|
|
||||||
myNode = hosts.${hostName};
|
myNode = hosts.${hostName};
|
||||||
listenPort = myNode.hypr.listenPort or 8001;
|
listenPort = myNode.hypr.listenPort or 8001;
|
||||||
|
|
||||||
precedingConfig = pkgs.writeText "hyprspace-interface.yml" ''
|
interfaceConfig = pkgs.writeText "hyprspace.yml" (builtins.toJSON {
|
||||||
interface:
|
interface = {
|
||||||
name: hyprspace
|
name = "hyprspace";
|
||||||
listen_port: ${builtins.toString listenPort}
|
listen_port = toString listenPort;
|
||||||
id: ${myNode.hypr.id}
|
inherit (myNode.hypr) id;
|
||||||
address: ${myNode.hypr.addr}/24
|
address = "${myNode.hypr.addr}/24";
|
||||||
private_key: !!binary |
|
private_key = "@HYPRSPACEPRIVATEKEY@";
|
||||||
'';
|
};
|
||||||
|
peers = peerList;
|
||||||
|
});
|
||||||
|
|
||||||
privateKeyFile = config.age.secrets.hyprspace-key.path;
|
privateKeyFile = config.age.secrets.hyprspace-key.path;
|
||||||
runConfig = "/run/hyprspace.yml";
|
runConfig = "/run/hyprspace.yml";
|
||||||
|
@ -33,14 +34,9 @@ in {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
test -e ${runConfig} && rm ${runConfig}
|
test -e ${runConfig} && rm ${runConfig}
|
||||||
touch ${runConfig}
|
cp ${interfaceConfig} ${runConfig}
|
||||||
chmod 0600 ${runConfig}
|
chmod 0600 ${runConfig}
|
||||||
|
${pkgs.replace-secret}/bin/replace-secret '@HYPRSPACEPRIVATEKEY@' "${privateKeyFile}" ${runConfig}
|
||||||
cat ${precedingConfig} >> ${runConfig}
|
|
||||||
sed 's/^/ /g' ${privateKeyFile} >> ${runConfig}
|
|
||||||
echo -n 'peers: ' >> ${runConfig}
|
|
||||||
cat ${peerList} >> ${runConfig}
|
|
||||||
|
|
||||||
chmod 0400 ${runConfig}
|
chmod 0400 ${runConfig}
|
||||||
'';
|
'';
|
||||||
environment.HYPRSPACE_SWARM_KEY = config.age.secrets.ipfs-swarm-key.path;
|
environment.HYPRSPACE_SWARM_KEY = config.age.secrets.ipfs-swarm-key.path;
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue