nixpkgs/nixos/modules/services/misc/bazarr.nix
Nicolas Dumazet 8d982dd6ca nixos/bazarr: fix unit: add RequiresMountsFor for data directory
This helps correctness for systems which need to mount particular
directories (impermanence, preservation). This option has no effect if
the system does not need to mount directories / if no mountpoints exist
for this directory or its parents.

Signed-off-by: Nicolas Dumazet <nicdumz.commits@gmail.com>
2026-03-31 22:19:15 +02:00

94 lines
2.3 KiB
Nix

{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.bazarr;
in
{
options = {
services.bazarr = {
enable = lib.mkEnableOption "bazarr, a subtitle manager for Sonarr and Radarr";
package = lib.mkPackageOption pkgs "bazarr" { };
dataDir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/bazarr";
description = "The directory where Bazarr stores its data files.";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Open ports in the firewall for the bazarr web interface.";
};
listenPort = lib.mkOption {
type = lib.types.port;
default = 6767;
description = "Port on which the bazarr web interface should listen";
};
user = lib.mkOption {
type = lib.types.str;
default = "bazarr";
description = "User account under which bazarr runs.";
};
group = lib.mkOption {
type = lib.types.str;
default = "bazarr";
description = "Group under which bazarr runs.";
};
};
};
config = lib.mkIf cfg.enable {
systemd.tmpfiles.settings."10-bazarr".${cfg.dataDir}.d = {
inherit (cfg) user group;
mode = "0700";
};
systemd.services.bazarr = {
description = "Bazarr";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
SyslogIdentifier = "bazarr";
ExecStart = pkgs.writeShellScript "start-bazarr" ''
${cfg.package}/bin/bazarr \
--config '${cfg.dataDir}' \
--port ${toString cfg.listenPort} \
--no-update True
'';
Restart = "on-failure";
KillSignal = "SIGINT";
SuccessExitStatus = "0 156";
};
unitConfig.RequiresMountsFor = [ cfg.dataDir ];
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.listenPort ];
};
users.users = lib.mkIf (cfg.user == "bazarr") {
bazarr = {
isSystemUser = true;
group = cfg.group;
home = cfg.dataDir;
};
};
users.groups = lib.mkIf (cfg.group == "bazarr") {
bazarr = { };
};
};
}