2023-06-03 00:23:07 +03:00
|
|
|
{ config, depot, lib, tools, ... }:
|
2021-10-16 20:36:25 +03:00
|
|
|
with tools.nginx;
|
|
|
|
let
|
|
|
|
inherit (tools.meta) domain;
|
2022-06-18 03:44:51 +03:00
|
|
|
gw = config.links.ipfsGateway;
|
2023-06-02 19:06:34 +03:00
|
|
|
cfg = config.services.ipfs;
|
|
|
|
metrics = config.links.ipfsMetrics;
|
2021-10-16 20:36:25 +03:00
|
|
|
in
|
|
|
|
{
|
2021-12-04 03:51:21 +02:00
|
|
|
users.users.nginx.extraGroups = [ cfg.group ];
|
|
|
|
|
2023-06-02 19:06:34 +03:00
|
|
|
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 *;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-06-02 19:06:34 +03:00
|
|
|
ipfs-metrics = {
|
|
|
|
serverName = null;
|
|
|
|
listen = lib.singleton {
|
|
|
|
addr = metrics.ipv4;
|
|
|
|
inherit (metrics) port;
|
2022-05-16 01:10:58 +03:00
|
|
|
};
|
2023-06-02 19:06:34 +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
|
|
|
};
|
|
|
|
};
|
2021-10-16 17:42:26 +03:00
|
|
|
security.acme.certs."ipfs.${domain}" = {
|
|
|
|
domain = "*.ipfs.${domain}";
|
|
|
|
extraDomainNames = [ "*.ipns.${domain}" ];
|
2022-08-07 22:06:17 +03:00
|
|
|
dnsProvider = "pdns";
|
2021-10-16 17:42:26 +03:00
|
|
|
group = "nginx";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."ipfs.${domain}" = vhosts.basic // {
|
|
|
|
serverName = "~^(.+)\.(ip[fn]s)\.${domain}$";
|
|
|
|
enableACME = false;
|
|
|
|
useACMEHost = "ipfs.${domain}";
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
2022-06-18 03:44:51 +03:00
|
|
|
proxyPass = gw.url;
|
2021-10-16 17:42:26 +03:00
|
|
|
extraConfig = ''
|
|
|
|
add_header X-Content-Type-Options "";
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-06-02 23:53:54 +03:00
|
|
|
|
2023-06-03 00:39:41 +03:00
|
|
|
services.ipfs.extraConfig.Gateway.PublicGateways = {
|
|
|
|
"${domain}" = {
|
|
|
|
Paths = [ "/ipfs" "/ipns" ];
|
|
|
|
NoDNSLink = false;
|
|
|
|
UseSubdomains = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-02 23:53:54 +03:00
|
|
|
consul.services.ipfs-gateway = {
|
|
|
|
mode = "external";
|
|
|
|
unit = "ipfs";
|
2023-06-03 00:23:07 +03:00
|
|
|
definition = rec {
|
2023-06-02 23:53:54 +03:00
|
|
|
name = "ipfs-gateway";
|
2023-06-03 00:23:07 +03:00
|
|
|
address = depot.reflection.interfaces.primary.addrPublic;
|
|
|
|
port = 443;
|
|
|
|
checks = [
|
2023-06-05 21:23:59 +03:00
|
|
|
rec {
|
2023-06-03 00:23:07 +03:00
|
|
|
name = "Frontend";
|
|
|
|
id = "service:ipfs-gateway:frontend";
|
|
|
|
interval = "60s";
|
|
|
|
http = "https://${address}/";
|
|
|
|
tls_server_name = "bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354.ipfs.${domain}"; # empty directory
|
2023-06-05 21:23:59 +03:00
|
|
|
header.Host = lib.singleton tls_server_name;
|
2023-06-03 00:23:07 +03:00
|
|
|
method = "HEAD";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "IPFS Node";
|
|
|
|
id = "service:ipfs-gateway:ipfs";
|
|
|
|
interval = "60s";
|
|
|
|
http = "${gw.url}/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/"; # empty directory
|
|
|
|
method = "HEAD";
|
|
|
|
}
|
|
|
|
];
|
2023-06-02 23:53:54 +03:00
|
|
|
};
|
|
|
|
};
|
2021-10-16 20:36:25 +03:00
|
|
|
}
|