about summary refs log tree commit diff
path: root/pkgs/tools/security/pass
diff options
context:
space:
mode:
authorDrew Risinger <drewrisinger@users.noreply.github.com>2021-03-21 22:36:31 -0400
committerDrew Risinger <drewrisinger@users.noreply.github.com>2021-04-06 09:18:44 -0400
commit40b9f4ef8777e927fdbcbcad104a359f21e4c122 (patch)
treed2cb3723c4377b43279b615df1f1b28d2f203614 /pkgs/tools/security/pass
parent413e9561f817ae4cbeb870f777ec5a66ab34e76c (diff)
passExtensions.pass-import: convert to buildPythonApplication
Rewrite the derivation using buildPythonApplication, which makes the
wrappers a lot cleaner.
Adds tests because the application wasn't working as intended
due to the wrong file-magic python package (used "filemagic" instead of
desired "file-magic").
Diffstat (limited to 'pkgs/tools/security/pass')
-rw-r--r--pkgs/tools/security/pass/extensions/0001-Fix-installation-with-Nix.patch41
-rw-r--r--pkgs/tools/security/pass/extensions/default.nix4
-rw-r--r--pkgs/tools/security/pass/extensions/import.nix70
3 files changed, 42 insertions, 73 deletions
diff --git a/pkgs/tools/security/pass/extensions/0001-Fix-installation-with-Nix.patch b/pkgs/tools/security/pass/extensions/0001-Fix-installation-with-Nix.patch
deleted file mode 100644
index 55822f170d14e..0000000000000
--- a/pkgs/tools/security/pass/extensions/0001-Fix-installation-with-Nix.patch
+++ /dev/null
@@ -1,41 +0,0 @@
-From 611cb2de31a460789c44615d3a52b8d24dbd6fdd Mon Sep 17 00:00:00 2001
-From: Maximilian Bosch <maximilian@mbosch.me>
-Date: Fri, 4 Dec 2020 21:53:52 +0100
-Subject: [PATCH] Fix installation with Nix
-
----
- Makefile | 2 +-
- setup.py | 4 ++--
- 2 files changed, 3 insertions(+), 3 deletions(-)
-
-diff --git a/Makefile b/Makefile
-index 2febf4e..8feab91 100644
---- a/Makefile
-+++ b/Makefile
-@@ -7,7 +7,7 @@ all:
- 	@echo
- 
- install:
--	@python3 setup.py install --root="$(DESTDIR)" --optimize=1 --skip-build
-+	@python3 setup.py install --root="$(DESTDIR)" --optimize=1 --skip-build --prefix=
- 	@echo
- 	@echo "pass-import is installed succesfully"
- 	@echo
-diff --git a/setup.py b/setup.py
-index b30870c..d9fedbc 100644
---- a/setup.py
-+++ b/setup.py
-@@ -15,8 +15,8 @@ with Path('pass_import', '__about__.py').open() as file:
- with open('README.md') as file:
-     long_description = file.read()
- 
--share = Path(sys.prefix, 'share')
--lib = Path('/usr', 'lib', 'password-store', 'extensions')
-+share = Path('/share')
-+lib = Path('/lib', 'password-store', 'extensions')
- if '--user' in sys.argv:
-     lib = Path.home() / '.password-store' / 'extensions'
-     if 'XDG_DATA_HOME' in os.environ:
--- 
-2.28.0
-
diff --git a/pkgs/tools/security/pass/extensions/default.nix b/pkgs/tools/security/pass/extensions/default.nix
index 1f41a69248214..96c252156de8b 100644
--- a/pkgs/tools/security/pass/extensions/default.nix
+++ b/pkgs/tools/security/pass/extensions/default.nix
@@ -7,9 +7,7 @@ with pkgs;
     pythonPackages = python3Packages;
   };
   pass-checkup = callPackage ./checkup.nix {};
