config/modules/hyprspace/default.nix

60 lines
1.7 KiB
Nix
Raw Permalink Normal View History

2022-02-05 21:42:36 +02:00
{ inputs, pkgs, lib, hosts, config, ... }:
let
inherit (config.networking) hostName;
2023-10-27 21:42:34 +03:00
hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hyprspace) hosts;
peersFormatted = builtins.mapAttrs (name: x: {
inherit name;
2023-10-27 21:42:34 +03:00
inherit (x.hyprspace) id;
routes = map (net: { inherit net; }) (x.hyprspace.routes or []);
}) hyprspaceCapableNodes;
2022-02-05 21:42:36 +02:00
peersFiltered = lib.filterAttrs (name: _: name != hostName) peersFormatted;
peerList = builtins.attrValues peersFiltered;
2022-02-05 21:42:36 +02:00
myNode = hosts.${hostName};
2023-10-27 21:42:34 +03:00
listenPort = myNode.hyprspace.listenPort or 8001;
2022-02-05 21:42:36 +02:00
privateKeyFile = config.age.secrets.hyprspace-key.path;
in {
imports = [
2024-06-02 21:06:10 +03:00
inputs.hyprspace.nixosModules.default
];
2022-02-05 21:42:36 +02:00
age.secrets.hyprspace-key = {
file = ../../secrets/hyprspace-key- + "${hostName}.age";
mode = "0400";
};
2024-06-02 21:06:10 +03:00
2022-02-05 21:42:36 +02:00
systemd.services.hyprspace = {
2022-11-13 03:12:44 +02:00
environment = lib.optionalAttrs config.services.kubo.enable {
2022-10-30 15:10:57 +02:00
HYPRSPACE_IPFS_API = config.services.kubo.settings.Addresses.API;
2022-11-13 03:12:44 +02:00
};
2022-02-05 21:42:36 +02:00
};
2024-06-02 21:06:10 +03:00
services.hyprspace = {
enable = true;
inherit privateKeyFile;
settings = {
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"
];
peers = peerList;
};
2022-02-05 21:42:36 +02:00
};
2024-06-02 21:06:10 +03:00
2022-02-05 21:42:36 +02:00
networking.networkmanager.dispatcherScripts = [{
source = pkgs.writeShellScript "hyprspace-reconnect.sh" ''
[[ "$2" != "up" ]] && exit 0
PATH=${pkgs.systemd}/bin:$PATH
case $1 in
wl*|en*)
systemctl reload-or-restart --no-block hyprspace.service;;
2022-02-05 21:42:36 +02:00
esac
exit 0
'';
type = "basic";
}];
}