depot/cluster/services/ipfs/gateway.nix

70 lines
1.7 KiB
Nix
Raw Normal View History

2024-07-04 19:30:38 +03:00
{ cluster, config, depot, lib, ... }:
2021-10-16 20:36:25 +03:00
let
2023-08-31 01:55:45 +03:00
inherit (depot.lib.meta) domain;
2024-07-04 19:30:38 +03:00
gw = cluster.config.hostLinks.${config.networking.hostName}.ipfsGateway;
cfg = config.services.ipfs;
metrics = config.links.ipfsMetrics;
2021-10-16 20:36:25 +03:00
in
{
users.users.nginx.extraGroups = [ cfg.group ];
links.ipfsMetrics = {
protocol = "http";
path = "/debug/metrics/prometheus";
};
2021-10-16 20:36:25 +03:00
services.nginx.virtualHosts = {
"top-level.${domain}".locations = {
"~ ^/ip[fn]s" = {
2022-06-18 03:44:51 +03:00
proxyPass = gw.url;
2021-10-16 20:36:25 +03:00
extraConfig = ''
add_header X-Content-Type-Options "";
add_header Access-Control-Allow-Origin *;
'';
};
};
ipfs-metrics = {
serverName = null;
listen = lib.singleton {
addr = metrics.ipv4;
inherit (metrics) port;
2022-05-16 01:10:58 +03:00
};
extraConfig = "access_log off;";
locations."/".return = "204";
locations."${metrics.path}".proxyPass = "http://unix:/run/ipfs/ipfs-api.sock:";
2021-10-16 20:36:25 +03:00
};
};
services.ipfs.extraConfig.Gateway.PublicGateways = {
"${domain}" = {
Paths = [ "/ipfs" "/ipns" ];
NoDNSLink = false;
UseSubdomains = true;
};
"p2p.${domain}" = {
Paths = [ "/routing" ];
NoDNSLink = true;
UseSubdomains = false;
};
};
consul.services.ipfs-gateway = {
mode = "external";
unit = "ipfs";
2024-07-04 19:30:38 +03:00
definition = {
name = "ipfs-gateway";
2024-07-04 19:30:38 +03:00
address = gw.ipv4;
port = gw.port;
checks = [
{
name = "IPFS Node";
id = "service:ipfs-gateway:ipfs";
interval = "60s";
http = "${gw.url}/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/"; # empty directory
method = "HEAD";
}
];
};
};
2021-10-16 20:36:25 +03:00
}