Skip to content

Commit 1047966

Browse files
committed
fix permissions issue with wait for api script
1 parent ead3d5e commit 1047966

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

modules/arr-common/mkArrServiceModule.nix

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with lib; let
88
inherit (config) nixflix;
99
inherit (nixflix) globals;
10-
cfg = config.nixflix.${serviceName};
10+
cfg = nixflix.${serviceName};
1111
stateDir = "${nixflix.stateDir}/${serviceName}";
1212

1313
mkWaitForApiScript = import ./mkWaitForApiScript.nix {inherit lib pkgs;};
@@ -63,16 +63,16 @@ with lib; let
6363
method = "Forms";
6464
};
6565
server = {
66-
inherit (config.nixflix.${serviceName}.config.hostConfig) port urlBase;
66+
inherit (nixflix.${serviceName}.config.hostConfig) port urlBase;
6767
};
6868
} // lib.optionalAttrs config.services.postgresql.enable {
6969
log.dbEnabled = true;
7070
postgres = {
71-
user = config.nixflix.${serviceName}.user;
71+
user = nixflix.${serviceName}.user;
7272
host = "/run/postgresql";
7373
port = 5432;
74-
mainDb = config.nixflix.${serviceName}.user;
75-
logDb = config.nixflix.${serviceName}.user;
74+
mainDb = nixflix.${serviceName}.user;
75+
logDb = nixflix.${serviceName}.user;
7676
};
7777
}
7878
'';
@@ -184,15 +184,15 @@ in {
184184
mediaDirs = mkOption {
185185
type = types.listOf types.path;
186186
default = [];
187-
defaultText = literalExpression ''[config.nixflix.mediaDir + "/<media-type>"]'';
187+
defaultText = literalExpression ''[nixflix.mediaDir + "/<media-type>"]'';
188188
description = "List of media directories to create and manage";
189189
};
190190
};
191191

192192
config = mkIf (nixflix.enable && cfg.enable) {
193193
assertions = [
194194
{
195-
assertion = cfg.vpn.enable -> config.nixflix.mullvad.enable;
195+
assertion = cfg.vpn.enable -> nixflix.mullvad.enable;
196196
message = "Cannot enable VPN routing for ${capitalizedName} (nixflix.${serviceName}.vpn.enable = true) when Mullvad VPN is disabled. Please set nixflix.mullvad.enable = true.";
197197
}
198198
];
@@ -228,14 +228,14 @@ in {
228228
);
229229
};
230230
downloadClients = mkDefault (
231-
optionals (config.nixflix.sabnzbd.enable or false) [
231+
optionals (nixflix.sabnzbd.enable or false) [
232232
{
233233
name = "SABnzbd";
234234
implementationName = "SABnzbd";
235-
inherit (config.nixflix.sabnzbd) apiKeyPath;
236-
inherit (config.nixflix.sabnzbd.settings) host;
237-
inherit (config.nixflix.sabnzbd.settings) port;
238-
urlBase = config.nixflix.sabnzbd.settings.url_base;
235+
inherit (nixflix.sabnzbd) apiKeyPath;
236+
inherit (nixflix.sabnzbd.settings) host;
237+
inherit (nixflix.sabnzbd.settings) port;
238+
urlBase = nixflix.sabnzbd.settings.url_base;
239239
}
240240
]
241241
);
@@ -337,11 +337,11 @@ in {
337337
["network.target"]
338338
++ (optional (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) "${serviceName}-env.service")
339339
++ (optional config.services.postgresql.enable "postgresql-ready.target")
340-
++ (optional config.nixflix.mullvad.enable "mullvad-config.service");
340+
++ (optional nixflix.mullvad.enable "mullvad-config.service");
341341
requires =
342342
(optional (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) "${serviceName}-env.service")
343343
++ (optional config.services.postgresql.enable "postgresql-ready.target");
344-
wants = optional config.nixflix.mullvad.enable "mullvad-config.service";
344+
wants = optional nixflix.mullvad.enable "mullvad-config.service";
345345
wantedBy = ["multi-user.target"];
346346

347347
serviceConfig =
@@ -356,7 +356,7 @@ in {
356356
// optionalAttrs (cfg.config.apiKeyPath != null && cfg.config.hostConfig.passwordPath != null) {
357357
EnvironmentFile = "/run/${serviceName}/env";
358358
}
359-
// optionalAttrs (config.nixflix.mullvad.enable && !cfg.vpn.enable) {
359+
// optionalAttrs (nixflix.mullvad.enable && !cfg.vpn.enable) {
360360
ExecStart = mkForce (pkgs.writeShellScript "${serviceName}-vpn-bypass" ''
361361
exec /run/wrappers/bin/mullvad-exclude ${getExe cfg.package} \
362362
-nobrowser -data='${stateDir}'

modules/arr-common/mkWaitForApiScript.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
}: serviceName: serviceConfig:
55
pkgs.writeShellScript "${serviceName}-wait-for-api" (let
66
capitalizedName = lib.toUpper (builtins.substring 0 1 serviceName) + builtins.substring 1 (-1) serviceName;
7+
screamingName = lib.toUpper serviceName;
8+
apiKeyEnvVar = screamingName + "__AUTH__APIKEY";
79
in ''
8-
API_KEY=$(cat ${serviceConfig.apiKeyPath})
10+
if [ -n "${"$"}{${apiKeyEnvVar}:-}" ]; then
11+
API_KEY="${"$"}${apiKeyEnvVar}"
12+
else
13+
API_KEY=$(cat ${serviceConfig.apiKeyPath})
14+
fi
15+
916
BASE_URL="http://127.0.0.1:${builtins.toString serviceConfig.hostConfig.port}${serviceConfig.hostConfig.urlBase}/api/${serviceConfig.apiVersion}"
1017
1118
echo "Waiting for ${capitalizedName} API to be available..."

tests/vm-tests/postgresql-integration.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ pkgs.testers.runNixOSTest {
8787
machine.wait_for_unit("lidarr-wait-for-db.service", timeout=60)
8888
8989
# Wait for all services
90-
machine.wait_for_unit("prowlarr.service", timeout=60)
91-
machine.wait_for_unit("sonarr.service", timeout=60)
92-
machine.wait_for_unit("radarr.service", timeout=60)
93-
machine.wait_for_unit("lidarr.service", timeout=60)
90+
machine.wait_for_unit("prowlarr.service", timeout=120)
91+
machine.wait_for_unit("sonarr.service", timeout=120)
92+
machine.wait_for_unit("radarr.service", timeout=120)
93+
machine.wait_for_unit("lidarr.service", timeout=120)
9494
machine.wait_for_open_port(9696, timeout=60)
9595
machine.wait_for_open_port(8989, timeout=60)
9696
machine.wait_for_open_port(7878, timeout=60)

0 commit comments

Comments
 (0)