|
25 | 25 | { |
26 | 26 | enable = mkEnableOption "${capitalizedName}"; |
27 | 27 |
|
| 28 | + vpn = { |
| 29 | + enable = mkOption { |
| 30 | + type = types.bool; |
| 31 | + default = false; |
| 32 | + description = '' |
| 33 | + Whether to route ${capitalizedName} traffic through the VPN. |
| 34 | + When false (default), ${capitalizedName} bypasses the VPN to prevent Cloudflare and image provider blocks. |
| 35 | + When true, ${capitalizedName} routes through the VPN (requires nixflix.mullvad.enable = true). |
| 36 | + ''; |
| 37 | + }; |
| 38 | + }; |
| 39 | + |
28 | 40 | config = mkOption { |
29 | 41 | type = |
30 | 42 | arrConfigModule |
|
80 | 92 | }; |
81 | 93 |
|
82 | 94 | config = mkIf (nixflix.enable && cfg.enable) { |
| 95 | + # Assertion: VPN routing requires Mullvad to be enabled |
| 96 | + assertions = [ |
| 97 | + { |
| 98 | + assertion = cfg.vpn.enable -> config.nixflix.mullvad.enable; |
| 99 | + message = "Cannot enable VPN routing for ${capitalizedName} (nixflix.${serviceName}.vpn.enable = true) when Mullvad VPN is disabled. Please set nixflix.mullvad.enable = true."; |
| 100 | + } |
| 101 | + ]; |
| 102 | + |
83 | 103 | # Set pattern-based defaults |
84 | 104 | nixflix.${serviceName}.config = { |
85 | 105 | apiKeyPath = mkDefault null; |
@@ -233,16 +253,29 @@ in { |
233 | 253 |
|
234 | 254 | # Ensure main service (radarr.service, etc.) starts after |
235 | 255 | # directories are created and configured dependencies |
236 | | - ${serviceName} = { |
237 | | - after = |
238 | | - ["nixflix-setup-dirs.service"] |
239 | | - ++ (optional config.services.postgresql.enable "postgresql-ready.target") |
240 | | - ++ (optional config.nixflix.mullvad.enable "mullvad-config.service"); |
241 | | - requires = |
242 | | - ["nixflix-setup-dirs.service"] |
243 | | - ++ (optional config.services.postgresql.enable "postgresql-ready.target"); |
244 | | - wants = optional config.nixflix.mullvad.enable "mullvad-config.service"; |
245 | | - }; |
| 256 | + ${serviceName} = |
| 257 | + { |
| 258 | + after = |
| 259 | + ["nixflix-setup-dirs.service"] |
| 260 | + ++ (optional (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) "${serviceName}-env.service") |
| 261 | + ++ (optional config.services.postgresql.enable "postgresql-ready.target") |
| 262 | + ++ (optional config.nixflix.mullvad.enable "mullvad-config.service"); |
| 263 | + requires = |
| 264 | + ["nixflix-setup-dirs.service"] |
| 265 | + ++ (optional (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) "${serviceName}-env.service") |
| 266 | + ++ (optional config.services.postgresql.enable "postgresql-ready.target"); |
| 267 | + wants = optional config.nixflix.mullvad.enable "mullvad-config.service"; |
| 268 | + } |
| 269 | + // optionalAttrs (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) { |
| 270 | + serviceConfig.EnvironmentFile = "/run/${serviceName}/env"; |
| 271 | + } |
| 272 | + // optionalAttrs (config.nixflix.mullvad.enable && !cfg.vpn.enable) { |
| 273 | + # Bypass VPN by wrapping with mullvad-exclude |
| 274 | + serviceConfig.ExecStart = mkForce (pkgs.writeShellScript "${serviceName}-vpn-bypass" '' |
| 275 | + exec /run/wrappers/bin/mullvad-exclude ${getExe config.services.${serviceName}.package} \ |
| 276 | + -nobrowser -data='${stateDir}' |
| 277 | + ''); |
| 278 | + }; |
246 | 279 | } |
247 | 280 | # Only create config and rootfolders services if apiKeyPath is configured |
248 | 281 | // optionalAttrs (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) { |
@@ -271,18 +304,6 @@ in { |
271 | 304 | ''; |
272 | 305 | }; |
273 | 306 |
|
274 | | - ${serviceName} = { |
275 | | - after = |
276 | | - ["${serviceName}-env.service" "nixflix-setup-dirs.service"] |
277 | | - ++ (optional config.services.postgresql.enable "postgresql-ready.target") |
278 | | - ++ (optional config.nixflix.mullvad.enable "mullvad-config.service"); |
279 | | - requires = |
280 | | - ["${serviceName}-env.service" "nixflix-setup-dirs.service"] |
281 | | - ++ (optional config.services.postgresql.enable "postgresql-ready.target"); |
282 | | - wants = optional config.nixflix.mullvad.enable "mullvad-config.service"; |
283 | | - serviceConfig.EnvironmentFile = "/run/${serviceName}/env"; |
284 | | - }; |
285 | | - |
286 | 307 | # Configure service via API |
287 | 308 | "${serviceName}-config" = mkArrHostConfigService serviceName cfg.config; |
288 | 309 | } |
|
0 commit comments