about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--nix/package.nix197
1 files changed, 93 insertions, 104 deletions
diff --git a/nix/package.nix b/nix/package.nix
index 1c7d836..979696b 100644
--- a/nix/package.nix
+++ b/nix/package.nix
@@ -13,8 +13,6 @@
   installShellFiles,
   # buildInputs
   mpv-unwrapped,
-  python3Packages,
-  python3,
   ffmpeg,
   openssl,
   libffi,
@@ -28,122 +26,113 @@
   fd,
   pkg-config,
   SDL2,
+  python3,
   # Passthru
   tree-sitter-yts,
-}:
-rustPlatform.buildRustPackage (finalAttrs: {
-  pname = "yt";
-  inherit
-    ((builtins.fromTOML (builtins.readFile
-          ../Cargo.toml)).workspace.package)
-    version
-    ;
+}: let
+  python = python3.withPackages (ps: [ps.yt-dlp]);
+in
+  rustPlatform.buildRustPackage (finalAttrs: {
+    pname = "yt";
+    inherit
+      ((builtins.fromTOML (builtins.readFile
+            ../Cargo.toml)).workspace.package)
+      version
+      ;
 
-  src = lib.cleanSourceWith {
-    src = lib.cleanSource ./..;
-    filter = name: type:
-      (type == "directory")
-      || (builtins.elem (builtins.baseNameOf name) [
-        "Cargo.toml"
-        "Cargo.lock"
-        "mkdb.sh"
-        "help.str"
-        "raw_error_warning.txt"
-        "urllib3_polyfill.py"
-      ])
-      || (lib.strings.hasSuffix ".rs" (builtins.baseNameOf name))
-      || (lib.strings.hasSuffix ".h" (builtins.baseNameOf name))
-      || (lib.strings.hasSuffix ".sql" (builtins.baseNameOf name));
-  };
+    src = lib.cleanSourceWith {
+      src = lib.cleanSource ./..;
+      filter = name: type:
+        (type == "directory")
+        || (builtins.elem (builtins.baseNameOf name) [
+          "Cargo.toml"
+          "Cargo.lock"
+          "mkdb.sh"
+          "help.str"
+          "raw_error_warning.txt"
+          "golden.txt"
+        ])
+        || (lib.strings.hasSuffix ".rs" (builtins.baseNameOf name))
+        || (lib.strings.hasSuffix ".h" (builtins.baseNameOf name))
+        || (lib.strings.hasSuffix ".sql" (builtins.baseNameOf name));
+    };
 
-  nativeBuildInputs = [
-    installShellFiles
-    makeWrapper
-    sqlite
-    fd
-    pkg-config
-  ];
+    nativeBuildInputs = [
+      installShellFiles
+      makeWrapper
+      sqlite
+      fd
+      pkg-config
+    ];
 
-  buildInputs = [
-    mpv-unwrapped.dev
-    ffmpeg
-    openssl
-    libffi
-    zlib
-    curl.dev
-  ];
+    buildInputs = [
+      mpv-unwrapped.dev
+      ffmpeg
+      openssl
+      libffi
+      zlib
+      curl.dev
+      python
+    ];
 
-  checkInputs = [
-    # Needed for the tests in `libmpv2`
-    SDL2
-  ];
+    checkInputs = [
+      # Needed for the tests in `libmpv2`
+      SDL2
+    ];
 
-  env = let
-    clang_version =
-      lib.versions.major
-      llvmPackages_latest.clang-unwrapped.version;
-  in {
-    # Needed for the compile time sqlite checks.
-    DATABASE_URL = "sqlite://database.sqlx";
+    env = let
+      clang_version =
+        lib.versions.major
+        llvmPackages_latest.clang-unwrapped.version;
+    in {
+      # Needed for the compile time sqlite checks.
+      DATABASE_URL = "sqlite://database.sqlx";
 
-    # Required by yt_dlp
-    FFMPEG_LOCATION = "${lib.getExe ffmpeg}";
+      # Required by yt_dlp
+      FFMPEG_LOCATION = "${lib.getExe ffmpeg}";
 
-    # Needed for the libmpv2.
-    C_INCLUDE_PATH = "${glibc.dev}/include";
-    LIBCLANG_INCLUDE_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/clang/${clang_version}/include";
-    LIBCLANG_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/libclang.so";
-  };
+      # Tell pyo3 which python to use.
+      PYO3_PYTHON = lib.getExe python;
 
-  doCheck = true;
+      # Needed for the libmpv2.
+      C_INCLUDE_PATH = "${glibc.dev}/include";
+      LIBCLANG_INCLUDE_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/clang/${clang_version}/include";
+      LIBCLANG_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/libclang.so";
+    };
 
-  prePatch = ''
-    # Generate the sqlite db, so that we can run the comp-time sqlite checks.
-    bash ./scripts/mkdb.sh
-  '';
+    doCheck = true;
+    checkFlags = [
+      # All of these tests try to connect to the internet to download test data.
+      "--skip=select::base::test_base"
+      "--skip=select::file::test_file"
+      "--skip=select::options::test_options"
+      "--skip=subscriptions::import_export::test_import_export"
+      "--skip=subscriptions::naming_subscriptions::test_naming_subscriptions"
+      "--skip=videos::downloading::test_downloading"
+    ];
 
-  passthru = {
-    inherit tree-sitter-yts;
-  };
+    prePatch = ''
+      # Generate the sqlite db, so that we can run the comp-time sqlite checks.
+      bash ./scripts/mkdb.sh
+    '';
 
-  cargoLock = {
-    lockFile = ../Cargo.lock;
-    outputHashes = {
-      "ruff_python_ast-0.0.0" = "sha256-/CVpNBOBpvQhz7X80nUHC2x7ZxxCJH8O0WAABJKEriA=";
-      "rustpython-0.4.0" = "sha256-VRWmqwbuaxvI4cR3wWQZlYiiMAiRbqpKcsNpI7T+AP8=";
-      "rustpython-doc-0.3.0" = "sha256-34ERuLFKzUD9Xmf1zlafe42GLWZfUlw17ejf/NN6yH4=";
+    passthru = {
+      inherit tree-sitter-yts;
     };
-  };
-
-  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";
+    cargoLock = {
+      lockFile = ../Cargo.lock;
+    };
 
-    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) \
-      --zsh <(COMPLETE=zsh $out/bin/yt)
+    postInstall = ''
+      installShellCompletion --cmd yt \
+        --bash <(COMPLETE=bash $out/bin/yt) \
+        --fish <(COMPLETE=fish $out/bin/yt) \
+        --zsh <(COMPLETE=zsh $out/bin/yt)
 
-    # 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 PYTHONPATH ${pythonPath}
-  '';
-})
+      # 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
+    '';
+  })