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/recyclarr: init module #374070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

omares
Copy link
Contributor

@omares omares commented Jan 15, 2025

Adds a service definition that allows to run Recyclarr (nixos packge) periodically.

Executing the sync regularly ensures that the Sonarr and Radarr instances stay updated with the latest configurations from the TRaSH guides

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/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 15, 2025
@h7x4 h7x4 added the 8.has: module (new) This PR adds a module in `nixos/` label Jan 17, 2025
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.

Reviewed on my phone, so kind of terse.

Can't recyclarr get away with running as a DynamicUser=true service? It shouldn't interact with many on-disk files unless I'm missing something?

...
}:

with lib;
Copy link
Contributor

Choose a reason for hiding this comment

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

We're trying to reducer usage of with lib; in NixOS.

IMO, having it over options and meta is fine, but people are pushing to remove it completely (see #340346 and #208242).

options.services.recyclarr = {
enable = mkEnableOption "recyclarr service";

package = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use mkPackageOption.

description = "The recyclarr command to run (e.g., sync).";
};

configFile = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use RFC-42-style settings please. If you're worried about secrets, I'd recommend using utils.genJqSecretsReplacementSnippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would the expectation be that a YAML file is generated based on the given settings, and its path is passed as the --config argument to the binary?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you can look at the PR I made to nginx-sso as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this approach, the file generation is moved into the service and out of the user's hands, making it cumbersome to use tools like SOPS or similar that are way better at managing secrets. Are we sure this is the correct solution in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the opposite: using utils.genJqSecretsReplacementSnippet makes it very easy to integrate with agenix/sops-nix to both set the configuration in nix while leaving secret handling to those tools.

I'm not sure I follow what is troubling you about it.

Copy link
Contributor Author

@omares omares Jan 28, 2025

Choose a reason for hiding this comment

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

The lack of documentation and examples regarding the use of genJqSecretsReplacementSnippet made it unclear how it works. I will apply the change and conduct a test usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, not sure why its documentation isn't surfaced in the manual/better documented. If the current usage in other modules isn't enough "documentation", I can walk you through its usage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I applied the change and verified that the service is still working. I had to loosen some security permissions, but nothing major.

'';
};

workingDir = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a use case for changing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If not specified, the recyclarr executable will use the directory where the binary file is located as the working directory. I assumed that if a specify location is defined, users should have the option to change it.

description = "Working directory for recyclarr.";
};

schedule = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there is a type for systemd timer strings, though I can't remember it nor look it up on my phone.


schedule = mkOption {
type = types.str;
default = "*-*-* 04:00:00"; # Every day at 4 AM
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use daily for an easy default instead of the cron-style way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it probably could use the random delay, persistence, etc... options that usually go with a timer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had those in my systemd.timers definition below; I will move them to the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After searching for examples, I only found restic pursuing this approach. Other services typically expect just the interval, for simplicity, I would suggest keeping the current option definition. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me.

${cfg.group} = { };
};

systemd.tmpfiles.rules = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Use systemd.tmpfiles.settings.


systemd.services.recyclarr = {
description = "Recyclarr Service";
after = [ "network.target" ];
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 this isn't necessary nor really useful.

systemd.services.recyclarr = {
description = "Recyclarr Service";
after = [ "network.target" ];
path = [ cfg.package ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it was remnant before using lib.getExe.

@omares omares force-pushed the add-recycalrr-service branch 3 times, most recently from 7367b64 to e370ce0 Compare January 27, 2025 21:44
@omares
Copy link
Contributor Author

omares commented Jan 27, 2025

Reviewed on my phone, so kind of terse.

Can't recyclarr get away with running as a DynamicUser=true service? It shouldn't interact with many on-disk files unless I'm missing something?

In theory, that should be possible, but I am not a fan of being unable to pin the UID and GID to ensure consistency across multiple system when needed and therefore tend to use specific user and group options.

@ambroisie
Copy link
Contributor

In theory, that should be possible, but I am not a fan of being unable to pin the UID and GID to ensure consistency across multiple system when needed and therefore tend to use specific user and group options.

IMO this is a downstream consumer thing you could handle in your own configuration, though I don't have very strong feelings about it.

@omares omares force-pushed the add-recycalrr-service branch from e370ce0 to 06c83d5 Compare January 29, 2025 23:21
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 (new) This PR adds a module in `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