1 { lib, stdenv, fetchurl
2 , unzip, mono, makeWrapper, icoutils
3 , substituteAll, xsel, xorg, xdotool, coreutils, unixtools, glib
4 , gtk2, makeDesktopItem, plugins ? [] }:
6 stdenv.mkDerivation (finalAttrs: {
11 url = "mirror://sourceforge/keepass/KeePass-${finalAttrs.version}-Source.zip";
12 hash = "sha256-97ZX1EzhMv4B3YZ3HoUqlGTEMsQn3cmNGr+uvS6AKYY=";
22 buildInputs = [ icoutils ];
26 src = ./fix-paths.patch;
27 xsel = "${xsel}/bin/xsel";
28 xprop = "${xorg.xprop}/bin/xprop";
29 xdotool = "${xdotool}/bin/xdotool";
30 uname = "${coreutils}/bin/uname";
31 whereis = "${unixtools.whereis}/bin/whereis";
32 gsettings = "${glib}/bin/gsettings";
36 # KeePass looks for plugins in under directory in which KeePass.exe is
37 # located. It follows symlinks where looking for that directory, so
38 # buildEnv is not enough to bring KeePass and plugins together.
40 # This derivation patches KeePass to search for plugins in specified
41 # plugin derivations in the Nix store and nowhere else.
42 pluginLoadPathsPatch = let
43 inherit (builtins) toString;
44 inherit (lib.strings) readFile concatStrings replaceStrings unsafeDiscardStringContext;
45 inherit (lib.lists) map length;
48 outputLc = toString (add 7 (length plugins));
49 patchTemplate = readFile ./keepass-plugins.patch;
50 loadTemplate = readFile ./keepass-plugins-load.patch;
53 (p: replaceStrings ["$PATH$"] [ (unsafeDiscardStringContext (toString p)) ] loadTemplate)
56 replaceStrings ["$OUTPUT_LC$" "$DO_LOADS$"] [outputLc loads] patchTemplate;
58 passAsFile = [ "pluginLoadPathsPatch" ];
60 sed -i 's/\r*$//' KeePass/Forms/MainForm.cs
61 patch -p1 <$pluginLoadPathsPatchPath
68 find . -name "*.sln" -print -exec sed -i 's/Format Version 10.00/Format Version 11.00/g' {} \;
69 find . -name "*.csproj" -print -exec sed -i '
70 s#ToolsVersion="3.5"#ToolsVersion="4.0"#g
71 s#<TargetFrameworkVersion>.*</TargetFrameworkVersion>##g
72 s#<PropertyGroup>#<PropertyGroup><TargetFrameworkVersion>v4.5</TargetFrameworkVersion>#g
73 s#<SignAssembly>.*$#<SignAssembly>false</SignAssembly>#g
74 s#<PostBuildEvent>.*sgen.exe.*$##
83 xbuild /p:Configuration=Release
89 "Build/KeePass/Release/*"
90 "Build/KeePassLib/Release/*"
91 "Ext/KeePass.config.xml" # contains <PreferUserConfiguration>true</PreferUserConfiguration>
94 # plgx plugin like keefox requires mono to compile at runtime
95 # after loading. It is brought into plugins bin/ directory using
96 # buildEnv in the plugin derivation. Wrapper below makes sure it
97 # is found and does not pollute output path.
98 binPaths = lib.concatStringsSep ":" (map (x: x + "/bin") plugins);
100 dynlibPath = lib.makeLibraryPath [ gtk2 ];
105 target="$out/lib/dotnet/${finalAttrs.pname}"
108 cp -rv $outputFiles "$target"
113 --add-flags "$target/KeePass.exe" \
114 --prefix PATH : "$binPaths" \
115 --prefix LD_LIBRARY_PATH : "$dynlibPath"
117 # setup desktop item with icon
118 mkdir -p "$out/share/applications"
119 cp $desktopItem/share/applications/* $out/share/applications
121 ${./extractWinRscIconsToStdFreeDesktopDir.sh} \
122 "./Translation/TrlUtil/Resources/KeePass.ico" \
123 '[^\.]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png' \
132 desktopItem = makeDesktopItem {
135 comment = "Password manager";
137 desktopName = "Keepass";
138 genericName = "Password manager";
139 categories = [ "Utility" ];
140 mimeTypes = [ "application/x-keepass2" ];
144 description = "GUI password manager with strong cryptography";
145 homepage = "http://www.keepass.info/";
146 maintainers = with lib.maintainers; [ amorsillo obadz ];
147 platforms = with lib.platforms; all;
148 license = lib.licenses.gpl2;
149 mainProgram = "keepass";