-  pass-import = callPackage ./import.nix {
-    pythonPackages = python3Packages;
-  };
+  pass-import = callPackage ./import.nix {};
   pass-otp = callPackage ./otp.nix {};
   pass-tomb = callPackage ./tomb.nix {};
   pass-update = callPackage ./update.nix {};
diff --git a/pkgs/tools/security/pass/extensions/import.nix b/pkgs/tools/security/pass/extensions/import.nix
index 11b4eecd14d99..be2492112c3f8 100644
--- a/pkgs/tools/security/pass/extensions/import.nix
+++ b/pkgs/tools/security/pass/extensions/import.nix
@@ -1,17 +1,12 @@
-{ lib, stdenv, fetchFromGitHub, pythonPackages, makeWrapper, fetchpatch }:
-
-let
-  pythonEnv = pythonPackages.python.withPackages (p: [
-    p.defusedxml
-    p.setuptools
-    p.pyaml
-    p.pykeepass
-    p.filemagic
-    p.cryptography
-    p.secretstorage
-  ]);
-
-in stdenv.mkDerivation rec {
+{ lib
+, fetchFromGitHub
+, fetchpatch
+, python3Packages
+, gnupg
+, pass
+}:
+
+python3Packages.buildPythonApplication rec {
   pname = "pass-import";
   version = "3.1";
 
@@ -22,26 +17,43 @@ in stdenv.mkDerivation rec {
     sha256 = "sha256-nH2xAqWfMT+Brv3z9Aw6nbvYqArEZjpM28rKsRPihqA=";
   };
 
-  patches = [ ./0001-Fix-installation-with-Nix.patch ];
-
-  nativeBuildInputs = [ makeWrapper ];
-
-  buildInputs = [ pythonEnv ];
-
-  makeFlags = [ "DESTDIR=${placeholder "out"}" ];
-
-  postInstall = ''
-    wrapProgram $out/bin/pimport \
-      --prefix PATH : "${pythonEnv}/bin" \
-      --prefix PYTHONPATH : "$out/${pythonPackages.python.sitePackages}"
-    wrapProgram $out/lib/password-store/extensions/import.bash \
-      --prefix PATH : "${pythonEnv}/bin" \
-      --prefix PYTHONPATH : "$out/${pythonPackages.python.sitePackages}"
+  # by default, tries to install scripts/pimport, which is a bash wrapper around "python -m pass_import ..."
+  # This is a better way to do the same, and takes advantage of the existing Nix python environments
+  patches = [
+    # from https://github.com/roddhjav/pass-import/pull/138
+    (fetchpatch {
+      name = "pass-import-pr-138-pimport-entrypoint.patch";
+      url = "https://github.com/roddhjav/pass-import/commit/ccdb6995bee6436992dd80d7b3101f0eb94c59bb.patch";
+      sha256 = "sha256-CO8PyWxa4eLuTQBB+jKTImFPlPn+1yt6NBsIp+SPk94=";
+    })
+  ];
+
+  propagatedBuildInputs = with python3Packages; [
+    cryptography
+    defusedxml
+    pyaml
+    pykeepass
+    python_magic  # similar API to "file-magic", but already in nixpkgs.
+    secretstorage
+  ];
+
+  checkInputs = [
+    gnupg
+    pass
+    python3Packages.pytestCheckHook
+  ];
+
+  disabledTests = [
+    "test_import_gnome_keyring" # requires dbus, which pytest doesn't support
+  ];
+  postCheck = ''
+    $out/bin/pimport --list-exporters --list-importers
   '';
 
   meta = with lib; {
     description = "Pass extension for importing data from existing password managers";
     homepage = "https://github.com/roddhjav/pass-import";
+    changelog = "https://github.com/roddhjav/pass-import/blob/v${version}/CHANGELOG.rst";
     license = licenses.gpl3Plus;
     maintainers = with maintainers; [ lovek323 fpletz tadfisher ];
     platforms = platforms.unix;