about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/keyring-pass/default.nix
blob: c9ac11c9313a899a810ce4ea7c88c2b6a7e73a81 (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
70
71
72
73
74
75
76
77
78
{ lib
, buildPythonPackage
, fetchFromGitHub
, gnupg
, keyring
, pass
, poetry-core
, pythonOlder
}:
buildPythonPackage rec {
  pname = "keyring-pass";
  version = "0.9.2";
  disabled = pythonOlder "3.6";

  pyproject = true;

  src = fetchFromGitHub {
    owner = "nazarewk";
    repo = "keyring_pass";
    rev = "refs/tags/v${version}";
    hash = "sha256-Sf7eDOB3prH2s6BzdBtxewSweC0ibLXVxNHBJRRaJe4=";
  };

  postPatch = ''
    substituteInPlace keyring_pass/__init__.py \
      --replace 'pass_binary = "pass"' 'pass_binary = "${lib.getExe pass}"'
  '';

  nativeBuildInputs = [
    poetry-core
  ];

  nativeCheckInputs = [
    keyring
    gnupg
  ];

  checkPhase = ''
    export HOME="$TMPDIR"

    # generate temporary GPG identity
    cat <<EOF | gpg --gen-key --batch /dev/stdin
    %no-protection
    %transient-key
    Key-Type: 1
    Key-Length: 1024
    Subkey-Type: 1
    Subkey-Length: 1024
    Name-Real: test
    Name-Email: test@example.com
    Expire-Date: 1
    EOF

    # configure password store
    ${lib.getExe pass} init test@example.com

    # Configure `keyring` CLI
    # first make sure `keyring-pass` is in "$PYTHONPATH"
    [[ "$PYTHONPATH" == *"$out"/lib/python*/site-packages* ]]
    export PYTHON_KEYRING_BACKEND="keyring_pass.PasswordStoreBackend"

    # confirm set/get/del works
    keyring set test-service test-username <<<"test-password"
    test "$(keyring get test-service test-username)" == "test-password"
    keyring del test-service test-username
  '';

  pythonImportsCheck = [
    "keyring_pass"
  ];

  meta = {
    description = "Password Store (pass) backend for python's keyring";
    homepage = "https://github.com/nazarewk/keyring_pass";
    license = lib.licenses.mit;
    maintainers = [ lib.maintainers.nazarewk ];
  };
}