summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhyperion <hyperion@spacekookie.de>2020-10-30 12:00:11 +0100
committerhyperion <hyperion@spacekookie.de>2020-10-30 12:00:11 +0100
commit857e0584d19e0abbc9f73a7ea9aea24be6a6786e (patch)
tree2ffbd6a261b00b6adfb148d458c6185a0ddf59a9
parent43fc40d5dc18615aab9b99f940de59a8da20a902 (diff)
Refactoring repository structure and building basic nix module
-rw-r--r--README.md46
-rw-r--r--brook-metrics/metrics.csv52
-rw-r--r--docs/logo.png (renamed from logo.png)bin92035 -> 92035 bytes
-rw-r--r--docs/logo.svg (renamed from logo.svg)0
-rw-r--r--metrics/.gitignore (renamed from brook-metrics/.gitignore)0
-rw-r--r--metrics/Cargo.lock (renamed from brook-metrics/Cargo.lock)4
-rw-r--r--metrics/Cargo.toml (renamed from brook-metrics/Cargo.toml)2
-rw-r--r--metrics/build (renamed from brook-metrics/build)0
-rw-r--r--metrics/metrics.csv141
-rw-r--r--metrics/shell.nix (renamed from brook-metrics/shell.nix)0
-rw-r--r--metrics/src/main.rs (renamed from brook-metrics/src/main.rs)2
-rw-r--r--nix/dash.nix44
-rw-r--r--nix/default.nix10
-rw-r--r--nix/metrics.nix30
-rw-r--r--nix/nginx.nix57
-rw-r--r--nix/prosody.nix60
-rw-r--r--static/test-video.webmbin4685023 -> 0 bytes
-rw-r--r--web/default.nix6
-rw-r--r--web/index.html (renamed from index.html)3
-rwxr-xr-xweb/static/ajax.min.js (renamed from static/ajax.min.js)0
-rw-r--r--web/static/main.css (renamed from static/main.css)0
21 files changed, 399 insertions, 58 deletions
diff --git a/README.md b/README.md
index 5e34d98..8d092fb 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
<div align="center">
- <img src="https://git.spacekookie.de/brook/plain/logo.png" width="256px"/>
+ <img src="https://git.spacekookie.de/brook/plain/docs/logo.png" width="256px"/>
<h1>brook</h1>
</div>
@@ -21,3 +21,47 @@ setup. Following is a quick overview of components.
viewer metrics
* `prosody` - An XMPP server to back the chat room
+
+## Configuration
+
+I'm running my brook instance on NixOS, and as such a lot of the
+configuration is Nix specific. For other linux distributions, or to
+consider a reference implementation for other systems, check the
+[`common`](./common) directory.
+
+### NixOS
+
+If you are already running an nginx, or prosody, you will have to
+manually integrate [`nix`](./nix) into your configuration. In case
+you don't, you can simply include the whole module.
+
+```nix
+imports = [
+ /path/to/brook/nix
+];
+```
+
+Then you can use the various `brook` submodules to configure your
+streaming setup. If you want to use XMPP chats, you need to configure
+prosody yourself - `brook` will only setup the anonymous user virtualhost
+to be used by the brook-web chat.
+
+```nix
+services.brook = {
+ nginx = {
+ enable = true;
+ hostAddr = "stream.spacekookie.de";
+ acmeHost = "spacekookie.de";
+ };
+
+ prosody = {
+ enable = true;
+ certRoot = "/var/lib/acme/spacekookie.de";
+ };
+
+ dash = {
+ enable = true;
+ name = "kookie.tv";
+ };
+};
+```
diff --git a/brook-metrics/metrics.csv b/brook-metrics/metrics.csv
deleted file mode 100644
index cf55087..0000000
--- a/brook-metrics/metrics.csv
+++ /dev/null
@@ -1,52 +0,0 @@
-2020-10-30_04:26:57 UTC,0
-2020-10-30_04:27:12 UTC,2
-2020-10-30_04:27:27 UTC,2
-2020-10-30_04:27:42 UTC,2
-2020-10-30_04:27:57 UTC,2
-2020-10-30_04:28:12 UTC,2
-2020-10-30_04:28:27 UTC,1
-2020-10-30_04:39:47 UTC,0
-2020-10-30_04:40:02 UTC,1
-2020-10-30_04:40:17 UTC,1
-2020-10-30_04:40:32 UTC,1
-2020-10-30_04:40:47 UTC,2
-2020-10-30_04:41:02 UTC,2
-2020-10-30_04:41:17 UTC,2
-2020-10-30_04:41:32 UTC,2
-2020-10-30_04:41:47 UTC,2
-2020-10-30_04:42:04 UTC,0
-2020-10-30_04:42:19 UTC,2
-2020-10-30_04:42:34 UTC,2
-2020-10-30_04:42:49 UTC,2
-2020-10-30_04:43:04 UTC,2
-2020-10-30_04:43:19 UTC,2
-2020-10-30_04:43:34 UTC,2
-2020-10-30_04:43:49 UTC,2
-2020-10-30_04:44:04 UTC,2
-2020-10-30_04:44:19 UTC,2
-2020-10-30_04:44:54 UTC,0
-2020-10-30_04:45:09 UTC,2
-2020-10-30_04:46:15 UTC,0
-2020-10-30_04:46:30 UTC,2
-2020-10-30_04:46:45 UTC,2
-2020-10-30_04:46:57 UTC,0
-2020-10-30_04:47:12 UTC,2
-2020-10-30_04:47:27 UTC,3
-2020-10-30_04:55:41 UTC,0
-2020-10-30_04:55:56 UTC,1
-2020-10-30_04:56:11 UTC,1
-2020-10-30_05:00:45 UTC,0
-2020-10-30_05:01:00 UTC,0
-2020-10-30_05:01:15 UTC,0
-2020-10-30_05:01:30 UTC,0
-2020-10-30_05:01:45 UTC,0
-2020-10-30_05:02:00 UTC,0
-2020-10-30_05:02:15 UTC,0
-2020-10-30_05:02:42 UTC,0
-2020-10-30_05:02:57 UTC,1
-2020-10-30_05:03:12 UTC,3
-2020-10-30_05:04:15 UTC,0
-2020-10-30_05:04:30 UTC,1
-2020-10-30_05:04:45 UTC,1
-2020-10-30_05:05:00 UTC,2
-2020-10-30_05:05:15 UTC,2
diff --git a/logo.png b/docs/logo.png
index c2404d1..c2404d1 100644
--- a/logo.png
+++ b/docs/logo.png
Binary files differ
diff --git a/logo.svg b/docs/logo.svg
index 69ab078..69ab078 100644
--- a/logo.svg
+++ b/docs/logo.svg
diff --git a/brook-metrics/.gitignore b/metrics/.gitignore
index ea8c4bf..ea8c4bf 100644
--- a/brook-metrics/.gitignore
+++ b/metrics/.gitignore
diff --git a/brook-metrics/Cargo.lock b/metrics/Cargo.lock
index 853c1ee..290b8a0 100644
--- a/brook-metrics/Cargo.lock
+++ b/metrics/Cargo.lock
@@ -516,9 +516,9 @@ dependencies = [
[[package]]
name = "ratman-identity"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "463e8a9937dd2525717feb9f85fbf5da115076eb812b894e255d6ce00bdda289"
+checksum = "ea478515f7e7c6be14890da4a68f7eac07c3e2f395ddc4d855e9d39f773f2783"
dependencies = [
"cfg-if",
"hex",
diff --git a/brook-metrics/Cargo.toml b/metrics/Cargo.toml
index a19ccfc..93ea887 100644
--- a/brook-metrics/Cargo.toml
+++ b/metrics/Cargo.toml
@@ -6,7 +6,7 @@ authors = ["Mx Kookie <kookie@spacekookie.de>"]
edition = "2018"
[dependencies]
-ratman-identity = { version = "*", features = ["random", "aligned"] }
+ratman-identity = { version = "0.5", features = ["random"] }
chrono = "0.4"
hyper = "0.13"
json = "0.12"
diff --git a/brook-metrics/build b/metrics/build
index 67e8e8a..67e8e8a 100644
--- a/brook-metrics/build
+++ b/metrics/build
diff --git a/metrics/metrics.csv b/metrics/metrics.csv
new file mode 100644
index 0000000..7a323b2
--- /dev/null
+++ b/metrics/metrics.csv
@@ -0,0 +1,141 @@
+2020-10-30_04:26:57 UTC,0
+2020-10-30_04:27:12 UTC,2
+2020-10-30_04:27:27 UTC,2
+2020-10-30_04:27:42 UTC,2
+2020-10-30_04:27:57 UTC,2
+2020-10-30_04:28:12 UTC,2
+2020-10-30_04:28:27 UTC,1
+2020-10-30_04:39:47 UTC,0
+2020-10-30_04:40:02 UTC,1
+2020-10-30_04:40:17 UTC,1
+2020-10-30_04:40:32 UTC,1
+2020-10-30_04:40:47 UTC,2
+2020-10-30_04:41:02 UTC,2
+2020-10-30_04:41:17 UTC,2
+2020-10-30_04:41:32 UTC,2
+2020-10-30_04:41:47 UTC,2
+2020-10-30_04:42:04 UTC,0
+2020-10-30_04:42:19 UTC,2
+2020-10-30_04:42:34 UTC,2
+2020-10-30_04:42:49 UTC,2
+2020-10-30_04:43:04 UTC,2
+2020-10-30_04:43:19 UTC,2
+2020-10-30_04:43:34 UTC,2
+2020-10-30_04:43:49 UTC,2
+2020-10-30_04:44:04 UTC,2
+2020-10-30_04:44:19 UTC,2
+2020-10-30_04:44:54 UTC,0
+2020-10-30_04:45:09 UTC,2
+2020-10-30_04:46:15 UTC,0
+2020-10-30_04:46:30 UTC,2
+2020-10-30_04:46:45 UTC,2
+2020-10-30_04:46:57 UTC,0
+2020-10-30_04:47:12 UTC,2
+2020-10-30_04:47:27 UTC,3
+2020-10-30_04:55:41 UTC,0
+2020-10-30_04:55:56 UTC,1
+2020-10-30_04:56:11 UTC,1
+2020-10-30_05:00:45 UTC,0
+2020-10-30_05:01:00 UTC,0
+2020-10-30_05:01:15 UTC,0
+2020-10-30_05:01:30 UTC,0
+2020-10-30_05:01:45 UTC,0
+2020-10-30_05:02:00 UTC,0
+2020-10-30_05:02:15 UTC,0
+2020-10-30_05:02:42 UTC,0
+2020-10-30_05:02:57 UTC,1
+2020-10-30_05:03:12 UTC,3
+2020-10-30_05:04:15 UTC,0
+2020-10-30_05:04:30 UTC,1
+2020-10-30_05:04:45 UTC,1
+2020-10-30_05:05:00 UTC,2
+2020-10-30_05:05:15 UTC,2
+2020-10-30_05:25:15 UTC,0
+2020-10-30_05:25:30 UTC,1
+2020-10-30_05:25:45 UTC,1
+2020-10-30_05:26:00 UTC,1
+2020-10-30_05:26:15 UTC,1
+2020-10-30_05:26:30 UTC,1
+2020-10-30_05:26:45 UTC,0
+2020-10-30_05:27:00 UTC,0
+2020-10-30_05:27:15 UTC,0
+2020-10-30_05:27:30 UTC,0
+2020-10-30_05:27:45 UTC,0
+2020-10-30_05:28:00 UTC,0
+2020-10-30_05:28:15 UTC,0
+2020-10-30_05:28:30 UTC,0
+2020-10-30_05:28:45 UTC,0
+2020-10-30_05:29:00 UTC,0
+2020-10-30_05:29:15 UTC,0
+2020-10-30_05:29:30 UTC,0
+2020-10-30_05:29:45 UTC,0
+2020-10-30_05:30:00 UTC,1
+2020-10-30_05:30:15 UTC,1
+2020-10-30_05:30:30 UTC,1
+2020-10-30_05:30:47 UTC,0
+2020-10-30_05:32:33 UTC,0
+2020-10-30_05:38:55 UTC,0
+2020-10-30_05:39:10 UTC,0
+2020-10-30_05:39:25 UTC,0
+2020-10-30_05:39:40 UTC,0
+2020-10-30_05:39:53 UTC,0
+2020-10-30_05:40:09 UTC,0
+2020-10-30_05:40:24 UTC,1
+2020-10-30_05:40:35 UTC,0
+2020-10-30_05:40:50 UTC,1
+2020-10-30_05:41:05 UTC,1
+2020-10-30_05:41:20 UTC,1
+2020-10-30_05:41:35 UTC,1
+2020-10-30_05:41:50 UTC,1
+2020-10-30_05:42:05 UTC,1
+2020-10-30_05:42:20 UTC,1
+2020-10-30_05:42:35 UTC,1
+2020-10-30_05:42:50 UTC,1
+2020-10-30_05:43:05 UTC,0
+2020-10-30_05:43:20 UTC,0
+2020-10-30_05:43:35 UTC,0
+2020-10-30_05:44:07 UTC,0
+2020-10-30_05:44:22 UTC,0
+2020-10-30_05:44:37 UTC,0
+2020-10-30_05:44:52 UTC,1
+2020-10-30_05:45:07 UTC,1
+2020-10-30_05:45:22 UTC,1
+2020-10-30_05:45:37 UTC,1
+2020-10-30_05:45:52 UTC,1
+2020-10-30_05:46:07 UTC,1
+2020-10-30_05:46:32 UTC,0
+2020-10-30_05:46:47 UTC,1
+2020-10-30_05:47:02 UTC,1
+2020-10-30_05:47:17 UTC,1
+2020-10-30_05:47:32 UTC,2
+2020-10-30_05:47:47 UTC,1
+2020-10-30_05:48:02 UTC,2
+2020-10-30_05:48:17 UTC,2
+2020-10-30_05:48:32 UTC,2
+2020-10-30_05:48:47 UTC,2
+2020-10-30_05:49:02 UTC,1
+2020-10-30_05:49:17 UTC,1
+2020-10-30_05:49:32 UTC,1
+2020-10-30_05:49:47 UTC,1
+2020-10-30_05:50:02 UTC,1
+2020-10-30_05:50:17 UTC,1
+2020-10-30_05:50:32 UTC,2
+2020-10-30_05:50:47 UTC,1
+2020-10-30_05:51:02 UTC,1
+2020-10-30_05:51:17 UTC,1
+2020-10-30_05:51:32 UTC,1
+2020-10-30_05:51:47 UTC,1
+2020-10-30_05:52:02 UTC,1
+2020-10-30_05:52:17 UTC,1
+2020-10-30_05:52:32 UTC,1
+2020-10-30_05:52:47 UTC,1
+2020-10-30_05:53:02 UTC,1
+2020-10-30_05:53:17 UTC,2
+2020-10-30_05:53:32 UTC,1
+2020-10-30_05:53:47 UTC,1
+2020-10-30_05:54:02 UTC,1
+2020-10-30_05:54:17 UTC,1
+2020-10-30_05:54:32 UTC,1
+2020-10-30_05:54:47 UTC,1
+2020-10-30_05:55:02 UTC,1
+2020-10-30_05:55:17 UTC,1
diff --git a/brook-metrics/shell.nix b/metrics/shell.nix
index 2fa04ad..2fa04ad 100644
--- a/brook-metrics/shell.nix
+++ b/metrics/shell.nix
diff --git a/brook-metrics/src/main.rs b/metrics/src/main.rs
index 649ddd9..af489dd 100644
--- a/brook-metrics/src/main.rs
+++ b/metrics/src/main.rs
@@ -138,6 +138,7 @@ async fn handle_request(req: Request<Body>) -> Result<Response<Body>, Infallible
#[tokio::main]
async fn main() {
+ eprintln!("ID Length: {}", ratman_identity::ID_LEN);
thread::spawn(|| dump_metrics());
let addr = SocketAddr::from(([0, 0, 0, 0], 7667));
@@ -146,6 +147,7 @@ async fn main() {
eprintln!("Bindng address: 0.0.0.0:7667");
let server = Server::bind(&addr).serve(service);
+
if let Err(e) = server.await {
eprintln!("[ERROR]: {}", e);
}
diff --git a/nix/dash.nix b/nix/dash.nix
new file mode 100644
index 0000000..c0af4d7
--- /dev/null
+++ b/nix/dash.nix
@@ -0,0 +1,44 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+ cfg = config.services.brook;
+in
+{
+ options.services.brook.dash = {
+ enable = mkEnableOption "ffmpeg dash server";
+
+ name = mkOption {
+ type = types.str;
+ description = ''
+ The name of the rtmp endpoint of the stream. This might show up as
+ metadata in some clients
+ '';
+ };
+ };
+
+ config = mkIf cfg.dash.enable {
+ systemd.services.brook-ffmpeg = {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+
+ serviceConfig = {
+ StateDirectory = "dash";
+ Group = "nginx";
+ };
+
+ script = let
+ ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg";
+ in
+ ''
+ ${ffmpeg}-listen 1 -i rtmp://0.0.0.0:1935/${cfg.dash.name}/live \
+ -c:v libx264 -x264opts "keyint=24:min-keyint=24:no-scenecut" -r 24 \
+ -c:a aac -b:a 128k \
+ -bf 1 -b_strategy 0 -sc_threshold 0 -pix_fmt yuv420p \
+ -map 0:v:0 -map 0:a:0 -map 0:v:0 \
+ -map 0:a:0 -map 0:v:0 -map 0:a:0 \
+ /var/lib/dash/live.mpd
+ '';
+ };
+ };
+}
diff --git a/nix/default.nix b/nix/default.nix
new file mode 100644
index 0000000..f5f4954
--- /dev/null
+++ b/nix/default.nix
@@ -0,0 +1,10 @@
+{ ... }:
+
+{
+ imports = [
+ ./dash.nix
+ ./metrics.nix
+ ./nginx.nix
+ ./prosody.nix
+ ];
+}
diff --git a/nix/metrics.nix b/nix/metrics.nix
new file mode 100644
index 0000000..8dfc881
--- /dev/null
+++ b/nix/metrics.nix
@@ -0,0 +1,30 @@
+{ lib, config, ... }:
+
+with lib;
+let
+ cfg = config.services.brook;
+in
+{
+ options.services.brook.metrics = {
+ enable = mkEnableOption "brook-web metrics backend";
+
+ port = mkOption {
+ type = types.int;
+ description = ''
+ Port to bind the brook-metrics backend server to.
+ '';
+ };
+
+ path = mkOption {
+ type = types.str;
+ description = ''
+ Set the BROOK_METRICS_PATH environment variable to let
+ brook-metrics know where to export the csv output to.
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+
+ };
+}
diff --git a/nix/nginx.nix b/nix/nginx.nix
new file mode 100644
index 0000000..d60b884
--- /dev/null
+++ b/nix/nginx.nix
@@ -0,0 +1,57 @@
+{ lib, config, pkgs, ... }:
+
+with lib;
+let
+ cfg = config.services.brook;
+in
+{
+ options.services.brook.nginx = {
+ enable = mkEnableOption "brook nginx host handling";
+
+ hostAddr = mkOption {
+ type = types.str;
+ example = "stream.example.com";
+ description = ''
+ Set the virtual host address to use for streaming
+ If nginx is not already enabled, this module will
+ enable it for you.
+ '';
+ };
+
+ acmeHost = mkOption {
+ type = types.str;
+ description = ''
+ An additional host address to use for acme handling. Not setting
+ this option will disable `useACMEHost` and `forceSSL` for this
+ virtualhost.
+ '';
+ };
+ };
+
+ config = mkIf cfg.nginx.enable {
+ services.nginx.virtualHosts."${cfg.nginx.hostAddr}" = {
+ serverAliases = [ cfg.nginx.acmeHost ];
+ enableACME = false;
+ useACMEHost = cfg.nginx.acmeHost;
+ forceSSL = true;
+
+ locations."/xmpp-bosh" = mkIf cfg.prosody.enable {
+ proxyPass = "https://localhost:${cfg.prosody.port}/http-bind";
+ extraConfig = ''
+ proxy_set_header Host ${cfg.prosody.guest-domain};
+ proxy_set_header X-Forwarded-For ${cfg.prosody.guest-domain};
+ proxy_buffering off;
+ tcp_nodelay on;
+ '';
+ };
+
+ locations."/dash" = {
+ root = "/var/lib";
+ };
+
+ locations."/metrics" = mkIf cfg.metrics.enable {
+ proxyPass = "http://localhost:${cfg.metrics.port}";
+ };
+ };
+ };
+}
diff --git a/nix/prosody.nix b/nix/prosody.nix
new file mode 100644
index 0000000..cfbc551
--- /dev/null
+++ b/nix/prosody.nix
@@ -0,0 +1,60 @@
+{ lib, config, ... }:
+
+with lib;
+let
+ cfg = config.services.brook;
+in
+{
+ options.services.brook.prosody = {
+ enable = mkEnableOption "brook XMPP chat with prosody";
+
+ port = mkOption {
+ type = types.int;
+ default = 5281;
+ description = ''
+ Specify the port that prosody's web server is listening on.
+ '';
+ };
+
+ guest-domain = mkOption {
+ type = types.string;
+ description = ''
+ The virtualhost prosody uses as an anonymous user scope.
+ By default prosody can either run in normal user mode, or in
+ anonymous mode. Becuase the stream chat doesn't require registration,
+ this creates a new virtualhost to achieve this.
+ '';
+ };
+
+ certRoot = mkOption {
+ type = types.string;
+ description = ''
+ Pass in the root path to the certificates that the
+ prosody virtualhost should use.
+ '';
+ };
+ };
+
+ config = mkIf cfg.prosody.enable {
+ services.prosody = {
+ modules = { bosh = true; websocket = true; };
+
+ virtualHosts."${cfg.prosody.guest-domain}" = {
+ enable = true;
+ domain = "${cfg.prosody.guest-domain}";
+ ssl = {
+ cert = "${cfg.prosody.certRoot}/fullchain.pem";
+ key = "${cfg.prosody.certRoot}/key.pem";
+ };
+ extraConfig = ''
+ authentication = "anonymous"
+ http_host = ${cfg.prosody.guest-domain}
+ '';
+ };
+
+ extraConfig = services.prosody.extraConfig + ''
+ consider_bosh_secure = true
+ '';
+ };
+ };
+}
diff --git a/static/test-video.webm b/static/test-video.webm
deleted file mode 100644
index 642e562..0000000
--- a/static/test-video.webm
+++ /dev/null
Binary files differ
diff --git a/web/default.nix b/web/default.nix
new file mode 100644
index 0000000..f292398
--- /dev/null
+++ b/web/default.nix
@@ -0,0 +1,6 @@
+{ stdenv, pkgs, ... }:
+
+stdenv.mkDerivation {
+ name = "brook-web";
+ src = ./.;
+}
diff --git a/index.html b/web/index.html
index 5eb8fac..fe5cfaf 100644
--- a/index.html
+++ b/web/index.html
@@ -31,8 +31,7 @@
</div>
<div class="content">
- <video class="stream" id="stream" controls>
- <!-- <source src="/static/test-video.webm" type="video/webm"> -->
+ <video class="stream" autoplay id="stream" controls>
Your browser does not support the video tag!
</video>
diff --git a/static/ajax.min.js b/web/static/ajax.min.js
index 9697988..9697988 100755
--- a/static/ajax.min.js
+++ b/web/static/ajax.min.js
diff --git a/static/main.css b/web/static/main.css
index a5305a4..a5305a4 100644
--- a/static/main.css
+++ b/web/static/main.css