modules/hyprspace, hosts: new config format, new cli interface, new addressing scheme

This commit is contained in:
Max Headroom 2023-10-27 01:17:50 +02:00
parent d058c17fc3
commit 153f144dc3
5 changed files with 29 additions and 30 deletions

View file

@ -6,7 +6,6 @@ tools: {
hypr = { hypr = {
id = "QmfJ5Tv2z9jFv9Aocevyn6QqRcfm9eYQZhvYvmAVfACfuM"; id = "QmfJ5Tv2z9jFv9Aocevyn6QqRcfm9eYQZhvYvmAVfACfuM";
addr = "10.100.3.7";
listenPort = 443; listenPort = 443;
routes = [ routes = [
"10.0.0.0/24" "10.0.0.0/24"

View file

@ -76,7 +76,7 @@ in
enable = true; enable = true;
externalInterface = "enp24s0"; externalInterface = "enp24s0";
internalIPs = [ internalIPs = [
"10.100.3.0/24" "100.64.0.0/16"
]; ];
}; };
} }

View file

@ -14,7 +14,6 @@ in with tools.dns; {
}; };
hypr = { hypr = {
id = "QmYs4xNBby2fTs8RnzfXEk161KD4mftBfCiR8yXtgGPj4J"; id = "QmYs4xNBby2fTs8RnzfXEk161KD4mftBfCiR8yXtgGPj4J";
addr = "10.100.3.5";
routes = [ routes = [
"10.1.0.1/32" "10.1.0.1/32"
"10.10.0.0/16" "10.10.0.0/16"
@ -28,7 +27,9 @@ in with tools.dns; {
}; };
hypr = { hypr = {
id = "QmbrAHuh4RYcyN9fWePCZMVmQjbaNXtyvrDCWz4VrchbXh"; id = "QmbrAHuh4RYcyN9fWePCZMVmQjbaNXtyvrDCWz4VrchbXh";
addr = "10.100.3.9"; routes = [
"10.1.0.9/32"
];
}; };
}; };
checkmate = { checkmate = {
@ -38,7 +39,9 @@ in with tools.dns; {
}; };
hypr = { hypr = {
id = "12D3KooWL84sAtq1QTYwb7gVbhSNX5ZUfVt4kgYKz8pdif1zpGUh"; id = "12D3KooWL84sAtq1QTYwb7gVbhSNX5ZUfVt4kgYKz8pdif1zpGUh";
addr = "10.100.3.32"; routes = [
"10.1.0.32/32"
];
}; };
}; };
thunderskin = { thunderskin = {
@ -48,13 +51,17 @@ in with tools.dns; {
}; };
hypr = { hypr = {
id = "12D3KooWB9AUPorFoACkWbphyargRBV9osJsYuQDumtQ85j7Aqmg"; id = "12D3KooWB9AUPorFoACkWbphyargRBV9osJsYuQDumtQ85j7Aqmg";
addr = "10.100.3.4"; routes = [
"10.1.0.4/32"
];
}; };
}; };
loki = { loki = {
hypr = { hypr = {
id = "QmYZ4qA1W9hEZgDKDgKgjNge1ZX3Z25gVGxs34uEoLghgq"; id = "QmYZ4qA1W9hEZgDKDgKgjNge1ZX3Z25gVGxs34uEoLghgq";
addr = "10.100.3.10"; routes = [
"10.100.3.10/32" # old
];
}; };
}; };
styx = { styx = {

View file

@ -6,7 +6,6 @@ tools: {
hypr = { hypr = {
id = "QmccBLgGP3HR36tTkwSYZX3KDv2EXb1MvYwGVs6PbpbHv9"; id = "QmccBLgGP3HR36tTkwSYZX3KDv2EXb1MvYwGVs6PbpbHv9";
addr = "10.100.3.13";
}; };
nixos = import ./system.nix; nixos = import ./system.nix;

View file

@ -3,33 +3,32 @@ let
inherit (config.networking) hostName; inherit (config.networking) hostName;
inherit (inputs.depot.packages.${pkgs.system}) hyprspace; inherit (inputs.depot.packages.${pkgs.system}) hyprspace;
hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hypr) hosts; hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hypr) hosts;
peersFormatted = builtins.mapAttrs (_: x: { peersFormatted = builtins.mapAttrs (name: x: {
inherit name;
inherit (x.hypr) id; inherit (x.hypr) id;
routes = map (net: { inherit net; }) ((x.hypr.routes or []) ++ [ "${x.hypr.addr}/32" ]); routes = map (net: { inherit net; }) (x.hypr.routes or []);
}) hyprspaceCapableNodes; }) hyprspaceCapableNodes;
peersFiltered = lib.filterAttrs (name: _: name != hostName) peersFormatted; peersFiltered = lib.filterAttrs (name: _: name != hostName) peersFormatted;
peerList = builtins.attrValues peersFiltered; peerList = builtins.attrValues peersFiltered;
myNode = hosts.${hostName}; myNode = hosts.${hostName};
listenPort = myNode.hypr.listenPort or 8001; listenPort = myNode.hypr.listenPort or 8001;
routes' = map (x: lib.genAttrs (x.hypr.routes or []) (_: { ip = x.hypr.addr; })) (builtins.attrValues hyprspaceCapableNodes); interfaceConfig = pkgs.writeText "hyprspace.json" (builtins.toJSON {
routes = builtins.foldl' (x: y: x // y) {} (lib.flatten routes'); listenAddresses = let
port = toString listenPort;
interfaceConfig = pkgs.writeText "hyprspace.yml" (builtins.toJSON { in [
interface = { "/ip4/0.0.0.0/tcp/${port}"
name = "hyprspace"; "/ip4/0.0.0.0/udp/${port}/quic-v1"
listen_port = listenPort; "/ip6/::/tcp/${port}"
inherit (myNode.hypr) id; "/ip6/::/udp/${port}/quic-v1"
address = "${myNode.hypr.addr}/24"; ];
private_key = "@HYPRSPACEPRIVATEKEY@"; privateKey = "@HYPRSPACEPRIVATEKEY@";
};
peers = peerList; peers = peerList;
}); });
privateKeyFile = config.age.secrets.hyprspace-key.path; privateKeyFile = config.age.secrets.hyprspace-key.path;
runConfig = "/run/hyprspace.yml"; runConfig = "/run/hyprspace.json";
in { in {
networking.hosts = lib.mapAttrs' (k: v: lib.nameValuePair (v.hypr.addr) ([k "${k}.hypr"])) hyprspaceCapableNodes;
age.secrets.hyprspace-key = { age.secrets.hyprspace-key = {
file = ../../secrets/hyprspace-key- + "${hostName}.age"; file = ../../secrets/hyprspace-key- + "${hostName}.age";
mode = "0400"; mode = "0400";
@ -49,11 +48,6 @@ in {
${pkgs.replace-secret}/bin/replace-secret '@HYPRSPACEPRIVATEKEY@' "${privateKeyFile}" ${runConfig} ${pkgs.replace-secret}/bin/replace-secret '@HYPRSPACEPRIVATEKEY@' "${privateKeyFile}" ${runConfig}
chmod 0400 ${runConfig} chmod 0400 ${runConfig}
''; '';
postStart = ''
sleep 1
'' + lib.concatStringsSep "\n" (lib.mapAttrsToList (net: v:
"${pkgs.iproute2}/bin/ip route add ${net} via ${v.ip} dev hyprspace metric 30000"
) routes);
environment = lib.optionalAttrs config.services.kubo.enable { environment = lib.optionalAttrs config.services.kubo.enable {
HYPRSPACE_IPFS_API = config.services.kubo.settings.Addresses.API; HYPRSPACE_IPFS_API = config.services.kubo.settings.Addresses.API;
}; };
@ -61,8 +55,8 @@ in {
Group = "wheel"; Group = "wheel";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "5s"; RestartSec = "5s";
ExecStart = "${hyprspace}/bin/hyprspace up hyprspace -f -c ${runConfig}"; ExecStart = "${hyprspace}/bin/hyprspace up -c ${runConfig}";
ExecStop = "${hyprspace}/bin/hyprspace down hyprspace -c ${runConfig}"; ExecStopPost = "${pkgs.coreutils}/bin/rm -f /run/hyprspace-rpc.hyprspace.sock";
ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID";
}; };
}; };