lib, readarr-audiobook: copy *arr helpers from nixpkgs instead of downloading them

This commit is contained in:
Edward Pierzchalski
2025-11-22 10:00:09 +11:00
parent d8ca911a13
commit 4d1d1cfe76
2 changed files with 97 additions and 9 deletions
+93
View File
@@ -0,0 +1,93 @@
# Utilities for defining *arr service settings, options, and configs.
#
# Copied from nixpkgs master as of 2025-11-11: https://raw.githubusercontent.com/NixOS/nixpkgs/cf540f8c9840457ed90a315dd635bceecb78495a/nixos/modules/services/misc/servarr/settings-options.nix
{
lib,
pkgs,
}: {
mkServarrSettingsOptions = name: port:
lib.mkOption {
type = lib.types.submodule {
freeformType = (pkgs.formats.ini {}).type;
options = {
update = {
mechanism = lib.mkOption {
type = with lib.types;
nullOr (enum [
"external"
"builtIn"
"script"
]);
description = "which update mechanism to use";
default = "external";
};
automatically = lib.mkOption {
type = lib.types.bool;
description = "Automatically download and install updates.";
default = false;
};
};
server = {
port = lib.mkOption {
type = lib.types.port;
description = "Port Number";
default = port;
};
};
log = {
analyticsEnabled = lib.mkOption {
type = lib.types.bool;
description = "Send Anonymous Usage Data";
default = false;
};
};
};
};
example = lib.options.literalExpression ''
{
update.mechanism = "internal";
server = {
urlbase = "localhost";
port = ${toString port};
bindaddress = "*";
};
}
'';
default = {};
description = ''
Attribute set of arbitrary config options.
Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config).
WARNING: this configuration is stored in the world-readable Nix store!
For secrets use [](#opt-services.${name}.environmentFiles).
'';
};
mkServarrEnvironmentFiles = name:
lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [];
description = ''
Environment file to pass secret configuration values.
Each line must follow the `${lib.toUpper name}__SECTION__KEY=value` pattern.
Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config).
'';
};
mkServarrSettingsEnvVars = name: settings:
lib.pipe settings [
(lib.mapAttrsRecursive (
path: value:
lib.optionalAttrs (value != null) {
name = lib.toUpper "${name}__${lib.concatStringsSep "__" path}";
value = toString (
if lib.isBool value
then lib.boolToString value
else value
);
}
))
(lib.collect (x: lib.isString x.name or false && lib.isString x.value or false))
lib.listToAttrs
];
}
+4 -9
View File
@@ -11,12 +11,7 @@ with lib; let
nixarr = config.nixarr; nixarr = config.nixarr;
port = 9494; port = 9494;
settings-options = pkgs.fetchurl { arr-settings-options = import ../lib/arr-settings-options.nix {inherit lib pkgs;};
# Master as of 2025-11-11
url = "https://raw.githubusercontent.com/NixOS/nixpkgs/cf540f8c9840457ed90a315dd635bceecb78495a/nixos/modules/services/misc/servarr/settings-options.nix";
hash = "sha256-7fh2fpYphR7kBV0zleRK+gL8gHLqVbjRbuv1B6x748s=";
};
servarr = import settings-options {inherit lib pkgs;};
in { in {
options.nixarr.readarr-audiobook = { options.nixarr.readarr-audiobook = {
enable = mkOption { enable = mkOption {
@@ -97,10 +92,10 @@ in {
# Uses name in description to refer to # Uses name in description to refer to
# `services.readarr-audiobook.environmentFiles`. # `services.readarr-audiobook.environmentFiles`.
settings = servarr.mkServarrSettingsOptions "readarr-audiobook" port; settings = arr-settings-options.mkServarrSettingsOptions "readarr-audiobook" port;
# Uses name in description to document `READARR__*` environment variables. # Uses name in description to document `READARR__*` environment variables.
environmentFiles = servarr.mkServarrEnvironmentFiles "readarr"; environmentFiles = arr-settings-options.mkServarrEnvironmentFiles "readarr";
user = lib.mkOption { user = lib.mkOption {
type = lib.types.str; type = lib.types.str;
@@ -160,7 +155,7 @@ in {
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
# Uses name to define `READARR__*` environment variables. # Uses name to define `READARR__*` environment variables.
environment = servarr.mkServarrSettingsEnvVars "readarr" service-cfg.settings; environment = arr-settings-options.mkServarrSettingsEnvVars "readarr" service-cfg.settings;
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";