-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
58 lines (52 loc) · 1.37 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ config, pkgs, lib, ... }:
let
cfg = config.services.webrtc;
inherit (lib) types mkOption mkIf optional escapeShellArg;
frontend = pkgs.callPackage ./client/webrtc.nix {};
backend = pkgs.callPackage ./server/webrtc.nix {};
in {
options.services.webrtc = {
enable = mkOption {
type = types.bool;
default = false;
};
virtualHost = mkOption {
type = types.str;
default = pkgs.lib.getFqdn config;
};
backend = mkOption {
type = types.submodule {
options = {
address = mkOption {
type = types.str;
};
};
};
};
};
config = mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts.${cfg.virtualHost}.locations = {
"/webrtc/signalling/".extraConfig = ''
proxy_pass http://${cfg.backend.address}/ ;
proxy_http_version 1.1 ;
proxy_set_header Upgrade $http_upgrade ;
proxy_set_header Connection "upgrade" ;
proxy_read_timeout 86400 ;
'';
"/webrtc/".extraConfig = ''
alias "${frontend}/" ;
try_files $uri /index.html =404 ;
'';
};
};
systemd.services.webrtc = {
wantedBy = ["multi-user.target"];
serviceConfig = {
Type = "simple";
ExecStart = "${backend}/bin/signalling ${cfg.backend.address}";
};
};
};
}