Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tvheadend: Add additional network params. #302304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 93 additions & 32 deletions nixos/modules/services/networking/tvheadend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,122 @@

with lib;

let cfg = config.services.tvheadend;
pidFile = "${config.users.users.tvheadend.home}/tvheadend.pid";
in
let
cfg = config.services.tvheadend;
dataDir = "/var/lib/tvheadend";
pidFile = "${dataDir}/tvheadend.pid";

{
in {
options = {
services.tvheadend = {
enable = mkEnableOption "Tvheadend";

package = mkPackageOption pkgs "tvheadend" { };

user = mkOption {
default = "tvheadend";
type = types.str;
description = ''
User account under which Tvheadend runs.

::: {.note}
If left as the default value this user will automatically be created
on system activation, otherwise you are responsible for
ensuring the user exists before the Tvheadend service starts.
:::
'';
};

group = mkOption {
default = "tvheadend";
type = types.str;
description = ''
Group under which Tvheadend runs.

::: {.note}
If left as the default value this group will automatically be created
on system activation, otherwise you are responsible for
ensuring the user exists before the Tvheadend service starts.
:::
'';
};

httpPort = mkOption {
type = types.int;
default = 9981;
type = types.int;
default = 9981;
description = "Port to bind HTTP to.";
};

htspPort = mkOption {
type = types.int;
default = 9982;
type = types.int;
default = 9982;
description = "Port to bind HTSP to.";
};

ipv6 = mkOption {
type = types.bool;
default = false;
example = true;
description = "Listen on IPv6.";
};

bindAddr = mkOption {
type = with types; nullOr str;
default = null;
description = "Specify bind address.";
example = "127.0.0.1";
};
};
};

config = mkIf cfg.enable {
users.users.tvheadend = {
environment = { systemPackages = [ cfg.package ]; };

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

users.users.tvheadend = mkIf (cfg.user == "tvheadend") {
description = "Tvheadend Service user";
home = "/var/lib/tvheadend";
createHome = true;
home = dataDir;
createHome = true;
isSystemUser = true;
group = "tvheadend";
group = cfg.group;
extraGroups = [ "video" ]; # In order to access tuner adapters.
};
users.groups.tvheadend = {};

systemd.services.tvheadend = {
description = "Tvheadend TV streaming server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
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}";
Type = "forking";
PIDFile = pidFile;
Restart = "always";
RestartSec = 5;
User = cfg.user;
Group = cfg.group;
# CLI options reference -
# https://github.com/tvheadend/tvheadend/blob/ab6ea89b11b1f1a8dcbfd7cfc29d65b3013f2702/src/main.c#L878
ExecStart = "${cfg.package}/bin/tvheadend " +
# Specify alternative http port
"--http_port ${toString cfg.httpPort} " +
# Specify alternative htsp port
"--htsp_port ${toString cfg.htspPort} " +
# Fork and run as daemon
"-f " +
# First run.
"-C " +
# Alternate PID path
"-p ${pidFile} " +
# Run as user
"-u ${cfg.user} " +
# Run as group
"-g ${cfg.group} " +
# Specify bind address
optionalString (cfg.bindAddr != null) "--bindaddr ${cfg.bindAddr} " +
# Listen on IPv6
optionalString (cfg.ipv6) "--ipv6 ";
ExecStop = "${pkgs.coreutils}/bin/rm ${pidFile}";
};
};
};
Expand Down