Skip to content

Commit 9f7ceda

Browse files
committed
chore: support both config and configFile
1 parent d2b67f1 commit 9f7ceda

File tree

1 file changed

+92
-40
lines changed

1 file changed

+92
-40
lines changed

nixarr/recyclarr/default.nix

+92-40
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
with lib; let
99
cfg = config.nixarr.recyclarr;
1010
nixarr = config.nixarr;
11+
format = pkgs.formats.yaml {};
1112

1213
# Helper function to extract API keys
1314
extractApiKeys = pkgs.writeShellApplication {
@@ -41,6 +42,12 @@ with lib; let
4142
chown ${config.services.recyclarr.user}:${config.services.recyclarr.group} "${cfg.stateDir}/env"
4243
'';
4344
};
45+
46+
# Generate configuration file from Nix attribute set if provided
47+
generatedConfigFile = format.generate "recyclarr-config.yml" cfg.configuration;
48+
49+
# Determine which config file to use
50+
effectiveConfigFile = if cfg.configFile != null then cfg.configFile else generatedConfigFile;
4451
in {
4552
options.nixarr.recyclarr = {
4653
enable = mkOption {
@@ -71,55 +78,87 @@ in {
7178
};
7279

7380
configFile = mkOption {
74-
type = types.path;
81+
type = types.nullOr types.path;
82+
default = null;
7583
description = ''
7684
Path to the recyclarr YAML configuration file. See [Recyclarr's
7785
documentation](https://recyclarr.dev/wiki/yaml/config-reference)
7886
for more information.
7987
8088
The API keys for Radarr and Sonarr can be referenced in the config
8189
file using the `RADARR_API_KEY` and `SONARR_API_KEY` environment
82-
variables (with macro `!env_var`). The below example configuration
83-
shows how these values can be used:
84-
85-
```yaml
86-
sonarr:
87-
series:
88-
base_url: "http://localhost:8989"
89-
api_key: !env_var SONARR_API_KEY
90-
quality_definition:
91-
type: series
92-
delete_old_custom_formats: true
93-
custom_formats:
94-
- trash_ids:
95-
- 85c61753df5da1fb2aab6f2a47426b09 # BR-DISK
96-
- 9c11cd3f07101cdba90a2d81cf0e56b4 # LQ
97-
- 47435ece6b99a0b477caf360e79ba0bb # x265 (HD)
98-
- fbcb31d8dabd2a319072b84fc0b7249c # Extras
99-
assign_scores_to:
100-
- name: WEB-DL (1080p)
101-
score: -10000
102-
radarr:
103-
movies:
104-
base_url: "http://localhost:7878"
105-
api_key: !env_var RADARR_API_KEY
106-
quality_definition:
107-
type: movie
108-
delete_old_custom_formats: true
109-
custom_formats:
110-
- trash_ids:
111-
- 570bc9ebecd92723d2d21500f4be314c # Remaster
112-
- eca37840c13c6ef2dd0262b141a5482f # 4K Remaster
113-
- e0c07d59beb37348e975a930d5e50319 # Criterion Collection
114-
- 9d27d9d2181838f76dee150882bdc58c # Masters of Cinema
115-
- db9b4c4b53d312a3ca5f1378f6440fc9 # Vinegar Syndrome
116-
assign_scores_to:
117-
- name: HD Bluray + WEB
118-
score: 25
119-
```
90+
variables (with macro `!env_var`).
91+
92+
Note: You cannot set both `configFile` and `configuration` options.
12093
'';
12194
example = "./recyclarr.yaml";
12295
};
96+
97+
configuration = mkOption {
98+
type = types.nullOr format.type;
99+
default = null;
100+
example = literalExpression ''
101+
{
102+
sonarr = {
103+
series = {
104+
base_url = "http://localhost:8989";
105+
api_key = "!env_var SONARR_API_KEY";
106+
quality_definition = {
107+
type = "series";
108+
};
109+
delete_old_custom_formats = true;
110+
custom_formats = [
111+
{
112+
trash_ids = [
113+
"85c61753df5da1fb2aab6f2a47426b09" # BR-DISK
114+
"9c11cd3f07101cdba90a2d81cf0e56b4" # LQ
115+
];
116+
assign_scores_to = [
117+
{
118+
name = "WEB-DL (1080p)";
119+
score = -10000;
120+
}
121+
];
122+
}
123+
];
124+
};
125+
};
126+
radarr = {
127+
movies = {
128+
base_url = "http://localhost:7878";
129+
api_key = "!env_var RADARR_API_KEY";
130+
quality_definition = {
131+
type = "movie";
132+
};
133+
delete_old_custom_formats = true;
134+
custom_formats = [
135+
{
136+
trash_ids = [
137+
"570bc9ebecd92723d2d21500f4be314c" # Remaster
138+
"eca37840c13c6ef2dd0262b141a5482f" # 4K Remaster
139+
];
140+
assign_scores_to = [
141+
{
142+
name = "HD Bluray + WEB";
143+
score = 25;
144+
}
145+
];
146+
}
147+
];
148+
};
149+
};
150+
}
151+
'';
152+
description = ''
153+
Recyclarr YAML configuration as a Nix attribute set. For detailed configuration options and examples,
154+
see the [official configuration reference](https://recyclarr.dev/wiki/yaml/config-reference/).
155+
156+
The API keys for Radarr and Sonarr can be referenced using the `RADARR_API_KEY` and `SONARR_API_KEY`
157+
environment variables (with the string "!env_var RADARR_API_KEY").
158+
159+
Note: You cannot set both `configFile` and `configuration` options.
160+
'';
161+
};
123162
};
124163

125164
config = mkIf cfg.enable {
@@ -138,6 +177,19 @@ in {
138177
or nixarr.sonarr.enable to be set, but neither was enabled.
139178
'';
140179
}
180+
{
181+
assertion = !(cfg.configFile != null && cfg.configuration != null);
182+
message = ''
183+
You cannot set both nixarr.recyclarr.configFile and nixarr.recyclarr.configuration.
184+
Please choose one method to configure Recyclarr.
185+
'';
186+
}
187+
{
188+
assertion = cfg.configFile != null || cfg.configuration != null;
189+
message = ''
190+
You must set either nixarr.recyclarr.configFile or nixarr.recyclarr.configuration.
191+
'';
192+
}
141193
];
142194

143195
services.recyclarr = {
@@ -168,7 +220,7 @@ in {
168220
requires = ["recyclarr-setup.service"];
169221
after = ["recyclarr-setup.service"];
170222
serviceConfig = {
171-
ExecStart = lib.mkForce "${cfg.package}/bin/recyclarr sync --app-data ${cfg.stateDir} --config ${cfg.configFile}";
223+
ExecStart = lib.mkForce "${cfg.package}/bin/recyclarr sync --app-data ${cfg.stateDir} --config ${effectiveConfigFile}";
172224
EnvironmentFile = "${cfg.stateDir}/env";
173225
ReadWritePaths = [cfg.stateDir];
174226
};

0 commit comments

Comments
 (0)