diff --git a/flake.nix b/flake.nix index 01a684c..500b509 100644 --- a/flake.nix +++ b/flake.nix @@ -125,6 +125,7 @@ systemStateVersion = "23.11"; hostName = "hl-minipc1"; enableNetworkDrives = true; + enableHomelabServices = true; home-manager = { enable = true; version = homeManagerVersion; @@ -136,7 +137,7 @@ enableFonts = true; enableNetworking = true; enableSSH = true; - hardware = { enable = false; }; + hardware = { enable = false; }; }; configuration = (import ./hosts/hl-minipc1.nix { user = user; }); }; diff --git a/hosts/hl-minipc1.nix b/hosts/hl-minipc1.nix index ab1618d..d367a4a 100644 --- a/hosts/hl-minipc1.nix +++ b/hosts/hl-minipc1.nix @@ -12,11 +12,12 @@ fsType = "ext4"; options = [ "nofail" ]; }; - services.audiobookshelf = { + homelab.services.audiobookshelf = { enable = true; host = "0.0.0.0"; openFirewall = true; port = 8000; - dataDir = "audiobookshelf"; + configDir = "/mnt/Data/audiobookshelf/config"; + metadtaDir = "/mnt/Data/audiobookshelf/metadata"; }; } diff --git a/modules/hl-services/audiobookshelf.nix b/modules/hl-services/audiobookshelf.nix new file mode 100644 index 0000000..bb1811d --- /dev/null +++ b/modules/hl-services/audiobookshelf.nix @@ -0,0 +1,98 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.homelab.services.audiobookshelf; +in { + options = { + homelab.services.audiobookshelf = { + enable = mkEnableOption + "Audiobookshelf, self-hosted audiobook and podcast server."; + + package = mkPackageOption pkgs "audiobookshelf" { }; + + configDir = mkOption { + description = + "Path to Audiobookshelf config folder"; + type = types.str; + }; + + metadtaDir = mkOption { + description = + "Path to Audiobookshelf config folder"; + 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 = "/var/lib/${cfg.dataDir}"; + ExecStart = + "${cfg.package}/bin/audiobookshelf --host ${cfg.host} --port ${ + toString cfg.port + } --config ${cfg.configDir} --metadata ${cfg.metadtaDir}"; + 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 ]; }; + }; + + meta.maintainers = with maintainers; [ wietsedv ]; +} diff --git a/modules/hl-services/default.nix b/modules/hl-services/default.nix new file mode 100644 index 0000000..47b5ff0 --- /dev/null +++ b/modules/hl-services/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = [ + ./audiobookshelf.nix + ]; +} diff --git a/modules/main.nix b/modules/main.nix index 2cb96e3..ab573dc 100644 --- a/modules/main.nix +++ b/modules/main.nix @@ -3,6 +3,7 @@ , hostName , system , enableNetworkDrives ? false +, enableHomelabServices ? false # Desktop Module , desktop ? { enable = false; @@ -52,6 +53,8 @@ }) ] else [ ]) ++ (if enableNetworkDrives then [ (import ./network-drives.nix) + ] else [ ]) ++ (if enableHomelabServices then [ + (import ./hl-services) ] else [ ]) ; }