Commit c14085ee authored by mdarocha's avatar mdarocha
Browse files

keepass: move to by-name, remove dependency on buildDotnetPackage

parent 17012aa0
Loading
Loading
Loading
Loading
+69 −40
Original line number Diff line number Diff line
{ lib, fetchurl, buildDotnetPackage, substituteAll, makeWrapper, makeDesktopItem,
  unzip, icoutils, gtk2, xorg, xdotool, xsel, coreutils, unixtools, glib, plugins ? [] }:
let
  inherit (builtins) add length readFile replaceStrings unsafeDiscardStringContext toString map;
in buildDotnetPackage rec {
{ lib, stdenv, fetchurl
, unzip, mono, makeWrapper, icoutils
, substituteAll, xsel, xorg, xdotool, coreutils, unixtools, glib
, gtk2, makeDesktopItem, plugins ? [] }:

stdenv.mkDerivation (finalAttrs: {
  pname = "keepass";
  version = "2.55";

  src = fetchurl {
    url = "mirror://sourceforge/keepass/KeePass-${version}-Source.zip";
    url = "mirror://sourceforge/keepass/KeePass-${finalAttrs.version}-Source.zip";
    hash = "sha256-XZf/5b+rwASB41DP3It3g8UUPIHWEtZBXGk+Qrjw1Bc=";
  };

  sourceRoot = ".";

  nativeBuildInputs = [ makeWrapper unzip ];
  nativeBuildInputs = [
    unzip
    mono
    makeWrapper
  ];
  buildInputs = [ icoutils ];

  patches = [
@@ -34,16 +39,21 @@ in buildDotnetPackage rec {
  #
  # This derivation patches KeePass to search for plugins in specified
  # plugin derivations in the Nix store and nowhere else.
  pluginLoadPathsPatch =
    let outputLc = toString (add 7 (length plugins));
  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 =
          lib.concatStrings
    loads = concatStrings
      (map
        (p: replaceStrings ["$PATH$"] [ (unsafeDiscardStringContext (toString p)) ] loadTemplate)
          plugins);
    in replaceStrings ["$OUTPUT_LC$" "$DO_LOADS$"] [outputLc loads] patchTemplate;
  in
  replaceStrings ["$OUTPUT_LC$" "$DO_LOADS$"] [outputLc loads] patchTemplate;

  passAsFile = [ "pluginLoadPathsPatch" ];
  postPatch = ''
@@ -51,7 +61,9 @@ in buildDotnetPackage rec {
    patch -p1 <$pluginLoadPathsPatchPath
  '';

  preConfigure = ''
  configurePhase = ''
    runHook preConfigure

    rm -rvf Build/*
    find . -name "*.sln" -print -exec sed -i 's/Format Version 10.00/Format Version 11.00/g' {} \;
    find . -name "*.csproj" -print -exec sed -i '
@@ -61,26 +73,23 @@ in buildDotnetPackage rec {
      s#<SignAssembly>.*$#<SignAssembly>false</SignAssembly>#g
      s#<PostBuildEvent>.*sgen.exe.*$##
    ' {} \;

    runHook postConfigure
  '';

  desktopItem = makeDesktopItem {
    name = "keepass";
    exec = "keepass";
    comment = "Password manager";
    icon = "keepass";
    desktopName = "Keepass";
    genericName = "Password manager";
    categories = [ "Utility" ];
    mimeTypes = [ "application/x-keepass2" ];
  };
  buildPhase = ''
    runHook preBuild

    xbuild /p:Configuration=Release

    runHook postBuld
  '';

  outputFiles = [
    "Build/KeePass/Release/*"
    "Build/KeePassLib/Release/*"
    "Ext/KeePass.config.xml" # contains <PreferUserConfiguration>true</PreferUserConfiguration>
  ];
  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
@@ -90,18 +99,26 @@ in buildDotnetPackage rec {

  dynlibPath = lib.makeLibraryPath [ gtk2 ];

  postInstall =
  let
    extractFDeskIcons = ./extractWinRscIconsToStdFreeDesktopDir.sh;
  in
  ''
    mkdir -p "$out/share/applications"
    cp ${desktopItem}/share/applications/* $out/share/applications
    wrapProgram $out/bin/keepass \
  installPhase = ''
    runHook preInstall

    target="$out/lib/dotnet/${finalAttrs.pname}"
    mkdir -p "$target"

    cp -rv $outputFiles "$target"

    makeWrapper \
      "${mono}/bin/mono" \
      "$out/bin/keepass" \
      --add-flags "$target/KeePass.exe" \
      --prefix PATH : "$binPaths" \
      --prefix LD_LIBRARY_PATH : "$dynlibPath"

    ${extractFDeskIcons} \
    # setup desktop item with icon
    mkdir -p "$out/share/applications"
    cp $desktopItem/share/applications/* $out/share/applications

    ${./extractWinRscIconsToStdFreeDesktopDir.sh} \
      "./Translation/TrlUtil/Resources/KeePass.ico" \
      '[^\.]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png' \
      '\1' \
@@ -109,8 +126,20 @@ in buildDotnetPackage rec {
      'keepass' \
      "$out" \
      "./tmp"
    runHook postInstall
  '';

  desktopItem = makeDesktopItem {
    name = "keepass";
    exec = "keepass";
    comment = "Password manager";
    icon = "keepass";
    desktopName = "Keepass";
    genericName = "Password manager";
    categories = [ "Utility" ];
    mimeTypes = [ "application/x-keepass2" ];
  };

  meta = {
    description = "GUI password manager with strong cryptography";
    homepage = "http://www.keepass.info/";
@@ -119,4 +148,4 @@ in buildDotnetPackage rec {
    license = lib.licenses.gpl2;
    mainProgram = "keepass";
  };
}
})
Loading