at 24.11-pre 2.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.audiobookshelf; 7in 8{ 9 options = { 10 services.audiobookshelf = { 11 enable = mkEnableOption "Audiobookshelf, self-hosted audiobook and podcast server."; 12 13 package = mkPackageOption pkgs "audiobookshelf" { }; 14 15 dataDir = mkOption { 16 description = "Path to Audiobookshelf config and metadata inside of /var/lib."; 17 default = "audiobookshelf"; 18 type = types.str; 19 }; 20 21 host = mkOption { 22 description = "The host Audiobookshelf binds to."; 23 default = "127.0.0.1"; 24 example = "0.0.0.0"; 25 type = types.str; 26 }; 27 28 port = mkOption { 29 description = "The TCP port Audiobookshelf will listen on."; 30 default = 8000; 31 type = types.port; 32 }; 33 34 user = mkOption { 35 description = "User account under which Audiobookshelf runs."; 36 default = "audiobookshelf"; 37 type = types.str; 38 }; 39 40 group = mkOption { 41 description = "Group under which Audiobookshelf runs."; 42 default = "audiobookshelf"; 43 type = types.str; 44 }; 45 46 openFirewall = mkOption { 47 description = "Open ports in the firewall for the Audiobookshelf web interface."; 48 default = false; 49 type = types.bool; 50 }; 51 }; 52 }; 53 54 config = mkIf cfg.enable { 55 systemd.services.audiobookshelf = { 56 description = "Audiobookshelf is a self-hosted audiobook and podcast server"; 57 58 after = [ "network.target" ]; 59 wantedBy = [ "multi-user.target" ]; 60 61 serviceConfig = { 62 Type = "simple"; 63 User = cfg.user; 64 Group = cfg.group; 65 StateDirectory = cfg.dataDir; 66 WorkingDirectory = "/var/lib/${cfg.dataDir}"; 67 ExecStart = "${cfg.package}/bin/audiobookshelf --host ${cfg.host} --port ${toString cfg.port}"; 68 Restart = "on-failure"; 69 }; 70 }; 71 72 users.users = mkIf (cfg.user == "audiobookshelf") { 73 audiobookshelf = { 74 isSystemUser = true; 75 group = cfg.group; 76 home = "/var/lib/${cfg.dataDir}"; 77 }; 78 }; 79 80 users.groups = mkIf (cfg.group == "audiobookshelf") { 81 audiobookshelf = { }; 82 }; 83 84 networking.firewall = mkIf cfg.openFirewall { 85 allowedTCPPorts = [ cfg.port ]; 86 }; 87 }; 88 89 meta.maintainers = with maintainers; [ wietsedv ]; 90}