Files
nixarr/nixarr/readarr/default.nix
T
rasmus-kirk 13dfd643d0 Fixed docs
2024-03-03 17:34:44 +01:00

86 lines
2.0 KiB
Nix

{
config,
lib,
...
}:
with lib; let
cfg = config.nixarr.readarr;
nixarr = config.nixarr;
in {
options.nixarr.readarr = {
enable = mkEnableOption "Enable the Readarr service";
stateDir = mkOption {
type = types.path;
default = "${nixarr.stateDir}/readarr";
description = "The state directory for Readarr";
};
vpn.enable = mkOption {
type = types.bool;
default = false;
description = ''
**Required options:** [`nixarr.vpn.enable`](#nixarr.vpn.enable)
Route Readarr traffic through the VPN.
'';
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.vpn.enable -> nixarr.vpn.enable;
message = ''
The nixarr.readarr.vpn.enable option requires the
nixarr.vpn.enable option to be set, but it was not.
'';
}
];
systemd.tmpfiles.rules = [
"d '${cfg.stateDir}' 0700 readarr root - -"
];
services.readarr = {
enable = cfg.enable;
user = "readarr";
group = "media";
dataDir = cfg.stateDir;
};
# Enable and specify VPN namespace to confine service in.
systemd.services.readarr.vpnconfinement = mkIf cfg.vpn.enable {
enable = true;
vpnnamespace = "wg";
};
# Port mappings
vpnnamespaces.wg = mkIf cfg.vpn.enable {
portMappings = [{ From = defaultPort; To = defaultPort; }];
};
services.nginx = mkIf cfg.vpn.enable {
enable = true;
recommendedTlsSettings = true;
recommendedOptimisation = true;
recommendedGzipSettings = true;
virtualHosts."127.0.0.1:${builtins.toString defaultPort}" = {
listen = [
{
addr = "0.0.0.0";
port = defaultPort;
}
];
locations."/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
proxyPass = "http://192.168.15.1:${builtins.toString defaultPort}";
};
};
};
};
}