From 6fa5767e07221bbc6fdfda24904b994becc10e7f Mon Sep 17 00:00:00 2001
From: Emily <vcs@emily.moe>
Date: Wed, 21 Aug 2024 20:56:34 +0100
Subject: [PATCH] tvheadend: drop

Closes: #332259
---
 .../manual/release-notes/rl-2411.section.md   |   6 +
 nixos/modules/module-list.nix                 |   1 -
 nixos/modules/rename.nix                      |   1 +
 .../modules/services/networking/tvheadend.nix |  63 --------
 pkgs/servers/tvheadend/default.nix            | 134 ------------------
 pkgs/top-level/aliases.nix                    |   1 +
 pkgs/top-level/all-packages.nix               |   2 -
 7 files changed, 8 insertions(+), 200 deletions(-)
 delete mode 100644 nixos/modules/services/networking/tvheadend.nix
 delete mode 100644 pkgs/servers/tvheadend/default.nix

diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md
index 800bbd03566dd..25a9beb55e80f 100644
--- a/nixos/doc/manual/release-notes/rl-2411.section.md
+++ b/nixos/doc/manual/release-notes/rl-2411.section.md
@@ -334,6 +334,12 @@
   were not used by any other package. External users are encouraged to
   migrate to OpenCV 4.
 
+- The `tvheadend` package and the `services.tvheadend` module have been
+  removed as nobody was willing to maintain them and they were stuck on
+  an unmaintained version that required FFmpeg 4; please see [pull
+  request #332259](https://github.com/NixOS/nixpkgs/pull/332259) if you
+  are interested in maintaining a newer version.
+
 ## Other Notable Changes {#sec-release-24.11-notable-changes}
 
 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index cf79c8b4792b6..812179b6962a3 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -1239,7 +1239,6 @@
   ./services/networking/tox-node.nix
   ./services/networking/toxvpn.nix
   ./services/networking/trickster.nix
-  ./services/networking/tvheadend.nix
   ./services/networking/twingate.nix
   ./services/networking/ucarp.nix
   ./services/networking/unbound.nix
diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix
index 374d127198d0d..71a4da5419e1a 100644
--- a/nixos/modules/rename.nix
+++ b/nixos/modules/rename.nix
@@ -94,6 +94,7 @@ in
       the program being unmaintained. The options `programs.msmtp.*` can be
       used instead.
     '')
+    (mkRemovedOptionModule [ "services" "tvheadend" ] "The tvheadend package and the corresponding module have been removed as nobody was willing to maintain them and they were stuck on an unmaintained version that required FFmpeg 4; please see https://github.com/NixOS/nixpkgs/pull/332259 if you are interested in maintaining a newer version.")
     (mkRemovedOptionModule [ "services" "venus" ] "The corresponding package was removed from nixpkgs.")
     (mkRemovedOptionModule [ "services" "wakeonlan"] "This module was removed in favor of enabling it with networking.interfaces.<name>.wakeOnLan")
     (mkRemovedOptionModule [ "services" "winstone" ] "The corresponding package was removed from nixpkgs.")
