about summary refs log tree commit diff
path: root/pkgs/applications/misc
diff options
context:
space:
mode:
authorNicole Angel <nikki@mailbox.org>2015-11-22 18:21:13 +0100
committerRok Garbas <rok@garbas.si>2015-12-23 02:12:36 +0100
commit90e881eece9f5125d03a0c8b390651b4486fa5e7 (patch)
tree6bf0f8dfe4ebe962dd5140481ac4b88bb93bae09 /pkgs/applications/misc
parente99beec0e16539c47c783b84592b79c088956527 (diff)
downloadnixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar.gz
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar.bz2
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar.lz
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar.xz
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.tar.zst
nixlib-90e881eece9f5125d03a0c8b390651b4486fa5e7.zip
keepass: load plugins from store paths, fixes #11206
Diffstat (limited to 'pkgs/applications/misc')
-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
3 files changed, 48 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)