diff options
Diffstat (limited to '')
-rw-r--r-- | modules/nixos/ipfs.nix | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/modules/nixos/ipfs.nix b/modules/nixos/ipfs.nix index 99ce6c9..cd28372 100644 --- a/modules/nixos/ipfs.nix +++ b/modules/nixos/ipfs.nix @@ -5,13 +5,15 @@ this, ... }: -with lib; let +with lib; +let cfg = config.nixfiles.modules.ipfs; gatewayDefaultPort = 6001; apiDefaultPort = 5001; swarmDefaultPort = 4001; -in { +in +{ options.nixfiles.modules.ipfs = { enable = mkEnableOption "IPFS daemon"; @@ -24,19 +26,13 @@ in { gatewayPort = mkOption { description = "Gateway port."; type = with types; port; - default = - if this.isHeadless - then gatewayDefaultPort + 990 - else gatewayDefaultPort; + default = if this.isHeadless then gatewayDefaultPort + 990 else gatewayDefaultPort; }; apiPort = mkOption { description = "API port."; type = with types; port; - default = - if this.isHeadless - then apiDefaultPort + 990 - else apiDefaultPort; + default = if this.isHeadless then apiDefaultPort + 990 else apiDefaultPort; }; swarmPort = mkOption { @@ -86,22 +82,25 @@ in { "/ip4/10.0.0.0/ipcidr/8" "/ip6/fc00::/ipcidr/7" ]; - in { + in + { Addresses = { API = "/ip4/127.0.0.1/tcp/${toString cfg.apiPort}"; Gateway = "/ip4/127.0.0.1/tcp/${toString cfg.gatewayPort}"; - Swarm = let - port = toString cfg.swarmPort; - in [ - "/ip4/0.0.0.0/tcp/${port}" - "/ip6/::/tcp/${port}" - "/ip4/0.0.0.0/udp/${port}/quic" - "/ip4/0.0.0.0/udp/${port}/quic-v1" - "/ip4/0.0.0.0/udp/${port}/quic-v1/webtransport" - "/ip6/::/udp/${port}/quic" - "/ip6/::/udp/${port}/quic-v1" - "/ip6/::/udp/${port}/quic-v1/webtransport" - ]; + Swarm = + let + port = toString cfg.swarmPort; + in + [ + "/ip4/0.0.0.0/tcp/${port}" + "/ip6/::/tcp/${port}" + "/ip4/0.0.0.0/udp/${port}/quic" + "/ip4/0.0.0.0/udp/${port}/quic-v1" + "/ip4/0.0.0.0/udp/${port}/quic-v1/webtransport" + "/ip6/::/udp/${port}/quic" + "/ip6/::/udp/${port}/quic-v1" + "/ip6/::/udp/${port}/quic-v1/webtransport" + ]; NoAnnounce = filterAddresses; }; @@ -116,7 +115,7 @@ in { }; networking.firewall = rec { - allowedTCPPorts = [swarmDefaultPort]; + allowedTCPPorts = [ swarmDefaultPort ]; allowedUDPPorts = allowedTCPPorts; }; } @@ -124,8 +123,8 @@ in { nixfiles.modules.nginx = { enable = true; upstreams = with cfg; { - kubo_gateway.servers."127.0.0.1:${toString gatewayPort}" = {}; - kubo_api.servers."127.0.0.1:${toString apiPort}" = {}; + kubo_gateway.servers."127.0.0.1:${toString gatewayPort}" = { }; + kubo_api.servers."127.0.0.1:${toString apiPort}" = { }; }; virtualHosts = { ${cfg.domain} = { @@ -135,9 +134,7 @@ in { "api.${cfg.domain}" = { locations = { "/".proxyPass = "http://kubo_api"; - "~ ^/$".return = "301 http${ - optionalString config.nixfiles.modules.acme.enable "s" - }://api.${cfg.domain}/webui"; + "~ ^/$".return = "301 http${optionalString config.nixfiles.modules.acme.enable "s"}://api.${cfg.domain}/webui"; }; extraConfig = libNginx.config.internalOnly; }; |