summary refs log tree commit diff
path: root/pkgs/applications/version-management/p4v/default.nix
blob: 2e0e01e5c98623871c464e26fd476c3a4489add5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ stdenv
, fetchurl
, lib
, qtbase
, qtwebengine
, qtdeclarative
, qtwebchannel
, syntax-highlighting
, openssl
, xkeyboard_config
, patchelfUnstable
, wrapQtAppsHook
, writeText
}:
let
  # This abomination exists because p4v calls CRYPTO_set_mem_functions and
  # expects it to succeed. The function will fail if CRYPTO_malloc has already
  # been called, which happens at init time via qtwebengine -> ... -> libssh. I
  # suspect it was meant to work with a version of Qt where openssl is
  # statically linked or some other library is used.
  crypto-hack = writeText "crypto-hack.c" ''
      #include <stddef.h>
      int CRYPTO_set_mem_functions(
            void *(*m)(size_t, const char *, int),
            void *(*r)(void *, size_t, const char *, int),
            void (*f)(void *, const char *, int)) { return 1; }
    '';

in stdenv.mkDerivation rec {
  pname = "p4v";
  version = "2021.3.2186916";

  src = fetchurl {
    url = "http://web.archive.org/web/20211118024745/https://cdist2.perforce.com/perforce/r21.3/bin.linux26x86_64/p4v.tgz";
    sha256 = "1zldg21xq4srww9pcfbv3p8320ghjnh333pz5r70z1gwbq4vf3jq";
  };

  dontBuild = true;
  nativeBuildInputs = [ patchelfUnstable wrapQtAppsHook ];

  ldLibraryPath = lib.makeLibraryPath [
      stdenv.cc.cc.lib
      qtbase
      qtwebengine
      qtdeclarative
      qtwebchannel
      syntax-highlighting
      openssl
  ];

  dontWrapQtApps = true;
  installPhase = ''
    mkdir $out
    cp -r bin $out
    mkdir -p $out/lib
    cp -r lib/P4VResources $out/lib
    $CC -fPIC -shared -o $out/lib/libcrypto-hack.so ${crypto-hack}

    for f in $out/bin/*.bin ; do
      patchelf --set-rpath $ldLibraryPath --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $f
      # combining this with above breaks rpath (patchelf bug?)
      patchelf --add-needed libstdc++.so \
               --add-needed $out/lib/libcrypto-hack.so \
               --clear-symbol-version _ZNSt20bad_array_new_lengthD1Ev \
               --clear-symbol-version _ZTVSt20bad_array_new_length \
               --clear-symbol-version _ZTISt20bad_array_new_length \
               --clear-symbol-version _ZdlPvm \
               $f
      wrapQtApp $f \
        --suffix QT_XKB_CONFIG_ROOT : ${xkeyboard_config}/share/X11/xkb
    done
  '';

  dontFixup = true;

  meta = {
    description = "Perforce Visual Client";
    homepage = "https://www.perforce.com";
    license = lib.licenses.unfreeRedistributable;
    platforms = [ "x86_64-linux" ];
    maintainers = with lib.maintainers; [ nathyong nioncode ];
  };
}