From 1d95ad6edb20dfb845f1e68bbd95dedc8a56082c Mon Sep 17 00:00:00 2001 From: rasmus-kirk Date: Fri, 30 May 2025 15:14:59 +0200 Subject: [PATCH] fixed statedir for audiobookshelf --- CHANGELOG.md | 5 + nixarr/audiobookshelf/default.nix | 6 +- .../audiobookshelf/shelf-module/default.nix | 91 +++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 nixarr/audiobookshelf/shelf-module/default.nix diff --git a/CHANGELOG.md b/CHANGELOG.md index 0299b2b..2d03970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +Added: +- Audiobookshelf service, with expose options + ## 2025-05-28 Added: diff --git a/nixarr/audiobookshelf/default.nix b/nixarr/audiobookshelf/default.nix index 21993ec..6c29895 100644 --- a/nixarr/audiobookshelf/default.nix +++ b/nixarr/audiobookshelf/default.nix @@ -8,6 +8,10 @@ with lib; let cfg = config.nixarr.audiobookshelf; nixarr = config.nixarr; in { + imports = [ + ./shelf-module + ]; + options.nixarr.audiobookshelf = { enable = mkOption { type = types.bool; @@ -165,7 +169,7 @@ in { # Always prioritise Audiobookshelf IO systemd.services.audiobookshelf.serviceConfig.IOSchedulingPriority = 0; - services.audiobookshelf = { + util-nixarr.services.audiobookshelf = { enable = cfg.enable; package = cfg.package; port = cfg.port; diff --git a/nixarr/audiobookshelf/shelf-module/default.nix b/nixarr/audiobookshelf/shelf-module/default.nix new file mode 100644 index 0000000..d420042 --- /dev/null +++ b/nixarr/audiobookshelf/shelf-module/default.nix @@ -0,0 +1,91 @@ +{ + config, + lib, + pkgs, + ... +}: + +with lib; + +let + cfg = config.util-nixarr.services.audiobookshelf; +in +{ + options.util-nixarr.services.audiobookshelf = { + enable = mkEnableOption "Audiobookshelf, self-hosted audiobook and podcast server"; + + package = mkPackageOption pkgs "audiobookshelf" { }; + + dataDir = mkOption { + description = "Path to Audiobookshelf config and metadata inside of /var/lib."; + default = "audiobookshelf"; + type = types.str; + }; + + host = mkOption { + description = "The host Audiobookshelf binds to."; + default = "127.0.0.1"; + example = "0.0.0.0"; + type = types.str; + }; + + port = mkOption { + description = "The TCP port Audiobookshelf will listen on."; + default = 8000; + type = types.port; + }; + + user = mkOption { + description = "User account under which Audiobookshelf runs."; + default = "audiobookshelf"; + type = types.str; + }; + + group = mkOption { + description = "Group under which Audiobookshelf runs."; + default = "audiobookshelf"; + type = types.str; + }; + + openFirewall = mkOption { + description = "Open ports in the firewall for the Audiobookshelf web interface."; + default = false; + type = types.bool; + }; + }; + + config = mkIf cfg.enable { + systemd.services.audiobookshelf = { + description = "Audiobookshelf is a self-hosted audiobook and podcast server"; + + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "simple"; + User = cfg.user; + Group = cfg.group; + StateDirectory = cfg.dataDir; + WorkingDirectory = cfg.dataDir; + ExecStart = "${cfg.package}/bin/audiobookshelf --host ${cfg.host} --port ${toString cfg.port}"; + Restart = "on-failure"; + }; + }; + + users.users = mkIf (cfg.user == "audiobookshelf") { + audiobookshelf = { + isSystemUser = true; + group = cfg.group; + home = "/var/lib/${cfg.dataDir}"; + }; + }; + + users.groups = mkIf (cfg.group == "audiobookshelf") { + audiobookshelf = { }; + }; + + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.port ]; + }; + }; +}