1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchPypi,
6 installShellFiles,
7 libnitrokey,
8 poetry-core,
9 cffi,
10 click,
11 cryptography,
12 fido2,
13 hidapi,
14 intelhex,
15 nkdfu,
16 pyusb,
17 requests,
18 tqdm,
19 tlv8,
20 semver,
21 nethsm,
22 nitrokey,
23 pyscard,
24}:
25
26let
27 pname = "pynitrokey";
28 version = "0.10.0";
29 mainProgram = "nitropy";
30in
31
32buildPythonPackage {
33 inherit pname version;
34 pyproject = true;
35
36 src = fetchPypi {
37 inherit pname version;
38 hash = "sha256-Kr6VtBADLvXUva7csbsHujGzBfRG1atJLF7qbIWmToM=";
39 };
40
41 nativeBuildInputs = [ installShellFiles ];
42
43 build-system = [ poetry-core ];
44
45 dependencies = [
46 cffi
47 click
48 cryptography
49 fido2
50 hidapi
51 intelhex
52 nkdfu
53 nitrokey
54 pyusb
55 requests
56 tqdm
57 tlv8
58 semver
59 nethsm
60 ];
61
62 optional-dependencies = {
63 pcsc = [
64 pyscard
65 ];
66 };
67
68 pythonRelaxDeps = true;
69
70 # libnitrokey is not propagated to users of the pynitrokey Python package.
71 # It is only usable from the wrapped bin/nitropy
72 makeWrapperArgs = [ "--set LIBNK_PATH ${lib.makeLibraryPath [ libnitrokey ]}" ];
73
74 pythonImportsCheck = [ "pynitrokey" ];
75
76 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
77 installShellCompletion --cmd ${mainProgram} \
78 --bash <(_NITROPY_COMPLETE=bash_source $out/bin/${mainProgram}) \
79 --zsh <(_NITROPY_COMPLETE=zsh_source $out/bin/${mainProgram}) \
80 --fish <(_NITROPY_COMPLETE=fish_source $out/bin/${mainProgram})
81 '';
82
83 meta = with lib; {
84 description = "Python client for Nitrokey devices";
85 homepage = "https://github.com/Nitrokey/pynitrokey";
86 changelog = "https://github.com/Nitrokey/pynitrokey/releases/tag/v${version}";
87 license = with licenses; [
88 asl20
89 mit
90 ];
91 maintainers = with maintainers; [
92 frogamic
93 ];
94 inherit mainProgram;
95 };
96}