about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/applications/misc/keepass/default.nix37
-rw-r--r--pkgs/applications/misc/keepass/keepass-plugins-load.patch1
-rw-r--r--pkgs/applications/misc/keepass/keepass-plugins.patch14
-rw-r--r--pkgs/top-level/all-packages.nix2
4 files changed, 50 insertions, 4 deletions
diff --git a/pkgs/applications/misc/keepass/default.nix b/pkgs/applications/misc/keepass/default.nix
index 950d16eeac8a..6914120f2967 100644
--- a/pkgs/applications/misc/keepass/default.nix
+++ b/pkgs/applications/misc/keepass/default.nix
@@ -1,6 +1,12 @@
-{ stdenv, fetchurl, buildDotnetPackage, makeWrapper, unzip, makeDesktopItem }:
+{ stdenv, lib, fetchurl, buildDotnetPackage, makeWrapper, unzip, makeDesktopItem, plugins ? [] }:
 
-buildDotnetPackage rec {
+# KeePass looks for plugins in under directory in which KeePass.exe is
+# located. It follows symlinks where looking for that directory, so
+# buildEnv is not enough to bring KeePass and plugins together.
+#
+# This derivation patches KeePass to search for plugins in specified
+# plugin derivations in the Nix store and nowhere else.
+with builtins; buildDotnetPackage rec {
   baseName = "keepass";
   version = "2.30";
 
@@ -11,10 +17,26 @@ buildDotnetPackage rec {
 
   sourceRoot = ".";
 
-  buildInputs = [ unzip ];
+  buildInputs = [ unzip makeWrapper ];
 
   patches = [ ./keepass.patch ];
 
+  pluginLoadPathsPatch =
+    let outputLc = toString (add 8 (length plugins));
+        patchTemplate = readFile ./keepass-plugins.patch;
+        loadTemplate  = readFile ./keepass-plugins-load.patch;
+        loads =
+          lib.concatStrings
+            (map
+              (p: replaceStrings ["$PATH$"] [ (unsafeDiscardStringContext (toString p)) ] loadTemplate)
+              plugins);
+    in replaceStrings ["$OUTPUT_LC$" "$DO_LOADS$"] [outputLc loads] patchTemplate;
+
+  passAsFile = [ "pluginLoadPathsPatch" ];
+  postPatch = ''
+    patch --binary -p1 <$pluginLoadPathsPatchPath
+  '';
+
   preConfigure = "rm -rvf Build/*";
 
   desktopItem = makeDesktopItem {
@@ -22,7 +44,7 @@ buildDotnetPackage rec {
     exec = "keepass";
     comment = "Password manager";
     desktopName = "Keepass";
-    genericName = "Password manager";    
+    genericName = "Password manager";
     categories = "Application;Other;";
   };
 
@@ -30,9 +52,16 @@ buildDotnetPackage rec {
   dllFiles = [ "KeePassLib.dll" ];
   exeFiles = [ "KeePass.exe" ];
 
+  # plgx plugin like keefox requires mono to compile at runtime
+  # after loading. It is brought into plugins bin/ directory using
+  # buildEnv in the plugin derivation. Wrapper below makes sure it
+  # is found and does not pollute output path.
+  binPaths = lib.concatStrings (lib.intersperse ":" (map (x: x + "/bin") plugins));
+
   postInstall = ''
     mkdir -p "$out/share/applications"
     cp ${desktopItem}/share/applications/* $out/share/applications
+    wrapProgram $out/bin/keepass --prefix PATH : "$binPaths"
   '';
 
   meta = {
diff --git a/pkgs/applications/misc/keepass/keepass-plugins-load.patch b/pkgs/applications/misc/keepass/keepass-plugins-load.patch
new file mode 100644
index 000000000000..872b6c06d788
--- /dev/null
+++ b/pkgs/applications/misc/keepass/keepass-plugins-load.patch
@@ -0,0 +1 @@
++				m_pluginManager.LoadAllPlugins("$PATH$/lib/dotnet/keepass");
diff --git a/pkgs/applications/misc/keepass/keepass-plugins.patch b/pkgs/applications/misc/keepass/keepass-plugins.patch
new file mode 100644
index 000000000000..1a32d77806a4
--- /dev/null
+++ b/pkgs/applications/misc/keepass/keepass-plugins.patch
@@ -0,0 +1,14 @@
+--- old/KeePass/Forms/MainForm.cs
++++ new/KeePass/Forms/MainForm.cs
+@@ -384,9 +384,$OUTPUT_LC$ @@ namespace KeePass.Forms
+ 			m_pluginManager.Initialize(m_pluginDefaultHost);
+ 
+ 			m_pluginManager.UnloadAllPlugins();
+-			if(AppPolicy.Current.Plugins)
+-				m_pluginManager.LoadAllPlugins(UrlUtil.GetFileDirectory(
+-					WinUtil.GetExecutable(), false, true));
++			if(AppPolicy.Current.Plugins) {
+$DO_LOADS$+			}
+ 
+ 			// Delete old files *after* loading plugins (when timestamps
+ 			// of loaded plugins have been updated already)
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index c387847dd274..2163fd81f78c 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -11695,6 +11695,8 @@ let
 
   keepass = callPackage ../applications/misc/keepass { };
 
+  keepass-keefox = callPackage ../applications/misc/keepass-plugins/keefox { };
+
   exrdisplay = callPackage ../applications/graphics/exrdisplay {
     fltk = fltk20;
   };