eb791b3019
Automated changes by the [update-flake-lock](https://github.com/DeterminateSystems/update-flake-lock) GitHub Action. ``` Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/9ca3f649614213b2aaf5f1e16ec06952fe4c2632?narHash=sha256-7EXDb5WBw%2Bd004Agt%2BJHC/Oyh/KTUglOaQ4MNjBbo5w%3D' (2024-05-27) → 'github:nixos/nixpkgs/71e91c409d1e654808b2621f28a327acfdad8dc2?narHash=sha256-GnR7/ibgIH1vhoy8cYdmXE6iyZqKqFxQSVkFgosBh6w%3D' (2024-08-28) ``` ### Running GitHub Actions on this PR GitHub Actions will not run workflows on pull requests which are opened by a GitHub Action. To run GitHub Actions workflows on this PR, run: ```sh git branch -D update_flake_lock_action git fetch origin git checkout update_flake_lock_action git commit --amend --no-edit git push origin update_flake_lock_action --force ``` --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
169 lines
4.6 KiB
Nix
169 lines
4.6 KiB
Nix
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
cfg = config.shb.audiobookshelf;
|
|
|
|
contracts = pkgs.callPackage ../contracts {};
|
|
|
|
fqdn = "${cfg.subdomain}.${cfg.domain}";
|
|
in
|
|
{
|
|
options.shb.audiobookshelf = {
|
|
enable = lib.mkEnableOption "selfhostblocks.audiobookshelf";
|
|
|
|
subdomain = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Subdomain under which audiobookshelf will be served.";
|
|
example = "abs";
|
|
};
|
|
|
|
domain = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "domain under which audiobookshelf will be served.";
|
|
example = "mydomain.com";
|
|
};
|
|
|
|
webPort = lib.mkOption {
|
|
type = lib.types.int;
|
|
description = "Audiobookshelf web port";
|
|
default = 8113;
|
|
};
|
|
|
|
ssl = lib.mkOption {
|
|
description = "Path to SSL files";
|
|
type = lib.types.nullOr contracts.ssl.certs;
|
|
default = null;
|
|
};
|
|
|
|
extraServiceConfig = lib.mkOption {
|
|
type = lib.types.attrsOf lib.types.str;
|
|
description = "Extra configuration given to the systemd service file.";
|
|
default = {};
|
|
example = lib.literalExpression ''
|
|
{
|
|
MemoryHigh = "512M";
|
|
MemoryMax = "900M";
|
|
}
|
|
'';
|
|
};
|
|
|
|
oidcProvider = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "OIDC provider name";
|
|
default = "Authelia";
|
|
};
|
|
|
|
authEndpoint = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "OIDC endpoint for SSO";
|
|
example = "https://authelia.example.com";
|
|
};
|
|
|
|
oidcClientID = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Client ID for the OIDC endpoint";
|
|
default = "audiobookshelf";
|
|
};
|
|
|
|
oidcAdminUserGroup = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "OIDC admin group";
|
|
default = "audiobookshelf_admin";
|
|
};
|
|
|
|
oidcUserGroup = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "OIDC user group";
|
|
default = "audiobookshelf_user";
|
|
};
|
|
|
|
ssoSecretFile = lib.mkOption {
|
|
type = lib.types.path;
|
|
description = "File containing the SSO shared secret.";
|
|
};
|
|
|
|
backup = lib.mkOption {
|
|
type = contracts.backup;
|
|
description = ''
|
|
Backup configuration. This is an output option.
|
|
|
|
Use it to initialize a block implementing the "backup" contract.
|
|
For example, with the restic block:
|
|
|
|
```
|
|
shb.restic.instances."audiobookshelf" = {
|
|
enable = true;
|
|
|
|
# Options specific to Restic.
|
|
} // config.shb.audiobookshelf.backup;
|
|
```
|
|
'';
|
|
readOnly = true;
|
|
default = {
|
|
user = "audiobookshelf";
|
|
sourceDirectories = [
|
|
"/var/lib/audiobookshelf"
|
|
];
|
|
};
|
|
};
|
|
|
|
logLevel = lib.mkOption {
|
|
type = lib.types.nullOr (lib.types.enum ["critical" "error" "warning" "info" "debug"]);
|
|
description = "Enable logging.";
|
|
default = false;
|
|
example = true;
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [{
|
|
|
|
services.audiobookshelf = {
|
|
enable = true;
|
|
openFirewall = true;
|
|
dataDir = "audiobookshelf";
|
|
host = "127.0.0.1";
|
|
port = cfg.webPort;
|
|
};
|
|
|
|
services.nginx.enable = true;
|
|
services.nginx.virtualHosts."${fqdn}" = {
|
|
http2 = true;
|
|
forceSSL = !(isNull cfg.ssl);
|
|
sslCertificate = lib.mkIf (!(isNull cfg.ssl)) cfg.ssl.paths.cert;
|
|
sslCertificateKey = lib.mkIf (!(isNull cfg.ssl)) cfg.ssl.paths.key;
|
|
|
|
# https://github.com/advplyr/audiobookshelf#nginx-reverse-proxy
|
|
extraConfig = ''
|
|
set $audiobookshelf 127.0.0.1;
|
|
location / {
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_pass http://$audiobookshelf:${builtins.toString cfg.webPort};
|
|
proxy_redirect http:// https://;
|
|
}
|
|
'';
|
|
};
|
|
|
|
shb.authelia.oidcClients = [
|
|
{
|
|
client_id = cfg.oidcClientID;
|
|
client_name = "Audiobookshelf";
|
|
client_secret.source = cfg.ssoSecretFile;
|
|
public = false;
|
|
authorization_policy = "one_factor";
|
|
redirect_uris = [
|
|
"https://${cfg.subdomain}.${cfg.domain}/auth/openid/callback"
|
|
"https://${cfg.subdomain}.${cfg.domain}/auth/openid/mobile-redirect"
|
|
];
|
|
}
|
|
];
|
|
} {
|
|
systemd.services.audiobookshelfd.serviceConfig = cfg.extraServiceConfig;
|
|
}]);
|
|
}
|