summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/pynitrokey/default.nix
blob: 52a5b004428be5903586a7af88d3aebc9e9bc2a8 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPypi,
  installShellFiles,
  libnitrokey,
  poetry-core,
  cffi,
  click,
  cryptography,
  fido2,
  hidapi,
  intelhex,
  nkdfu,
  pyusb,
  requests,
  tqdm,
  tlv8,
  semver,
  nethsm,
  nitrokey,
  pyscard,
}:

let
  pname = "pynitrokey";
  version = "0.11.2";
  mainProgram = "nitropy";
in

buildPythonPackage {
  inherit pname version;
  pyproject = true;

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-x0OWFSp6PrW4wTWNP8mLJpbrrYZ66XKOBi8l1vCsko4=";
  };

  nativeBuildInputs = [ installShellFiles ];

  build-system = [ poetry-core ];

  dependencies = [
    cffi
    click
    cryptography
    fido2
    hidapi
    intelhex
    nkdfu
    nitrokey
    pyusb
    requests
    tqdm
    tlv8
    semver
    nethsm
  ];

  optional-dependencies = {
    pcsc = [
      pyscard
    ];
  };

  pythonRelaxDeps = true;

  # libnitrokey is not propagated to users of the pynitrokey Python package.
  # It is only usable from the wrapped bin/nitropy
  makeWrapperArgs = [ "--set LIBNK_PATH ${lib.makeLibraryPath [ libnitrokey ]}" ];

  pythonImportsCheck = [ "pynitrokey" ];

  postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    installShellCompletion --cmd ${mainProgram} \
      --bash <(_NITROPY_COMPLETE=bash_source $out/bin/${mainProgram}) \
      --zsh <(_NITROPY_COMPLETE=zsh_source $out/bin/${mainProgram}) \
      --fish <(_NITROPY_COMPLETE=fish_source $out/bin/${mainProgram})
  '';

  meta = {
    description = "Python client for Nitrokey devices";
    homepage = "https://github.com/Nitrokey/pynitrokey";
    changelog = "https://github.com/Nitrokey/pynitrokey/releases/tag/v${version}";
    license = with lib.licenses; [
      asl20
      mit
    ];
    maintainers = with lib.maintainers; [
      frogamic
    ];
    inherit mainProgram;
  };
}