Subject: Request for patch evaluation/review

From: Prafulla Giri <[email-masked]>
Date: Sat, 26 Sep 2020 12:00:40 +0545

Esteemed maintainers (and contributors),

Attached is a patch which, as far as I can see, should work. But it does
not. I would like to submit it here for review. Please tell me what I am
doing wrong or what I am failing to do, so that I might clean up this patch
and submit a proper one.

1. The problem this patch is trying to solve:
Aegisub (guix install aegisub), as it currently is, does not give any sound
(at least on foreign distros). The terminal output reads as follows, when a
video file (with audio) is added into the program and an attempt is made at
playing it: (Video is added to aegisub by using 'Video > Open Video...')
```
ALSA lib conf.c:3683:(snd_config_hooks_call) Cannot open shared library
libasound_module_conf_pulse.so
(/gnu/store/zcjdb23gbhl0pcnvvm8rnlprkfl43cv5-alsa-lib-1.2.2/lib/alsa-lib/libasound_module_conf_pulse.so:
libasound_module_conf_pulse.so: cannot open shared object file: No such
file or directory)
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
```
The complaint being that it can't find libasound_module_conf_pulse.so. This
.so comes from the guix package `alsa-plugins:pulseaudio`. The /gnu/store
directory for it is something like
/gnu/store/...-alsa-plugins-1.2.2-pulseaudio/lib/alsa-lib/libasound_module_conf_pulse.so.
However, the .so file is being looked for inside of the /gnu/store path to
alsa-lib
(/gnu/store/...-alsa-lib-1.2.2/lib/alsa-lib/libasound_module_conf_pulse.so.

2. The Natural Solution:
Since libasound_module_conf_pulse.so is supplied by
`alsa-plugins:pulseaudio`, and the program is looking for it inside the
path to alsa-lib (supplied by `alsa-lib`), union-build is a logical
solution. This is what the patch implements.

3. Problem:
Despite this patch being applied, it continues to look for the .so file
inside the path to alsa-lib and not the union-alsa. What is more, alsa-lib
is not even in the inputs. Only union-alsa is. And yet, it seems to be
trying to use alsa-lib's /gnu/store path, which, the way I see it, violates
guix's functional package management.

4. It's not guix, it's me:
I'm sure this is some mistake on my part. Hence, I submit the diff here for
review.

P. S: The diff has changed a bit because I got this idea of moving
out/lib/alsa-lib/* into out/lib/ just to see if that makes any difference.
Only to realize a little too late that it doesn't. But I send the diff with
those changes included because I didn't stash the previous (cleaner) one.
diff --git a/gnu/packages/video.scm b/gnu/packages/video.scm
index 0f727a6e9e..0e037fb24b 100644
--- a/gnu/packages/video.scm
+++ b/gnu/packages/video.scm
@@ -3836,7 +3836,41 @@ programmers to access a standard API to open and decompress media files.")
        ("hunspell" ,hunspell)
        ("mesa" ,mesa)
        ("libass" ,libass)
-       ("alsa-lib" ,alsa-lib)
+       ("alsa-lib-with-pulseaudio-plugin"
+        ,(package
+           (inherit alsa-lib)
+           (name "alsa-lib-with-pulseaudio-plugin")
+           (source #f)
+           (build-system trivial-build-system)
+           (arguments
+            `(#:modules ((guix build union)
+		         (guix build utils))
+              #:builder
+              (begin
+	        (use-modules (ice-9 match)
+		             (guix build union)
+		             (guix build utils))
+	        (let ((out (assoc-ref %outputs "out")))
+	          (match %build-inputs
+	            (((names . directories) ...)
+	             (union-build out
+			          directories
+			          #:create-all-directories? #f)
+	             #t))
+	          ;; do stuff here
+	          (find-files (string-append out "/lib/alsa-lib/")
+		              (lambda (found stat)
+			        (symlink-relative
+			         found
+			         (string-append
+			          out
+			          "/lib/"
+			          (basename found)))
+			        #t)))
+	        #t)))
+           (inputs
+            `(("alsa-lib" ,alsa-lib)
+              ("alsa-plugins:pulseaudio" ,alsa-plugins "pulseaudio")))))
        ("pulseaudio" ,pulseaudio)
        ("libx11" ,libx11)
        ("freetype" ,freetype)