From 1c3025053614784ad57fe0447d54ad6cc0b44c90 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 2 Jun 2024 20:06:10 +0200 Subject: [PATCH] modules/hyprspace: use upstream module --- hosts/TITAN/extras/fbi-downloader.nix | 2 +- hosts/TITAN/extras/invokeai.nix | 2 +- modules/cockpit/default.nix | 2 +- modules/hyprspace/default.nix | 62 ++++++++------------------- modules/hyprspace/options.nix | 10 ----- 5 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 modules/hyprspace/options.nix diff --git a/hosts/TITAN/extras/fbi-downloader.nix b/hosts/TITAN/extras/fbi-downloader.nix index 79d9568..989a02d 100644 --- a/hosts/TITAN/extras/fbi-downloader.nix +++ b/hosts/TITAN/extras/fbi-downloader.nix @@ -39,5 +39,5 @@ networking.firewall.interfaces.tungsten.allowedTCPPorts = [ 9091 ]; - services.hyprspace.services.fbi-download = "/tcp/${toString config.services.transmission.settings.rpc-port}"; + services.hyprspace.settings.services.fbi-download = "/tcp/${toString config.services.transmission.settings.rpc-port}"; } diff --git a/hosts/TITAN/extras/invokeai.nix b/hosts/TITAN/extras/invokeai.nix index 869b3db..f5538e2 100644 --- a/hosts/TITAN/extras/invokeai.nix +++ b/hosts/TITAN/extras/invokeai.nix @@ -13,5 +13,5 @@ }; }; - services.hyprspace.services.invokeai = "/tcp/${toString config.services.invokeai.settings.port}"; + services.hyprspace.settings.services.invokeai = "/tcp/${toString config.services.invokeai.settings.port}"; } diff --git a/modules/cockpit/default.nix b/modules/cockpit/default.nix index 2a04adc..7998fe7 100644 --- a/modules/cockpit/default.nix +++ b/modules/cockpit/default.nix @@ -17,5 +17,5 @@ in }; }; - services.hyprspace.services.manage = "/tcp/${toString port}"; + services.hyprspace.settings.services.manage = "/tcp/${toString port}"; } diff --git a/modules/hyprspace/default.nix b/modules/hyprspace/default.nix index 86c2069..a415e1a 100644 --- a/modules/hyprspace/default.nix +++ b/modules/hyprspace/default.nix @@ -1,7 +1,6 @@ { inputs, pkgs, lib, hosts, config, ... }: let inherit (config.networking) hostName; - hyprspace = inputs.hyprspace.packages.${pkgs.system}.default; hyprspaceCapableNodes = lib.filterAttrs (_: host: host ? hyprspace) hosts; peersFormatted = builtins.mapAttrs (name: x: { inherit name; @@ -12,63 +11,38 @@ let peerList = builtins.attrValues peersFiltered; myNode = hosts.${hostName}; listenPort = myNode.hyprspace.listenPort or 8001; - - 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; - inherit (config.services.hyprspace) services; - }); - privateKeyFile = config.age.secrets.hyprspace-key.path; - runConfig = "/run/hyprspace.json"; in { imports = [ - ./options.nix + inputs.hyprspace.nixosModules.default ]; age.secrets.hyprspace-key = { file = ../../secrets/hyprspace-key- + "${hostName}.age"; mode = "0400"; }; - environment.systemPackages = [ - hyprspace - ]; + systemd.services.hyprspace = { - enable = true; - wantedBy = [ "multi-user.target" ]; - wants = [ "network-online.target" ]; - after = [ "network-online.target" ]; - preStart = '' - test -e ${runConfig} && rm ${runConfig} - cp ${interfaceConfig} ${runConfig} - chmod 0600 ${runConfig} - ${pkgs.replace-secret}/bin/replace-secret '@HYPRSPACEPRIVATEKEY@' "${privateKeyFile}" ${runConfig} - chmod 0400 ${runConfig} - ''; environment = lib.optionalAttrs config.services.kubo.enable { HYPRSPACE_IPFS_API = config.services.kubo.settings.Addresses.API; }; - serviceConfig = { - Group = "wheel"; - Restart = "on-failure"; - RestartSec = "5s"; - 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"; + }; + + 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; }; }; - networking.firewall = { - allowedTCPPorts = [ listenPort ]; - allowedUDPPorts = [ listenPort ]; - trustedInterfaces = [ "hyprspace" ]; - }; + networking.networkmanager.dispatcherScripts = [{ source = pkgs.writeShellScript "hyprspace-reconnect.sh" '' [[ "$2" != "up" ]] && exit 0 diff --git a/modules/hyprspace/options.nix b/modules/hyprspace/options.nix deleted file mode 100644 index 7410677..0000000 --- a/modules/hyprspace/options.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ lib, ... }: - -{ - options.services.hyprspace = { - services = lib.mkOption { - type = lib.types.attrsOf lib.types.path; - default = {}; - }; - }; -}