From 1aeee74f9f6ea76e44b057ebbcbf09670303b477 Mon Sep 17 00:00:00 2001 From: Stefan Frijters Date: Tue, 10 Mar 2026 12:11:42 +0100 Subject: [PATCH] keepass: use writeText instead of passAsFile --- pkgs/by-name/ke/keepass/package.nix | 64 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/pkgs/by-name/ke/keepass/package.nix b/pkgs/by-name/ke/keepass/package.nix index 73a02c9059dd..8274bfbf9c4c 100644 --- a/pkgs/by-name/ke/keepass/package.nix +++ b/pkgs/by-name/ke/keepass/package.nix @@ -5,6 +5,7 @@ unzip, mono, makeWrapper, + writeText, icoutils, replaceVars, xsel, @@ -17,7 +18,38 @@ makeDesktopItem, plugins ? [ ], }: +let + # 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. + pluginLoadPathsPatch = + let + inherit (builtins) toString; + inherit (lib.strings) + readFile + concatStrings + replaceStrings + unsafeDiscardStringContext + ; + inherit (lib.lists) map length; + inherit (lib) add; + outputLc = toString (add 7 (length plugins)); + patchTemplate = readFile ./keepass-plugins.patch; + loadTemplate = readFile ./keepass-plugins-load.patch; + loads = concatStrings ( + map ( + p: replaceStrings [ "$PATH$" ] [ (unsafeDiscardStringContext (toString p)) ] loadTemplate + ) plugins + ); + in + writeText "load-paths.patch" ( + replaceStrings [ "$OUTPUT_LC$" "$DO_LOADS$" ] [ outputLc loads ] patchTemplate + ); +in stdenv.mkDerivation (finalAttrs: { pname = "keepass"; version = "2.60"; @@ -47,39 +79,9 @@ stdenv.mkDerivation (finalAttrs: { }) ]; - # 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. - pluginLoadPathsPatch = - let - inherit (builtins) toString; - inherit (lib.strings) - readFile - concatStrings - replaceStrings - unsafeDiscardStringContext - ; - inherit (lib.lists) map length; - inherit (lib) add; - - outputLc = toString (add 7 (length plugins)); - patchTemplate = readFile ./keepass-plugins.patch; - loadTemplate = readFile ./keepass-plugins-load.patch; - loads = concatStrings ( - map ( - p: replaceStrings [ "$PATH$" ] [ (unsafeDiscardStringContext (toString p)) ] loadTemplate - ) plugins - ); - in - replaceStrings [ "$OUTPUT_LC$" "$DO_LOADS$" ] [ outputLc loads ] patchTemplate; - - passAsFile = [ "pluginLoadPathsPatch" ]; postPatch = '' sed -i 's/\r*$//' KeePass/Forms/MainForm.cs - patch -p1 <$pluginLoadPathsPatchPath + patch -p1 <${pluginLoadPathsPatch} ''; configurePhase = ''