{ lib, pkgs, config, ... }: let interfaces = import ../../interfaces.nix; cfg = config.services.mopidy; in { services.mopidy = { enable = true; extensionPackages = with pkgs; [ mopidy-iris mopidy-local mopidy-moped mopidy-mpd mopidy-muse mopidy-somafm mopidy-ytmusic ]; settings = { audio.output = "audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/run/snapserver/mopidy.fifo"; file.enabled = false; local = { library = "sqlite"; scan_flush_threshold = 100; media_dir = "/var/lib/music"; included_file_extensions = lib.strings.concatStringsSep "," [ ".aac" ".flac" ".m4a" ".mp3" ".opus" ]; }; m3u = { playlists_dir = "$XDG_CONFIG_DIR/mopidy/playlists"; }; http = { enabled = true; hostname = "::"; port = 6680; }; mpd = { enabled = true; hostname = "::"; port = 6600; }; }; }; networking.firewall.interfaces."${interfaces.lan}".allowedTCPPorts = [ cfg.settings.http.port cfg.settings.mpd.port ]; environment.systemPackages = [ (with config.systemd.services.mopidy.serviceConfig; pkgs.writeShellScriptBin "mopidyctl" '' cmd='sudo -u ${User} -- ${ExecStart}' if [ $# -eq 0 ]; then exec $cmd --help fi exec $cmd "$@" '' ) ]; }