depot/hosts/VEGAS/services/sips/default.nix

82 lines
2.6 KiB
Nix
Raw Normal View History

2022-02-03 01:43:29 +02:00
{ config, inputs, pkgs, tools, ... }:
let
host = tools.identity.autoDomain "sips";
inherit (inputs.self.packages.${pkgs.system}) sips;
2022-06-18 03:44:51 +03:00
inherit (config) links;
2022-02-03 01:43:29 +02:00
connStringNet = "host=127.0.0.1 sslmode=disable dbname=sips user=sips";
connString = "host=/var/run/postgresql dbname=sips user=sips";
sipsctl = pkgs.runCommandNoCC "sipsctl-with-env" {
nativeBuildInputs = [ pkgs.makeWrapper ];
} ''
makeWrapper ${sips}/bin/sipsctl $out/bin/sipsctl \
--set PGPASSFILE ${config.age.secrets.sips-db-credentials.path} \
--add-flags '--dbdriver postgres --db "${connStringNet}"'
ln -s ${sips}/share $out/share
'';
in
{
age.secrets.sips-db-credentials = {
file = ../../../../secrets/sips-db-credentials.age;
mode = "0400";
};
2022-06-18 03:44:51 +03:00
links = {
sips.protocol = "http";
sipsInternal.protocol = "http";
sipsIpfsApiProxy.protocol = "http";
};
2022-02-03 01:43:29 +02:00
systemd.services.sips = {
wantedBy = [ "multi-user.target" ];
2022-02-26 15:59:47 +02:00
after = [ "network.target" "postgresql.service" ];
2022-02-03 01:43:29 +02:00
requires = [ "sips-ipfs-api-proxy.service" ];
serviceConfig = {
2022-06-18 03:44:51 +03:00
ExecStart = "${sips}/bin/sips --dbdriver postgres --db \"${connString}\" --addr ${links.sipsInternal.tuple} --api ${links.sipsIpfsApiProxy.url} --apitimeout 604800s";
2022-02-03 01:43:29 +02:00
PrivateNetwork = true;
DynamicUser = true;
};
environment.PGPASSFILE = config.age.secrets.sips-db-credentials.path;
};
systemd.services.sips-ipfs-api-proxy = {
after = [ "network.target" "sips.service" ];
bindsTo = [ "sips.service" ];
serviceConfig = {
2022-06-18 03:44:51 +03:00
ExecStart = "${pkgs.socat}/bin/socat tcp4-listen:${links.sipsIpfsApiProxy.portStr},fork,reuseaddr,bind=${links.sipsIpfsApiProxy.ipv4} unix-connect:/run/ipfs/ipfs-api.sock";
2022-02-03 01:43:29 +02:00
PrivateNetwork = true;
DynamicUser = true;
SupplementaryGroups = "ipfs";
};
unitConfig.JoinsNamespaceOf = "sips.service";
};
systemd.services.sips-proxy = {
after = [ "network.target" "sips.service" ];
bindsTo = [ "sips.service" ];
requires = [ "sips-proxy.socket" ];
serviceConfig = {
2022-06-18 03:44:51 +03:00
ExecStart = "${config.systemd.package}/lib/systemd/systemd-socket-proxyd ${links.sipsInternal.tuple}";
2022-02-03 01:43:29 +02:00
PrivateNetwork = true;
DynamicUser = true;
SupplementaryGroups = "ipfs";
};
unitConfig.JoinsNamespaceOf = "sips.service";
};
systemd.sockets.sips-proxy = {
wantedBy = [ "sockets.target" ];
after = [ "network.target" ];
socketConfig = {
2022-06-18 03:44:51 +03:00
ListenStream = "${links.sips.tuple}";
2022-02-03 01:43:29 +02:00
};
};
environment.systemPackages = [ sipsctl ];
2022-06-18 03:44:51 +03:00
services.nginx.virtualHosts.${host} = tools.nginx.vhosts.proxy links.sips.url;
2022-02-03 01:43:29 +02:00
}