Unverified Commit 1ac172a5 authored by Bruno BELANYI's avatar Bruno BELANYI Committed by GitHub
Browse files

ersatztv: init at 25.8.0; nixos/ersatztv init module (#348655)

parents 1c438e9f 5cf1b92c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1321,6 +1321,12 @@
    githubId = 5892756;
    name = "Alec Snyder";
  };
  allout58 = {
    email = "jamesthollowell@gmail.com";
    github = "allout58";
    githubId = 2939703;
    name = "James Hollowell";
  };
  allusive = {
    email = "jasper@allusive.dev";
    name = "Allusive";
+2 −0
Original line number Diff line number Diff line
@@ -194,6 +194,8 @@

- [nixbit](https://github.com/pbek/nixbit), a GUI application for updating your NixOS system from a Nix Flakes Git repository. Available as [programs.nixbit](#opt-programs.nixbit.enable).

- [ErsatzTV](https://ersatztv.org), a personal IPTV server. Available as [services.ersatztv](#opt-services.ersatztv.enable)

## Backward Incompatibilities {#sec-release-25.11-incompatibilities}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
+1 −0
Original line number Diff line number Diff line
@@ -833,6 +833,7 @@
  ./services/misc/dwm-status.nix
  ./services/misc/dysnomia.nix
  ./services/misc/errbot.nix
  ./services/misc/ersatztv.nix
  ./services/misc/etebase-server.nix
  ./services/misc/etesync-dav.nix
  ./services/misc/evdevremapkeys.nix
+133 −0
Original line number Diff line number Diff line
{
  config,
  pkgs,
  lib,
  ...
}:

let
  inherit (lib)
    mkIf
    getExe
    maintainers
    mkEnableOption
    mkOption
    mkPackageOption
    ;
  inherit (lib.types)
    str
    path
    bool
    float
    int
    ;
  cfg = config.services.ersatztv;
  defaultEnv = {
    ETV_UI_PORT = 8409;
    ETV_BASE_URL = "/";
  };
in
{
  options = {
    services.ersatztv = {
      enable = mkEnableOption "ErsatzTV";

      package = mkPackageOption pkgs "ersatztv" { };

      user = mkOption {
        type = str;
        default = "ersatztv";
        description = "User account under which ErsatzTV runs.";
      };

      group = mkOption {
        type = str;
        default = "ersatztv";
        description = "Group under which ErsatzTV runs.";
      };

      environment = mkOption {
        type =
          with lib.types;
          attrsOf (oneOf [
            str
            int
            float
            bool
          ]);
        default = defaultEnv;
        example = {
          ETV_UI_PORT = 8000;
          ETV_STREAMING_PORT = 8001;
        };
        description = "Environment variables to set for the ErsatzTV service.";
      };

      baseUrl = mkOption {
        type = str;
        default = "/";
        description = ''
          Base URL to support reverse proxies that use paths (e.g. `/ersatztv`)
        '';
      };

      openFirewall = mkOption {
        type = bool;
        default = false;
        description = ''
          Open the default ports in the firewall for the server.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    services.ersatztv.environment = lib.mapAttrs (_: lib.mkDefault) defaultEnv;

    systemd = {
      services.ersatztv = {
        description = "ErsatzTV";
        after = [ "network-online.target" ];
        wants = [ "network-online.target" ];
        wantedBy = [ "multi-user.target" ];

        serviceConfig = {
          Type = "simple";
          User = cfg.user;
          Group = cfg.group;
          DynamicUser = true;
          UMask = "0077";
          StateDirectory = "ersatztv";
          WorkingDirectory = "/var/lib/ersatztv";
          ExecStart = getExe cfg.package;
          Restart = "on-failure";
        };

        # Set environment variables for the service, using known values for ETV_CONFIG_FOLDER and ETV_TRANSCODE_FOLDER, and allowing overrides from cfg.environment
        environment = {
          ETV_CONFIG_FOLDER = "/var/lib/ersatztv/config";
          ETV_TRANSCODE_FOLDER = "/var/lib/ersatztv/transcode";
        }
        // cfg.environment;
      };
    };

    users.users = mkIf (cfg.user == "ersatztv") {
      ersatztv = {
        inherit (cfg) group;
        isSystemUser = true;
      };
    };

    users.groups = mkIf (cfg.group == "ersatztv") { ersatztv = { }; };

    networking.firewall = mkIf cfg.openFirewall {
      allowedTCPPorts = [
        cfg.environment.ETV_UI_PORT
      ];
    };

  };

  meta.maintainers = with maintainers; [ allout58 ];
}
+1 −0
Original line number Diff line number Diff line
@@ -523,6 +523,7 @@ in
  };
  ergo = runTest ./ergo.nix;
  ergochat = runTest ./ergochat.nix;
  ersatztv = handleTest ./ersatztv.nix { };
  esphome = runTest ./esphome.nix;
  etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
  etcd = import ./etcd/default.nix { inherit pkgs runTest; };
Loading