{ config, lib, pkgs, ... }: let music = config.xdg.userDirs.music; database = "${config.xdg.dataHome}/beets/music.db"; lyrics = "${config.xdg.cacheHome}/ncmpcpp/lyrics"; in { home.activation = { setupMusic = lib.hm.dag.entryAfter ["writeBoundary"] '' $DRY_RUN_CMD mkdir $VERBOSE_ARG -p ''$(dirname "${database}") $DRY_RUN_CMD mkdir $VERBOSE_ARG -p ${lyrics} ''; }; home.packages = with pkgs; [ mpc-cli ]; services.mopidy = { enable = true; extensionPackages = with pkgs; [ mopidy-bandcamp # mopidy-beets: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/audio/mopidy/somafm.nix mopidy-mpd mopidy-somafm mopidy-youtube ]; settings = { core = { restore_state = true; }; file = { media_dirs = [ "${music}|Music" ]; follow_symlinks = false; show_dotfiles = false; excluded_file_extensions = [ ".directory" ".html" ".jpeg" ".jpg" ".log" ".nfo" ".pdf" ".png" ".txt" ".zip" ]; }; mpd = { enabled = true; hostname = "localhost"; port = 6600; }; bandcamp = { enabled = true; discover_tags = [ "jazz" "funk" "electronic" ]; }; somafm = { enabled = true; encoding = "aac"; quality = "highest"; dj_as_artist = true; }; youtube = { enabled = true; # NOTE: 'youtube-dl' dependency is hardcoded for the # 'mopidy-youtube' package so setting this to "yt_dlp" to use # 'yt-dlp" package will only lead to errors. youtube_dl_package = "youtube_dl"; allow_cache = true; search_results = 20; playlist_max_videos = 100; autoplay_enabled = false; }; }; }; programs.beets = let mpd = config.services.mopidy.settings.mpd; in { enable = true; mpdIntegration = { enableStats = true; enableUpdate = true; host = mpd.hostname; port = mpd.port; }; settings = { directory = music; library = database; import = { move = true; }; plugins = [ "fetchart" "embedart" "lyrics" "lastgenre" ]; fetchart = { cautious = true; maxwidth = 1024; }; lastgenre = { count = 3; fallback = "''"; }; }; }; programs.ncmpcpp = { enable = true; package = pkgs.ncmpcpp.override { taglibSupport = false; }; bindings = [ { key = "j"; command = "scroll_down"; } { key = "k"; command = "scroll_up"; } { key = "J"; command = [ "select_item" "scroll_down" ]; } { key = "K"; command = [ "select_item" "scroll_up" ]; } { key = "ctrl-b"; command = "page_up"; } { key = "ctrl-f"; command = "page_down"; } { key = "ctrl-u"; command = "page_up"; } { key = "ctrl-d"; command = "page_down"; } { key = "g"; command = "move_home"; } { key = "G"; command = "move_end"; } { key = "backspace"; command = "delete_playlist_items"; } { key = "l"; command = "next_column"; } { key = "l"; command = "slave_screen"; } { key = "+"; command = "volume_up"; } { key = "0"; command = "volume_up"; } { key = "h"; command = "previous_column"; } { key = "h"; command = "master_screen"; } { key = "-"; command = "volume_down"; } { key = "9"; command = "volume_down"; } { key = "?"; command = "show_help"; } { key = "space"; command = "pause"; } { key = "U"; command = "update_database"; } { key = "n"; command = "next_found_item"; } { key = "N"; command = "previous_found_item"; } { key = "p"; command = "previous_found_item"; } { key = "L"; command = "show_lyrics"; } ]; settings = { ncmpcpp_directory = "${config.xdg.configHome}/ncmpcpp"; lyrics_directory = lyrics; progressbar_look = "━━"; user_interface = "alternative"; alternative_ui_separator_color = "yellow:b"; alternative_header_first_line_format = "$b$4$aqqu$/a$9 {%t}|{%f} $4$atqq$/a$9$/b"; }; }; programs.kitty.keybindings = let leader = "ctrl+space"; in { "${leader}>o>m" = "launch --type=overlay ncmpcpp"; }; }