Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Stunkymonkey
Copy link
Contributor

@Stunkymonkey Stunkymonkey commented Jan 13, 2025

with the new formats.xml we can do great things. it was prepare some time ago.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jan 13, 2025
@Stunkymonkey Stunkymonkey force-pushed the exportarr-sonarr-test branch from 43fec13 to 6a0cd16 Compare January 13, 2025 22:06
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 13, 2025
@Stunkymonkey Stunkymonkey requested a review from tie January 13, 2025 22:18
@Stunkymonkey Stunkymonkey marked this pull request as ready for review January 13, 2025 22:24
@bjornfor
Copy link
Contributor

nixos/sonaar: add settings option

I wondered what "sonaar" is, then I realized it's a typo :-)

@bjornfor
Copy link
Contributor

Commit nixos/tests/prometheus-exporters: add exportarr-sonarr test says this adds a test, but the test already exist and is merely getting simplified by using the new module options?

@Stunkymonkey Stunkymonkey changed the title nixos/sonaar: add settings option nixos/sonarr: add settings option Jan 14, 2025
settings = lib.mkOption {
inherit (settingsFormat) type;
description = "An attribute set containing Sonarr configuration settings.";
default = { };
Copy link
Contributor

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 about

An attribute set containing Sonarr configuration written to the config.xml file, which will be applied on every service start. IOW, it overwrites imperative changes done in web UI.

I 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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 = ....

Copy link
Contributor

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.

Copy link
Contributor

@ambroisie ambroisie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see this added, just a couple of notes :-)

nixos/modules/services/misc/sonarr.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/sonarr.nix Show resolved Hide resolved
nixos/modules/services/misc/sonarr.nix Outdated Show resolved Hide resolved
let
# add empty ApiKey so it can be replaced afterwards
configContent =
settingsCombined // (lib.optionalAttrs (cfg.apiKeyFile != "") { ApiKey = "#APIKEY#"; });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the module should assert that cfg.settingsdoes not contain ApiKey due to it being a secret in the nix store.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added assertions

settings = lib.mkOption {
inherit (settingsFormat) type;
description = "An attribute set containing Sonarr configuration settings.";
default = { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = { };
default = settingsDefault;

@@ -44,6 +83,15 @@ in
};

config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.settings ? ApiKey -> false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertion = cfg.settings ? ApiKey -> false;
assertion = !(builtins.hasAttr "ApiKey" cfg.settings);

{
assertion = cfg.settings ? ApiKey -> false;
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should point to apiKeyFile in the message, how about:

Suggested change
The `services.sonarr.settings` attribute set must not contain `ApiKey`, as it is a secret and cannot be securely stored in the Nix store.
The `services.sonarr.settings` attribute set must not contain `ApiKey`, you should instead use `services.sonarr.apiKeyFile` to avoid storing secrets in the Nix store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants