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 = {
id = "QmfJ5Tv2z9jFv9Aocevyn6QqRcfm9eYQZhvYvmAVfACfuM";
addr = "10.100.3.7";
listenPort = 443;
routes = [
"10.0.0.0/24"

View file

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

View file

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

View file

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

View file

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