nixpkgs/nixos/modules/services/misc/subsonic.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

169 lines
5.4 KiB
Nix

{ config, lib, options, pkgs, ... }:
with lib;
let
cfg = config.services.subsonic;
opt = options.services.subsonic;
in {
options = {
services.subsonic = {
enable = mkEnableOption "Subsonic daemon";
home = mkOption {
type = types.path;
default = "/var/lib/subsonic";
description = lib.mdDoc ''
The directory where Subsonic will create files.
Make sure it is writable.
'';
};
listenAddress = mkOption {
type = types.str;
default = "0.0.0.0";
description = lib.mdDoc ''
The host name or IP address on which to bind Subsonic.
Only relevant if you have multiple network interfaces and want
to make Subsonic available on only one of them. The default value
will bind Subsonic to all available network interfaces.
'';
};
port = mkOption {
type = types.port;
default = 4040;
description = lib.mdDoc ''
The port on which Subsonic will listen for
incoming HTTP traffic. Set to 0 to disable.
'';
};
httpsPort = mkOption {
type = types.port;
default = 0;
description = lib.mdDoc ''
The port on which Subsonic will listen for
incoming HTTPS traffic. Set to 0 to disable.
'';
};
contextPath = mkOption {
type = types.path;
default = "/";
description = lib.mdDoc ''
The context path, i.e., the last part of the Subsonic
URL. Typically '/' or '/subsonic'. Default '/'
'';
};
maxMemory = mkOption {
type = types.int;
default = 100;
description = lib.mdDoc ''
The memory limit (max Java heap size) in megabytes.
Default: 100
'';
};
defaultMusicFolder = mkOption {
type = types.path;
default = "/var/music";
description = lib.mdDoc ''
Configure Subsonic to use this folder for music. This option
only has effect the first time Subsonic is started.
'';
};
defaultPodcastFolder = mkOption {
type = types.path;
default = "/var/music/Podcast";
description = lib.mdDoc ''
Configure Subsonic to use this folder for Podcasts. This option
only has effect the first time Subsonic is started.
'';
};
defaultPlaylistFolder = mkOption {
type = types.path;
default = "/var/playlists";
description = lib.mdDoc ''
Configure Subsonic to use this folder for playlists. This option
only has effect the first time Subsonic is started.
'';
};
transcoders = mkOption {
type = types.listOf types.path;
default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ];
defaultText = literalExpression ''[ "''${pkgs.ffmpeg.bin}/bin/ffmpeg" ]'';
description = lib.mdDoc ''
List of paths to transcoder executables that should be accessible
from Subsonic. Symlinks will be created to each executable inside
''${config.${opt.home}}/transcoders.
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.subsonic = {
description = "Personal media streamer";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = ''
${pkgs.jre8}/bin/java -Xmx${toString cfg.maxMemory}m \
-Dsubsonic.home=${cfg.home} \
-Dsubsonic.host=${cfg.listenAddress} \
-Dsubsonic.port=${toString cfg.port} \
-Dsubsonic.httpsPort=${toString cfg.httpsPort} \
-Dsubsonic.contextPath=${cfg.contextPath} \
-Dsubsonic.defaultMusicFolder=${cfg.defaultMusicFolder} \
-Dsubsonic.defaultPodcastFolder=${cfg.defaultPodcastFolder} \
-Dsubsonic.defaultPlaylistFolder=${cfg.defaultPlaylistFolder} \
-Djava.awt.headless=true \
-verbose:gc \
-jar ${pkgs.subsonic}/subsonic-booter-jar-with-dependencies.jar
'';
preStart = ''
# Formerly this module set cfg.home to /var/subsonic. Try to move
# /var/subsonic to cfg.home.
oldHome="/var/subsonic"
if [ "${cfg.home}" != "$oldHome" ] &&
! [ -e "${cfg.home}" ] &&
[ -d "$oldHome" ] &&
[ $(${pkgs.coreutils}/bin/stat -c %u "$oldHome") -eq \
${toString config.users.users.subsonic.uid} ]; then
logger Moving "$oldHome" to "${cfg.home}"
${pkgs.coreutils}/bin/mv -T "$oldHome" "${cfg.home}"
fi
# Install transcoders.
${pkgs.coreutils}/bin/rm -rf ${cfg.home}/transcode ; \
${pkgs.coreutils}/bin/mkdir -p ${cfg.home}/transcode ; \
${pkgs.bash}/bin/bash -c ' \
for exe in "$@"; do \
${pkgs.coreutils}/bin/ln -sf "$exe" ${cfg.home}/transcode; \
done' IGNORED_FIRST_ARG ${toString cfg.transcoders}
'';
serviceConfig = {
# Needed for Subsonic to find subsonic.war.
WorkingDirectory = "${pkgs.subsonic}";
Restart = "always";
User = "subsonic";
UMask = "0022";
};
};
users.users.subsonic = {
description = "Subsonic daemon user";
home = cfg.home;
createHome = true;
group = "subsonic";
uid = config.ids.uids.subsonic;
};
users.groups.subsonic.gid = config.ids.gids.subsonic;
};
}