Mopidy is a sweet mpd-compatible music player that can play local files and stream from services like Spotify and YouTube.

NixOS has a package for Mopidy and several extensions. You can install them with nix-env -i, but Mopidy will not detect the extensions, and it can be difficult to figure out why.

This is Nix working the way it is supposed to work: the extensions are Python libraries, and the build environment for the mopidy package can’t be altered by installing other packages.

The solution is to make a new environment that depends on the mopidy package and any extension packages you want.

It’s easy with nix-shell:

nix-shell -p mopidy mopidy-mopify mopidy-spotify --run mopidy

Turned into an executable script:

#! /usr/bin/env nix-shell
#! nix-shell -p mopidy mopidy-mopify mopidy-spotify --run mopidy

There is also a mopidy service, used with something like this in /etc/nixos/configuration.nix:

services.mopidy = {
  enable = true;
  extensionPackages = [ pkgs.mopidy-spotify pkgs.mopidy-mopify ];
  configuration = ''
    [spotify]
    username = dade.murphy
    password = hack.the.planet
  '';
};