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;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-01 21:14:16 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
2026-04-24 20:04:04 +01:00
|
|
|
# qbittorrent app data — Z recursively enforces ownership/perms on boot
|
|
|
|
|
# (self-heals UID/GID drift from migrations etc.)
|
2026-04-01 21:14:16 +01:00
|
|
|
"d /var/lib/qbittorrent 0755 qbittorrent media -"
|
2026-04-24 20:04:04 +01:00
|
|
|
"Z /var/lib/qbittorrent 0755 qbittorrent media -"
|
2026-04-01 21:14:16 +01:00
|
|
|
|
|
|
|
|
# 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";
|
2026-04-15 23:23:56 +01:00
|
|
|
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
|
|
|
}
|