Skip to content

Commit 1e2e6c4

Browse files
authored
fix accidental overrides (#289)
* fix accidental overrides * add test coverage, update changelog
1 parent e4ebfbd commit 1e2e6c4

4 files changed

Lines changed: 99 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1010

1111
- fix seerr sonarr activeDirectory default resolving host config ([#283](https://github.com/kiriwalawren/nixflix/pull/283))
1212
- fix \*arr rootfolders oneshot racing app startup ([#286](https://github.com/kiriwalawren/nixflix/pull/286))
13+
- fix \*arr `config.hostConfig` auth/port/urlBase values being ignored in favor of hardcoded `settings` env vars ([#289](https://github.com/kiriwalawren/nixflix/issues/289))
1314

1415
## [3.0.0] - 2026-07-12
1516

modules/arr-common/mkArrServiceModule.nix

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let
1414
inherit (import ./utils.nix { inherit lib pkgs serviceName; })
1515
usesMediaDirs
1616
capitalizedName
17+
capitalize
1718
serviceBase
1819
mkWaitForApiScript
1920
;
@@ -170,8 +171,8 @@ in
170171
defaultText = literalExpression ''
171172
{
172173
auth = {
173-
required = "Enabled";
174-
method = "Forms";
174+
required = capitalize config.nixflix.${serviceName}.config.hostConfig.authenticationRequired;
175+
method = capitalize config.nixflix.${serviceName}.config.hostConfig.authenticationMethod;
175176
};
176177
server = {
177178
inherit (config.nixflix.${serviceName}.config.hostConfig) port urlBase;
@@ -202,6 +203,14 @@ in
202203
Attribute set of arbitrary config options.
203204
Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config).
204205
206+
These values are translated into environment variables (e.g. `settings.auth.method`
207+
becomes `${toUpper serviceBase}__AUTH__METHOD`), which ${capitalizedName} reads on
208+
startup and are applied *in addition to and with higher precedence than* anything
209+
configured through `config.hostConfig` via the API. `auth.required`/`auth.method`
210+
and `server.port`/`server.urlBase` default to mirroring the corresponding
211+
`config.hostConfig` values, so setting those is normally enough; only set these
212+
directly to override that derived default.
213+
205214
!!! warning
206215
207216
This configuration is stored in the world-readable Nix store!
@@ -266,10 +275,13 @@ in
266275
nixflix.${serviceName} = {
267276
settings = {
268277
auth = {
269-
required = "Enabled";
270-
method = "Forms";
278+
required = mkDefault (capitalize cfg.config.hostConfig.authenticationRequired);
279+
method = mkDefault (capitalize cfg.config.hostConfig.authenticationMethod);
280+
};
281+
server = {
282+
port = mkDefault cfg.config.hostConfig.port;
283+
urlBase = mkDefault cfg.config.hostConfig.urlBase;
271284
};
272-
server = { inherit (cfg.config.hostConfig) port urlBase; };
273285
};
274286
};
275287

modules/arr-common/utils.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
}:
66
let
77
serviceBase = builtins.elemAt (lib.splitString "-" serviceName) 0;
8+
capitalize = s: lib.toUpper (builtins.substring 0 1 s) + builtins.substring 1 (-1) s;
89
in
910
{
10-
inherit serviceBase;
11+
inherit serviceBase capitalize;
1112
usesMediaDirs = !(lib.elem serviceName [ "prowlarr" ]);
12-
capitalizedName =
13-
lib.toUpper (builtins.substring 0 1 serviceName) + builtins.substring 1 (-1) serviceName;
13+
capitalizedName = capitalize serviceName;
1414
isSonarr = serviceBase == "sonarr";
1515
isRadarr = serviceBase == "radarr";
1616
isLidarr = serviceBase == "lidarr";

tests/unit-tests/default.nix

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,4 +825,82 @@ in
825825
in
826826
assertTest "hostconfig-password-requires-username" (!result.success);
827827

828+
# https://github.com/kiriwalawren/nixflix/issues/270
829+
# settings.auth/settings.server must mirror config.hostConfig so that the
830+
# environment variables actually reflect what the user configured there.
831+
hostconfig-drives-settings-auth =
832+
let
833+
config = evalConfig [
834+
{
835+
nixflix = {
836+
enable = true;
837+
radarr = {
838+
enable = true;
839+
config = {
840+
hostConfig = {
841+
port = 7878;
842+
urlBase = "/radarr";
843+
authenticationMethod = "external";
844+
authenticationRequired = "disabledForLocalAddresses";
845+
username = "admin";
846+
password._secret = "/run/secrets/radarr-pass";
847+
};
848+
apiKey._secret = "/run/secrets/radarr-api";
849+
rootFolders = [ { path = "/media/movies"; } ];
850+
};
851+
};
852+
};
853+
}
854+
];
855+
radarrCfg = config.config.nixflix.radarr;
856+
environment = config.config.systemd.services.radarr.environment;
857+
in
858+
pkgs.runCommand "unit-test-hostconfig-drives-settings-auth" { } ''
859+
${check "settings.auth.method mirrors hostConfig.authenticationMethod" (
860+
radarrCfg.settings.auth.method == "External"
861+
)}
862+
${check "settings.auth.required mirrors hostConfig.authenticationRequired" (
863+
radarrCfg.settings.auth.required == "DisabledForLocalAddresses"
864+
)}
865+
${check "settings.server.port mirrors hostConfig.port" (radarrCfg.settings.server.port == 7878)}
866+
${check "settings.server.urlBase mirrors hostConfig.urlBase" (
867+
radarrCfg.settings.server.urlBase == "/radarr"
868+
)}
869+
${check "RADARR__AUTH__METHOD env var reflects hostConfig" (
870+
environment.RADARR__AUTH__METHOD == "External"
871+
)}
872+
${check "RADARR__AUTH__REQUIRED env var reflects hostConfig" (
873+
environment.RADARR__AUTH__REQUIRED == "DisabledForLocalAddresses"
874+
)}
875+
echo 'PASS: hostconfig-drives-settings-auth' > $out
876+
'';
877+
878+
# A user should be able to override settings.auth directly (normal priority,
879+
# no lib.mkForce needed) since the hostConfig-derived value is only mkDefault.
880+
settings-auth-overrides-hostconfig =
881+
let
882+
config = evalConfig [
883+
{
884+
nixflix = {
885+
enable = true;
886+
radarr = {
887+
enable = true;
888+
config = {
889+
hostConfig = {
890+
port = 7878;
891+
authenticationMethod = "forms";
892+
username = "admin";
893+
password._secret = "/run/secrets/radarr-pass";
894+
};
895+
apiKey._secret = "/run/secrets/radarr-api";
896+
rootFolders = [ { path = "/media/movies"; } ];
897+
};
898+
settings.auth.method = "External";
899+
};
900+
};
901+
}
902+
];
903+
radarrCfg = config.config.nixflix.radarr;
904+
in
905+
assertTest "settings-auth-overrides-hostconfig" (radarrCfg.settings.auth.method == "External");
828906
}

0 commit comments

Comments
 (0)