Alright, I've gotten it working.

After discussing on IRC with a few different people, I decided that making a new beets-specific variable was probably the best way forward. I've created $GUIX_BEETSPLUGINS for this purpose, which points to `/gnu/store/xxx-profile/lib/python3.9/site-packages`, and appended it to the $GUIX_PYTHONPATH which wraps 'beets'.

I've also wrapped the whole definition in a `let` to programmatically set the python version, so it is easier to update should it change. Ideally, this would be set from the input python's version, but I don't know how to do that (yet).

I've also taken the liberty of moving all of the unnecessarily-propagated inputs to 'beets-bandcamp' and made them normal inputs.

Patch is attached, let me know what You think.
From 5ebae013a269c0d82a6d3af9124514bbb0d7536f Mon Sep 17 00:00:00 2001
From: Christopher Rodriguez <yewsc...@gmail.com>
Date: Tue, 21 Dec 2021 14:25:51 -0500
Subject: [PATCH] Added $GUIX_BEETSPLUGINS variable

---
 gnu/packages/music.scm | 177 ++++++++++++++++++++++++-----------------
 1 file changed, 102 insertions(+), 75 deletions(-)

diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index ba0658470c..f0fa69964a 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -3780,82 +3780,98 @@ (define-public instantmusic
     (license license:expat))))
 
 (define-public beets
-  (package
-    (name "beets")
-    (version "1.5.0")
-    (source (origin
-              (method url-fetch)
-              (uri (pypi-uri "beets" version))
-              (sha256
-               (base32
-                "0arl4nc3y8iwa331hf6ggai19y8ns9pl03g5d6ac857wq2x7nzw8"))))
-    (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'set-HOME
-           (lambda _
-             (setenv "HOME" (string-append (getcwd) "/tmp"))
-             #t))
-         (replace 'check
-           (lambda* (#:key tests? #:allow-other-keys)
-             (when tests?
-               (invoke "pytest" "-v" "test"))))
-         ;; Wrap the executable, so it can find python-gi (aka
-         ;; pygobject) and gstreamer plugins.
-         (add-after 'wrap 'wrap-typelib
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((prog (string-append (assoc-ref outputs "out")
-                                        "/bin/beet"))
-                   (plugins (getenv "GST_PLUGIN_SYSTEM_PATH"))
-                   (types (getenv "GI_TYPELIB_PATH")))
-               (wrap-program prog
-                 `("GST_PLUGIN_SYSTEM_PATH" ":" prefix (,plugins))
-                 `("GI_TYPELIB_PATH" ":" prefix (,types)))
-               #t))))))
-    (native-inputs
-     (list gobject-introspection
-           python-flask
-           python-mock
-           python-py7zr
-           python-pytest-6
-           python-responses))
-    (inputs
-     (list bash-minimal
-           gst-plugins-base
-           gst-plugins-good
-           gstreamer
-           python-confuse
-           python-jellyfish
-           python-mediafile
-           python-munkres
-           python-musicbrainzngs
-           python-pyyaml
-           python-six
-           python-unidecode
-           ;; Optional dependencies for plugins. Some of these are also required by tests.
-           python-beautifulsoup4 ; For lyrics.
-           python-discogs-client ; For discogs.
-           python-mpd2 ; For mpdstats.
-           python-mutagen ; For scrub.
-           python-langdetect ; For lyrics.
-           python-pillow ; For fetchart, embedart, thumbnails.
-           python-pyacoustid ; For chroma.
-           python-pygobject ; For bpd, replaygain.
-           python-pylast ; For lastgenre, lastimport.
-           python-pyxdg ; For thumbnails.
-           python-rarfile ; For import.
-           python-reflink ; For reflink.
-           python-requests
-           python-requests-oauthlib)) ; For beatport.
-    (home-page "https://beets.io";)
-    (synopsis "Music organizer")
-    (description "The purpose of beets is to get your music collection
+  (let ((beets-python-version "3.9"))
+    (package
+      (name "beets")
+      (version "1.5.0")
+      (source (origin
+                (method url-fetch)
+                (uri (pypi-uri "beets" version))
+                (sha256
+                 (base32
+                  "0arl4nc3y8iwa331hf6ggai19y8ns9pl03g5d6ac857wq2x7nzw8"))))
+      (build-system python-build-system)
+      ;; Beets plugins are found by beets via PYTHONPATH; the following
+      ;; search path ensures that they are found even when Python is not
+      ;; present in the profile.
+      (native-search-paths
+       ;; XXX: Attempting to use (package-native-search-paths python) here would
+       ;; cause an error about python being an unbound variable in the
+       ;; tests. Instead, we set and use an explicit python version.
+       (list
+        (search-path-specification
+         (variable "GUIX_BEETSPLUGINPATH")
+         (separator #f)
+         (files (list (string-append "lib/python" beets-python-version "/site-packages"))))))
+      (arguments
+       `(#:phases
+         (modify-phases %standard-phases
+           (add-after 'unpack 'set-HOME
+             (lambda _
+               (setenv "HOME" (string-append (getcwd) "/tmp"))
+               #t))
+           (replace 'check
+             (lambda* (#:key tests? #:allow-other-keys)
+               (when tests?
+                 (invoke "pytest" "-v" "test"))))
+           ;; Wrap the executable, so it can find python-gi (aka pygobject) and
+           ;; gstreamer plugins.
+           (add-after 'wrap 'wrap-typelib
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((prog (string-append (assoc-ref outputs "out")
+                                           "/bin/beet"))
+                      (gst-plugins (getenv "GST_PLUGIN_SYSTEM_PATH"))
+                      (beets-plugins ":${GUIX_BEETSPLUGINPATH}")
+                      (types (getenv "GI_TYPELIB_PATH")))
+                 (wrap-program prog
+                   `("GST_PLUGIN_SYSTEM_PATH" ":" prefix (,gst-plugins))
+                   `("GI_TYPELIB_PATH" ":" prefix (,types))
+                   `("GUIX_PYTHONPATH" ":" prefix (,beets-plugins))))
+               #t)))))
+      (native-inputs
+       (list gobject-introspection
+             python-flask
+             python-mock
+             python-py7zr
+             python-pytest-6
+             python-responses))
+      (inputs
+       (list bash-minimal
+             gst-plugins-base
+             gst-plugins-good
+             gstreamer
+             python
+             python-confuse
+             python-jellyfish
+             python-mediafile
+             python-munkres
+             python-musicbrainzngs
+             python-pyyaml
+             python-six
+             python-unidecode
+             ;; Optional dependencies for plugins. Some of these are also required by tests.
+             python-beautifulsoup4 ; For lyrics.
+             python-discogs-client ; For discogs.
+             python-mpd2 ; For mpdstats.
+             python-mutagen ; For scrub.
+             python-langdetect ; For lyrics.
+             python-pillow ; For fetchart, embedart, thumbnails.
+             python-pyacoustid ; For chroma.
+             python-pygobject ; For bpd, replaygain.
+             python-pylast ; For lastgenre, lastimport.
+             python-pyxdg ; For thumbnails.
+             python-rarfile ; For import.
+             python-reflink ; For reflink.
+             python-requests
+             python-requests-oauthlib)) ; For beatport.
+      (home-page "https://beets.io";)
+      (synopsis "Music organizer")
+      (description "The purpose of beets is to get your music collection
 right once and for all.  It catalogs your collection, automatically
 improving its metadata as it goes using the MusicBrainz database.
 Then it provides a variety of tools for manipulating and accessing
 your music.")
-    (license license:expat)))
+      (license license:expat))))
 
 (define-public beets-next
   (deprecated-package "beets-next" beets))
@@ -3871,10 +3887,21 @@ (define-public beets-bandcamp
                (base32
                 "0dwbdkrb9c0ppzm5s78h47ndpr88cw1k0z8fgfhkl706wazx2ddg"))))
     (build-system python-build-system)
-    (arguments '(#:tests? #f))          ; there are no tests
+    (arguments
+     `(#:tests? #f))
     (propagated-inputs
-     (list beets python-isodate python-beautifulsoup4 python-requests
-           python-six))
+     (list python-isodate))
+    (inputs
+     (list beets
+           python-beautifulsoup4
+           python-confuse
+           python-jellyfish
+           python-mediafile
+           python-munkres
+           python-musicbrainzngs
+           python-pyyaml
+           python-six
+           python-unidecode))
     (home-page "https://github.com/unrblt/beets-bandcamp";)
     (synopsis "Bandcamp plugin for beets")
     (description
-- 
2.34.0

Attachment: OpenPGP_0x1102102EBE7C3AE4.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to