8
8
with lib ; let
9
9
cfg = config . nixarr . recyclarr ;
10
10
nixarr = config . nixarr ;
11
+ format = pkgs . formats . yaml { } ;
11
12
12
13
# Helper function to extract API keys
13
14
extractApiKeys = pkgs . writeShellApplication {
@@ -41,6 +42,12 @@ with lib; let
41
42
chown ${ config . services . recyclarr . user } :${ config . services . recyclarr . group } "${ cfg . stateDir } /env"
42
43
'' ;
43
44
} ;
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 ;
44
51
in {
45
52
options . nixarr . recyclarr = {
46
53
enable = mkOption {
71
78
} ;
72
79
73
80
configFile = mkOption {
74
- type = types . path ;
81
+ type = types . nullOr types . path ;
82
+ default = null ;
75
83
description = ''
76
84
Path to the recyclarr YAML configuration file. See [Recyclarr's
77
85
documentation](https://recyclarr.dev/wiki/yaml/config-reference)
78
86
for more information.
79
87
80
88
The API keys for Radarr and Sonarr can be referenced in the config
81
89
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.
120
93
'' ;
121
94
example = "./recyclarr.yaml" ;
122
95
} ;
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
+ } ;
123
162
} ;
124
163
125
164
config = mkIf cfg . enable {
@@ -138,6 +177,19 @@ in {
138
177
or nixarr.sonarr.enable to be set, but neither was enabled.
139
178
'' ;
140
179
}
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
+ }
141
193
] ;
142
194
143
195
services . recyclarr = {
168
220
requires = [ "recyclarr-setup.service" ] ;
169
221
after = [ "recyclarr-setup.service" ] ;
170
222
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 } " ;
172
224
EnvironmentFile = "${ cfg . stateDir } /env" ;
173
225
ReadWritePaths = [ cfg . stateDir ] ;
174
226
} ;
0 commit comments