Browse Source

feat: New Module release

pull/7/head v0.1.0.5
Dale 2 months ago
parent
commit
189f8e7f67
Signed by: Deiru GPG Key ID: AA250C0277B927E1
  1. 110
      module-releases/0-1-0-5.nix

110
module-releases/0-1-0-5.nix

@ -0,0 +1,110 @@
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.services.miracle-tv;
miracleSrc = pkgs.fetchgit {
url = "https://code.gensokyo.social/Gensokyo.social/miracle-tv.git";
rev = "c7746679bfc59472b065816dfb32c251747ffb0d";
sha256 = "1j5hc2l89fl1rshcfbcsfr7aw5fd4ahqbndxdcqbhivv5x6f1b0d";
};
miracle-tv = (import "${miracleSrc}/default.nix");
in {
options.services.miracle-tv = {
enable = mkEnableOption "Miracle TV server";
settings = {
nodeEnv = mkOption {
type = types.str;
default = "production";
};
name = mkOption {
type = types.str;
default = "MiracleTV";
};
dataDir = mkOption {
type = types.str;
default = "/var/miracle-tv";
};
enableNginx = mkEnableOption "Enable Nginx Management";
url = mkOption {
type = types.str;
default = "localhost";
};
client = {
hostname = mkOption {
type = types.str;
default = "0.0.0.0";
};
port = mkOption {
type = types.int;
default = 4000;
};
};
server = {
hostname = mkOption {
type = types.str;
default = "0.0.0.0";
};
port = mkOption {
type = types.int;
default = 4000;
};
};
database = {
host = mkOption {
type = types.str;
default = "localhost";
};
port = mkOption {
type = types.int;
default = 28015;
};
db = mkOption {
type = types.str;
default = "miracle-tv";
};
};
};
};
config = let
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.settings);
in lib.mkIf cfg.enable {
services.nginx.virtualHosts = lib.mkIf cfg.settings.enableNginx {
"${cfg.settings.url}" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${toString cfg.settings.client.port}/";
extraConfig = ''
proxy_pass_request_headers on;
'';
};
locations."/media" = {
root = "${cfg.settings.dataDir}";
};
locations."/api/" = {
proxyPass = "http://localhost:${toString cfg.settings.server.port}/";
extraConfig = ''
proxy_pass_request_headers on;
'';
};
};
};
systemd.services.miracle-tv = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${miracle-tv}/bin/server ${configFile}";
environment = {
NODE_ENV = cfg.settings.nodeEnv;
};
};
systemd.services.miracle-tv-frontend = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${miracle-tv}/bin/client -p ${toString cfg.settings.client.port} -H ${cfg.settings.client.hostname}";
environment = {
NEXT_PUBLIC_API_URL = "https://${cfg.settings.url}/api/graphql";
NODE_ENV = cfg.settings.nodeEnv;
};
};
};
}
Loading…
Cancel
Save