about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-17 09:05:28 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-17 09:05:28 +0200
commitea77b898e5dfb2a7900a87a1bb73167a6e1a140c (patch)
treefa92f3be291ab90e858f0571450db58f88e12df7
parentrefactor(yt_dlp): Split the big `lib.rs` file up (diff)
downloadyt-ea77b898e5dfb2a7900a87a1bb73167a6e1a140c.zip
fix(package): Set the PYTHONPATH ourselves
The propagation mechanism seems to be python exclusive and not something
that works inside the `buildRustPackage` function.
-rw-r--r--package/package.nix26
1 files changed, 23 insertions, 3 deletions
diff --git a/package/package.nix b/package/package.nix
index 5a29fad..f4d6eac 100644
--- a/package/package.nix
+++ b/package/package.nix
@@ -14,6 +14,7 @@
   # buildInputs
   mpv-unwrapped,
   python3Packages,
+  python3,
   ffmpeg,
   openssl,
   libffi,
@@ -61,7 +62,6 @@ rustPlatform.buildRustPackage (finalAttrs: {
   ];
 
   buildInputs = [
-    python3Packages.yt-dlp
     mpv-unwrapped.dev
     ffmpeg
     openssl
@@ -110,7 +110,26 @@ rustPlatform.buildRustPackage (finalAttrs: {
     };
   };
 
-  postInstall = ''
+  postInstall = let
+    collectDeps = pkg: let
+      next = pkg.propagatedBuildInputs or [];
+    in
+      [pkg]
+      ++ next
+      ++ (lib.flatten (builtins.map collectDeps next));
+
+    loadPythonDep = der: "${der}/lib/python${lib.versions.majorMinor python3.version}/site-packages";
+
+    pythonPath = builtins.concatStringsSep ":" (lib.lists.unique (
+      builtins.map loadPythonDep (
+        (collectDeps python3Packages.yt-dlp)
+        ++ [
+          # HACK(@bpeetz): These packages are not picked up in the traversal up top. <2025-06-16>
+          python3Packages.chardet
+        ]
+      )
+    ));
+  in ''
     installShellCompletion --cmd yt \
       --bash <(COMPLETE=bash $out/bin/yt) \
       --fish <(COMPLETE=fish $out/bin/yt) \
@@ -119,6 +138,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
     # NOTE: We cannot clear the path, because we need access to the $EDITOR. <2025-04-04>
     wrapProgram $out/bin/yt \
       --prefix PATH : ${lib.makeBinPath finalAttrs.buildInputs} \
-      --set YTDLP_NO_PLUGINS 1
+      --set YTDLP_NO_PLUGINS 1 \
+      --set PYTHONPATH ${pythonPath}
   '';
 })