Free and Open-source video streaming suite. https://miracle-tv.live
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.9 KiB

  1. { lib, pkgs, config, ... }:
  2. with lib;
  3. let
  4. cfg = config.services.miracle-tv;
  5. miracleSrc = ./.;
  6. miracle-tv = (import "${miracleSrc}/default.nix");
  7. in {
  8. options.services.miracle-tv = {
  9. enable = mkEnableOption "Miracle TV server";
  10. settings = {
  11. nodeEnv = mkOption {
  12. type = types.str;
  13. default = "production";
  14. };
  15. name = mkOption {
  16. type = types.str;
  17. default = "MiracleTV";
  18. };
  19. dataDir = mkOption {
  20. type = types.str;
  21. default = "/var/miracle-tv";
  22. };
  23. enableNginx = mkEnableOption "Enable Nginx Management";
  24. url = mkOption {
  25. type = types.str;
  26. default = "localhost";
  27. };
  28. client = {
  29. hostname = mkOption {
  30. type = types.str;
  31. default = "0.0.0.0";
  32. };
  33. port = mkOption {
  34. type = types.int;
  35. default = 4000;
  36. };
  37. };
  38. server = {
  39. hostname = mkOption {
  40. type = types.str;
  41. default = "0.0.0.0";
  42. };
  43. port = mkOption {
  44. type = types.int;
  45. default = 4000;
  46. };
  47. };
  48. database = {
  49. host = mkOption {
  50. type = types.str;
  51. default = "localhost";
  52. };
  53. port = mkOption {
  54. type = types.int;
  55. default = 28015;
  56. };
  57. db = mkOption {
  58. type = types.str;
  59. default = "miracle-tv";
  60. };
  61. };
  62. };
  63. };
  64. config = let
  65. configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.settings);
  66. in lib.mkIf cfg.enable {
  67. services.nginx.virtualHosts = lib.mkIf cfg.settings.enableNginx {
  68. "${cfg.settings.url}" = {
  69. enableACME = true;
  70. forceSSL = true;
  71. locations."/" = {
  72. proxyPass = "http://localhost:${toString cfg.settings.client.port}/";
  73. extraConfig = ''
  74. proxy_pass_request_headers on;
  75. '';
  76. };
  77. locations."/media" = {
  78. root = "${cfg.settings.dataDir}";
  79. };
  80. locations."/api/" = {
  81. proxyPass = "http://localhost:${toString cfg.settings.server.port}/";
  82. extraConfig = ''
  83. proxy_pass_request_headers on;
  84. '';
  85. };
  86. };
  87. };
  88. systemd.services.miracle-tv = {
  89. wantedBy = [ "multi-user.target" ];
  90. serviceConfig.ExecStart = "${miracle-tv}/bin/miracle-server ${configFile}";
  91. environment = {
  92. NODE_ENV = cfg.settings.nodeEnv;
  93. };
  94. };
  95. systemd.services.miracle-tv-frontend = {
  96. wantedBy = [ "multi-user.target" ];
  97. serviceConfig.ExecStart = "${miracle-tv}/bin/miracle-client -p ${toString cfg.settings.client.port} -H ${cfg.settings.client.hostname}";
  98. environment = {
  99. NEXT_PUBLIC_API_URL = "https://${cfg.settings.url}/api/graphql";
  100. NEXT_PUBLIC_MEDIA_URL = "https://${cfg.settings.url}/media";
  101. NODE_ENV = cfg.settings.nodeEnv;
  102. };
  103. };
  104. };
  105. }