Skip to content

Commit 85bc1c6

Browse files
committed
add draft triples nixos module
1 parent dbe50c1 commit 85bc1c6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@
6060
];
6161
};
6262
});
63+
nixosModules = {
64+
triples = import ./triples.nix;
65+
};
6366
};
6467
}

triples.nix

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
modulesPath,
6+
...
7+
}:
8+
with lib; let
9+
cfg = config.services.triples;
10+
in {
11+
options.services.triples = {
12+
enable = mkEnableOption "triples server";
13+
14+
nginx = mkOption {
15+
type = types.submodule (import "${modulesPath}/services/web-servers/nginx/vhost-options.nix" {inherit config lib;});
16+
default = {};
17+
description = "Extra configuration for the nginx virtual host of triples.";
18+
};
19+
};
20+
21+
config = mkIf cfg.enable {
22+
systemd.services.triples = {
23+
description = "Run triples backend";
24+
wantedBy = ["multi-user.target"];
25+
after = ["networking.target"];
26+
serviceConfig = {
27+
ExecStart = "${pkgs.triples-serve}/bin/serve -bot=false -static=${pkgs.triples-static}/";
28+
Restart = "always";
29+
};
30+
};
31+
services.nginx = {
32+
enable = true;
33+
upstreams.triples-backend.servers."localhost:8080" = {};
34+
virtualHosts."localhost" = mkMerge [
35+
cfg.nginx
36+
{
37+
# default = true;
38+
# root = mkForce "${cfg.package}/share/fluidd/htdocs";
39+
locations = {
40+
"/api/join" = {
41+
proxyWebsockets = true;
42+
proxyPass = "http://triples-backend/api/join";
43+
extraConfig = ''
44+
# go websocket origin check
45+
# ($http_host instead of $host because the latter strips
46+
# port number, relevant for local vm test)
47+
proxy_set_header Host $http_host;
48+
'';
49+
};
50+
"/" = {
51+
proxyPass = "http://triples-backend/";
52+
};
53+
};
54+
}
55+
];
56+
};
57+
};
58+
}

0 commit comments

Comments
 (0)