nixos/services/qbittorrent-nox.nix

62 lines
1.7 KiB
Nix
Raw Permalink Normal View History

2026-01-20 21:10:47 +00:00
{ config, pkgs, lib, ... }:
{
config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") {
2026-01-21 22:37:12 +00:00
environment.systemPackages = with pkgs; [
2026-01-21 22:34:37 +00:00
qbittorrent-nox
];
2026-01-22 09:39:13 +00:00
# Create qbittorrent user with media group
users.users.qbittorrent = {
isSystemUser = true;
2026-01-26 19:41:28 +00:00
group = "media";
2026-01-22 09:39:13 +00:00
extraGroups = [ "media" ];
home = "/var/lib/qbittorrent";
createHome = true;
};
2026-01-26 19:41:28 +00:00
# Create media group (shared with sonarr/radarr)
2026-01-22 09:39:13 +00:00
users.groups.media = {
gid = 3000;
};
systemd.tmpfiles.rules = [
# qbittorrent app data — Z recursively enforces ownership/perms on boot
# (self-heals UID/GID drift from migrations etc.)
"d /var/lib/qbittorrent 0755 qbittorrent media -"
"Z /var/lib/qbittorrent 0755 qbittorrent media -"
# Storage - qbittorrent downloads here
"d /mnt/storage/torrents/downloads 2775 qbittorrent media -"
"Z /mnt/storage/torrents/downloads 2775 qbittorrent media -"
];
2026-01-21 22:41:48 +00:00
systemd.services.qbittorrent-nox = {
description = "qBittorrent-nox service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = "qbittorrent";
2026-01-26 19:41:28 +00:00
Group = "media";
ExecStart = "${pkgs.qbittorrent-nox}/bin/qbittorrent-nox --confirm-legal-notice";
2026-01-21 22:41:48 +00:00
Restart = "on-failure";
UMask = "0002";
2026-01-26 19:41:28 +00:00
# Security hardening - FIXED
2026-01-21 22:41:48 +00:00
NoNewPrivileges = true;
PrivateTmp = true;
ProtectSystem = "strict";
2026-01-26 19:41:28 +00:00
ProtectHome = false; # Changed to false so it can write to /var/lib/qbittorrent
2026-01-21 22:41:48 +00:00
ReadWritePaths = [
"/var/lib/qbittorrent"
2026-01-21 22:49:01 +00:00
"/mnt/storage/torrents"
2026-01-21 22:41:48 +00:00
];
2026-01-26 19:41:28 +00:00
# Set proper working directory
WorkingDirectory = "/var/lib/qbittorrent";
2026-01-21 22:41:48 +00:00
};
};
2026-01-22 09:39:13 +00:00
2026-01-26 19:41:28 +00:00
users.users.fred.extraGroups = [ "media" ];
2026-01-20 21:39:16 +00:00
};
2026-01-20 21:10:47 +00:00
}