nixpkgs/pkgs/tools/audio/beets/common.nix

157 lines
3.8 KiB
Nix
Raw Normal View History

2022-05-08 23:25:23 +00:00
{ stdenv
, fetchpatch
, bashInteractive
, diffPlugins
, glibcLocales
, gobject-introspection
, gst_all_1
2022-05-08 23:25:23 +00:00
, lib
, python3Packages
2022-11-21 19:13:36 +00:00
, sphinxHook
, runtimeShell
, writeScript
# plugin deps
2022-05-09 19:19:56 +00:00
, aacgain
, essentia-extractor
, ffmpeg
, flac
, imagemagick
, keyfinder-cli
, mp3gain
, mp3val
, src
, version
, extraPatches ? [ ]
, pluginOverrides ? { }
, disableAllPlugins ? false
2023-10-26 21:02:58 +00:00
, disabledTests ? []
, extraNativeBuildInputs ? []
# tests
, runCommand
, beets
}@inputs:
let
inherit (lib) attrNames attrValues concatMap;
mkPlugin = { name, enable ? !disableAllPlugins, builtin ? false, propagatedBuildInputs ? [ ], testPaths ? [ "test/test_${name}.py" ], wrapperBins ? [ ] }: {
inherit name enable builtin propagatedBuildInputs testPaths wrapperBins;
};
basePlugins = lib.mapAttrs (_: a: { builtin = true; } // a) (import ./builtin-plugins.nix inputs);
allPlugins = lib.mapAttrs (n: a: mkPlugin { name = n; } // a) (lib.recursiveUpdate basePlugins pluginOverrides);
builtinPlugins = lib.filterAttrs (_: p: p.builtin) allPlugins;
enabledPlugins = lib.filterAttrs (_: p: p.enable) allPlugins;
disabledPlugins = lib.filterAttrs (_: p: !p.enable) allPlugins;
pluginWrapperBins = concatMap (p: p.wrapperBins) (attrValues enabledPlugins);
in
python3Packages.buildPythonApplication {
pname = "beets";
inherit src version;
patches = extraPatches;
propagatedBuildInputs = with python3Packages; [
confuse
gst-python
jellyfish
mediafile
munkres
musicbrainzngs
mutagen
pygobject3
pyyaml
reflink
unidecode
typing-extensions
] ++ (concatMap (p: p.propagatedBuildInputs) (attrValues enabledPlugins));
2022-08-02 18:36:46 +00:00
nativeBuildInputs = [
gobject-introspection
2022-11-21 19:13:36 +00:00
sphinxHook
] ++ extraNativeBuildInputs;
2022-08-02 18:36:46 +00:00
buildInputs = [
] ++ (with gst_all_1; [
gst-plugins-base
gst-plugins-good
gst-plugins-ugly
]);
2022-11-21 19:13:36 +00:00
outputs = [ "out" "doc" "man" ];
sphinxBuilders = [ "html" "man" ];
postInstall = ''
mkdir -p $out/share/zsh/site-functions
cp extra/_beet $out/share/zsh/site-functions/
'';
makeWrapperArgs = [
"--set GI_TYPELIB_PATH \"$GI_TYPELIB_PATH\""
"--set GST_PLUGIN_SYSTEM_PATH_1_0 \"$GST_PLUGIN_SYSTEM_PATH_1_0\""
"--prefix PATH : ${lib.makeBinPath pluginWrapperBins}"
];
nativeCheckInputs = with python3Packages; [
pytestCheckHook
mock
rarfile
responses
] ++ pluginWrapperBins;
disabledTestPaths = lib.flatten (attrValues (lib.mapAttrs (_: v: v.testPaths) disabledPlugins));
2023-10-26 21:02:58 +00:00
inherit disabledTests;
# Perform extra "sanity checks", before running pytest tests.
preCheck = ''
# Check for undefined plugins
find beetsplug -mindepth 1 \
\! -path 'beetsplug/__init__.py' -a \
\( -name '*.py' -o -path 'beetsplug/*/__init__.py' \) -print \
| sed -n -re 's|^beetsplug/([^/.]+).*|\1|p' \
| sort -u > plugins_available
${diffPlugins (attrNames builtinPlugins) "plugins_available"}
export BEETS_TEST_SHELL="${bashInteractive}/bin/bash --norc"
export HOME="$(mktemp -d)"
env EDITOR="${writeScript "beetconfig.sh" ''
#!${runtimeShell}
cat > "$1" <<CFG
plugins: ${lib.concatStringsSep " " (attrNames enabledPlugins)}
CFG
''}" "$out/bin/beet" config -e
env EDITOR=true "$out/bin/beet" config -e
'';
passthru.plugins = allPlugins;
passthru.tests.gstreamer = runCommand "beets-gstreamer-test" {
meta.timeout = 60;
} ''
set -euo pipefail
export HOME=$(mktemp -d)
mkdir $out
cat << EOF > $out/config.yaml
replaygain:
backend: gstreamer
EOF
${beets}/bin/beet -c $out/config.yaml > /dev/null
'';
meta = with lib; {
description = "Music tagger and library organizer";
homepage = "https://beets.io";
license = licenses.mit;
maintainers = with maintainers; [ aszlig doronbehar lovesegfault pjones ];
platforms = platforms.linux;
2023-08-14 00:44:29 +00:00
mainProgram = "beet";
};
}