diff --git a/nixos/modules/services/networking/tvheadend.nix b/nixos/modules/services/networking/tvheadend.nix
deleted file mode 100644
index 19a10a03bd9b6..0000000000000
--- a/nixos/modules/services/networking/tvheadend.nix
+++ /dev/null
@@ -1,63 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-
-let cfg     = config.services.tvheadend;
-    pidFile = "${config.users.users.tvheadend.home}/tvheadend.pid";
-in
-
-{
-  options = {
-    services.tvheadend = {
-      enable = mkEnableOption "Tvheadend";
-      httpPort = mkOption {
-        type        = types.int;
-        default     = 9981;
-        description = "Port to bind HTTP to.";
-      };
-
-      htspPort = mkOption {
-        type        = types.int;
-        default     = 9982;
-        description = "Port to bind HTSP to.";
-      };
-    };
-  };
-
-  config = mkIf cfg.enable {
-    users.users.tvheadend = {
-      description = "Tvheadend Service user";
-      home        = "/var/lib/tvheadend";
-      createHome  = true;
-      isSystemUser = true;
-      group = "tvheadend";
-    };
-    users.groups.tvheadend = {};
-
-    systemd.services.tvheadend = {
-      description = "Tvheadend TV streaming server";
-      wantedBy    = [ "multi-user.target" ];
-      after       = [ "network.target" ];
-
-      serviceConfig = {
-        Type         = "forking";
-        PIDFile      = pidFile;
-        Restart      = "always";
-        RestartSec   = 5;
-        User         = "tvheadend";
-        Group        = "video";
-        ExecStart    = ''
-                       ${pkgs.tvheadend}/bin/tvheadend \
-                       --http_port ${toString cfg.httpPort} \
-                       --htsp_port ${toString cfg.htspPort} \
-                       -f \
-                       -C \
-                       -p ${pidFile} \
-                       -u tvheadend \
-                       -g video
-                       '';
-        ExecStop     = "${pkgs.coreutils}/bin/rm ${pidFile}";
-      };
-    };
-  };
-}
diff --git a/pkgs/servers/tvheadend/default.nix b/pkgs/servers/tvheadend/default.nix
deleted file mode 100644
index 499a046663aef..0000000000000
--- a/pkgs/servers/tvheadend/default.nix
+++ /dev/null
@@ -1,134 +0,0 @@
-{ lib
-, stdenv
-, fetchFromGitHub
-, fetchpatch
-
-# buildtime
-, makeWrapper
-, pkg-config
-, python3
-, which
-
-# runtime
-, avahi
-, bzip2
-, dbus
-, dtv-scan-tables
-, ffmpeg_4
-, gettext
-, gnutar
-, gzip
-, libiconv
-, openssl
-, uriparser
-, zlib
-}:
-
-let
-  version = "4.2.8";
-in stdenv.mkDerivation {
-  pname = "tvheadend";
-  inherit version;
-
-  src = fetchFromGitHub {
-    owner = "tvheadend";
-    repo = "tvheadend";
-    rev = "v${version}";
-    sha256 = "1xq059r2bplaa0nd0wkhw80jfwd962x0h5hgd7fz2yp6largw34m";
-  };
-
-  outputs = [
-    "out"
-    "man"
-  ];
-
-  patches = [
-    # Pull upstream fix for -fno-common toolchain
-    #   https://github.com/tvheadend/tvheadend/pull/1342
-    # TODO: can be removed with 4.3 release.
-    (fetchpatch {
-      name = "fno-common.patch";
-      url = "https://github.com/tvheadend/tvheadend/commit/bd92f1389f1aacdd08e913b0383a0ca9dc223153.patch";
-      sha256 = "17bsx6mnv4pjiayvx1d57dphva0kvlppvnmmaym06dh4524pnly1";
-    })
-  ];
-
-  nativeBuildInputs = [
-    makeWrapper
-    pkg-config
-    python3
-    which
-  ];
-
-  buildInputs = [
-    avahi
-    bzip2
-    dbus
-    ffmpeg_4 # depends on libav
-    gettext
-    gzip
-    libiconv
-    openssl
-    uriparser
-    zlib
-  ];
-
-  enableParallelBuilding = true;
-
-  env.NIX_CFLAGS_COMPILE = toString ([
-    "-Wno-error=format-truncation"
-    "-Wno-error=stringop-truncation"
-  ] ++ lib.optionals (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "12") [
-    # Needed with GCC 12 but unrecognized with GCC 9
-    "-Wno-error=use-after-free"
-  ]);
-
-  configureFlags = [
-    # disable dvbscan, as having it enabled causes a network download which
-    # cannot happen during build.  We now include the dtv-scan-tables ourselves
-    "--disable-dvbscan"
-    "--disable-bintray_cache"
-    "--disable-ffmpeg_static"
-    # incompatible with our libhdhomerun version
-    "--disable-hdhomerun_client"
-    "--disable-hdhomerun_static"
-    "--disable-libx264_static"
-    "--disable-libx265_static"
-    "--disable-libvpx_static"
-    "--disable-libtheora_static"
-    "--disable-libvorbis_static"
-    "--disable-libfdkaac_static"
-    "--disable-libmfx_static"
-  ];
-
-  preConfigure = ''
-    substituteInPlace src/config.c \
-      --replace /usr/bin/tar ${gnutar}/bin/tar
-
-    substituteInPlace src/input/mpegts/scanfile.c \
-      --replace /usr/share/dvb ${dtv-scan-tables}/share/dvbv5
-
-    # the version detection script `support/version` reads this file if it
-    # exists, so let's just use that
-    echo ${version} > rpm/version
-  '';
-
-  postInstall = ''
-    wrapProgram $out/bin/tvheadend \
-      --prefix PATH : ${lib.makeBinPath [ bzip2 ]}
-  '';
-
-  meta = with lib; {
-    description = "TV streaming server and digital video recorder";
-    longDescription = ''
-      Tvheadend is a TV streaming server for Linux supporting DVB-S,
-      DVB-S2, DVB-C, DVB-T, ATSC, IPTV,SAT>IP and other formats
-      through the unix pipe as input sources.
-    '';
-    homepage = "https://tvheadend.org";
-    license = licenses.gpl3Only;
-    platforms = platforms.unix;
-    maintainers = with maintainers; [ simonvandel ];
-    mainProgram = "tvheadend";
-  };
-}
diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix
index 9194ba9b4c88b..b71bd5483295b 100644
--- a/pkgs/top-level/aliases.nix
+++ b/pkgs/top-level/aliases.nix
@@ -1494,6 +1494,7 @@ mapAliases ({
   trustedGrub-for-HP = throw "trustedGrub-for-HP has been removed, because it is not maintained upstream anymore"; # Added 2023-05-10
   tumpa = throw "tumpa has been removed, as it is broken"; # Added 2024-07-15
   tvbrowser-bin = tvbrowser; # Added 2023-03-02
+  tvheadend = throw "tvheadend has been removed as it nobody was willing to maintain it and it was stuck on an unmaintained version that required FFmpeg 4; please see https://github.com/NixOS/nixpkgs/pull/332259 if you are interested in maintaining a newer version"; # Added 2024-08-21
   typst-fmt = typstfmt; # Added 2023-07-15
   typst-preview = throw "The features of 'typst-preview' have been consolidated to 'tinymist', an all-in-one language server for typst"; # Added 2024-07-07
 
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8f04392e84002..ca628fe80bf33 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -39115,8 +39115,6 @@ with pkgs;
 
   tvbrowser = callPackage ../applications/misc/tvbrowser { };
 
-  tvheadend = callPackage ../servers/tvheadend { };
-
   twitch-cli = callPackage ../development/tools/twitch-cli { };
 
   uacme = callPackage ../tools/admin/uacme { };