-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/sonarr: add settings option #373576
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,20 @@ | |||||
}: | ||||||
let | ||||||
cfg = config.services.sonarr; | ||||||
|
||||||
settingsFormat = pkgs.formats.xml { }; | ||||||
settingsDefault = { | ||||||
Port = 8989; | ||||||
BindAddress = "*"; | ||||||
AuthenticationMethod = "None"; | ||||||
UpdateMechanism = "external"; | ||||||
}; | ||||||
settingsCombined = settingsDefault // cfg.settings; | ||||||
|
||||||
# add empty ApiKey so it can be replaced afterwards | ||||||
configContent = | ||||||
settingsCombined // (lib.optionalAttrs (cfg.apiKeyFile != null) { ApiKey = "@APIKEY@"; }); | ||||||
configFile = settingsFormat.generate "sonarr-config.xml" { Config = configContent; }; | ||||||
in | ||||||
{ | ||||||
options = { | ||||||
|
@@ -27,6 +41,31 @@ in | |||||
''; | ||||||
}; | ||||||
|
||||||
settings = lib.mkOption { | ||||||
inherit (settingsFormat) type; | ||||||
description = "An attribute set containing Sonarr configuration settings."; | ||||||
default = { }; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
example = { | ||||||
LogLevel = "info"; | ||||||
EnableSsl = "False"; | ||||||
Port = 8989; | ||||||
SslPort = 9898; | ||||||
UrlBase = ""; | ||||||
BindAddress = "*"; | ||||||
AuthenticationMethod = "None"; | ||||||
UpdateMechanism = "external"; | ||||||
Branch = "main"; | ||||||
InstanceName = "Sonarr"; | ||||||
}; | ||||||
}; | ||||||
|
||||||
apiKeyFile = lib.mkOption { | ||||||
type = lib.types.nullOr lib.types.path; | ||||||
description = "Path to the file containing the API key for Sonarr (32 chars)."; | ||||||
ambroisie marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
example = "/run/secrets/sonarr-apikey"; | ||||||
default = null; | ||||||
}; | ||||||
|
||||||
user = lib.mkOption { | ||||||
type = lib.types.str; | ||||||
default = "sonarr"; | ||||||
|
@@ -44,6 +83,15 @@ in | |||||
}; | ||||||
|
||||||
config = lib.mkIf cfg.enable { | ||||||
assertions = [ | ||||||
{ | ||||||
assertion = cfg.settings ? ApiKey -> false; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
message = '' | ||||||
The `services.sonarr.settings` attribute set must not contain `ApiKey`, as it is a secret and cannot be securely stored in the Nix store. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should point to
Suggested change
|
||||||
''; | ||||||
} | ||||||
]; | ||||||
|
||||||
systemd.tmpfiles.rules = [ | ||||||
"d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -" | ||||||
]; | ||||||
|
@@ -52,11 +100,19 @@ in | |||||
description = "Sonarr"; | ||||||
after = [ "network.target" ]; | ||||||
wantedBy = [ "multi-user.target" ]; | ||||||
reloadTriggers = [ configFile ]; | ||||||
|
||||||
serviceConfig = { | ||||||
Type = "simple"; | ||||||
User = cfg.user; | ||||||
Group = cfg.group; | ||||||
# set config file in pre | ||||||
ExecStartPre = | ||||||
[ | ||||||
"${pkgs.coreutils}/bin/install -o ${cfg.user} -g ${cfg.group} ${configFile} ${cfg.dataDir}/config.xml" | ||||||
] | ||||||
++ lib.optional (cfg.apiKeyFile != null) | ||||||
"${pkgs.replace-secret}/bin/replace-secret '@APIKEY@' '${cfg.apiKeyFile}' ${cfg.dataDir}/config.xml"; | ||||||
ExecStart = utils.escapeSystemdExecArgs [ | ||||||
(lib.getExe cfg.package) | ||||||
"-nobrowser" | ||||||
|
@@ -67,7 +123,7 @@ in | |||||
}; | ||||||
|
||||||
networking.firewall = lib.mkIf cfg.openFirewall { | ||||||
allowedTCPPorts = [ 8989 ]; | ||||||
allowedTCPPorts = [ settingsCombined.Port ]; | ||||||
}; | ||||||
|
||||||
users.users = lib.mkIf (cfg.user == "sonarr") { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, changes done in the web UI is still allowed, but will be reverted on the next service start. I think that should be noted in the
description
field. How aboutI think config.xml covers roughly the stuff in Settings -> General -- should we mention it?
By reading the generated documentation, it seems the default settings are empty. But they're not. Can we have the actual default settings in the option default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so overall you only suggest an documentation change? Or can we only write, when the config changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to update the description and wonder if we can put the default values right there in
default = ...
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what to do about the "this affects some of the applications config" issue -- I was just thinking out loud.