summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/uv/default.nix
blob: 662ffffb3f65ef68b5b02527a45e66be34a83226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  buildPythonPackage,
  hatchling,
  lib,
  uv,
}:

buildPythonPackage {
  inherit (uv)
    pname
    version
    src
    meta
    ;
  pyproject = true;

  build-system = [ hatchling ];

  postPatch =
    # Add the path to the uv binary as a fallback after other path search methods have been exhausted
    ''
      substituteInPlace python/uv/_find_uv.py \
        --replace-fail \
        'sysconfig.get_path("scripts", scheme=_user_scheme()),' \
        'sysconfig.get_path("scripts", scheme=_user_scheme()), "${baseNameOf (lib.getExe uv)}",'
    ''
    # Sidestep the maturin build system in favour of reusing the binary already built by nixpkgs,
    # to avoid rebuilding the uv binary for every active python package set.
    + ''
      substituteInPlace pyproject.toml \
        --replace-fail 'requires = ["maturin>=1.0,<2.0"]' 'requires = ["hatchling"]' \
        --replace-fail 'build-backend = "maturin"' 'build-backend = "hatchling.build"'

      cat >> pyproject.toml <<EOF
      [tool.hatch.build]
      packages = ['python/uv']

      EOF
    '';

  postInstall = ''
    mkdir -p $out/bin && ln -s ${lib.getExe uv} $out/bin/uv
  '';

  pythonImportsCheck = [ "uv" ];
}