summary refs log tree commit diff
path: root/pkgs/development/tools/poetry/default.nix
blob: 6a4ca2a3057d270077db96e4661fec197c21bd73 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ lib, poetry2nix, python, fetchFromGitHub, runtimeShell }:

poetry2nix.mkPoetryApplication {

  inherit python;

  pyproject = ./pyproject.toml;
  poetrylock = ./poetry.lock;

  src = fetchFromGitHub {
    owner = "sdispater";
    repo = "poetry";
    rev = "1.0.0";
    sha256 = "05xlx9wnlrsjj3i4wawnvxadvqwsdh03401wpgingkbq0c50aimi";
  };

  # "Vendor" dependencies (for build-system support)
  postPatch = ''
    for path in ''${PYTHONPATH//:/ }; do
      echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py
    done
  '';

  # Poetry is a bit special in that it can't use itself as the `build-system` property in pyproject.toml.
  # That's why we need to hackily install outputs completely manually.
  #
  # For projects using poetry normally overriding the installPhase is not required.
  installPhase = ''
    runHook preInstall

    mkdir -p $out/lib/${python.libPrefix}/site-packages
    cp -r poetry $out/lib/${python.libPrefix}/site-packages

    mkdir -p $out/bin
    cat > $out/bin/poetry <<EOF
    #!${python.interpreter}
    import sys

    if __name__ == '__main__':
        sys.path.append("$out/lib/${python.libPrefix}/site-packages")
        from poetry.console import main
        main()
    EOF
    chmod +x $out/bin/poetry

    mkdir -p "$out/share/bash-completion/completions"
    "$out/bin/poetry" completions bash > "$out/share/bash-completion/completions/poetry"
    mkdir -p "$out/share/zsh/vendor-completions"
    "$out/bin/poetry" completions zsh > "$out/share/zsh/vendor-completions/_poetry"
    mkdir -p "$out/share/fish/vendor_completions.d"
    "$out/bin/poetry" completions fish > "$out/share/fish/vendor_completions.d/poetry.fish"

    runHook postInstall
  '';

  # Propagating dependencies leads to issues downstream
  # We've already patched poetry to prefer "vendored" dependencies
  postFixup = ''
    rm $out/nix-support/propagated-build-inputs
  '';

  # Fails because of impurities (network, git etc etc)
  doCheck = false;

  meta = with lib; {
    platforms = platforms.all;
    maintainers = with maintainers; [ adisbladis jakewaksbaum ];
  };
}