about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/misc/pdfstudio/common.nix
blob: f6ee4178695058ffd9ca98ac677e71a006bc37e1 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ pname
, program
, src
, year
, version
, desktopName
, longDescription
, buildFHSEnv
, extraBuildInputs ? [ ]
, jdk
, stdenv
, lib
, dpkg
, makeDesktopItem
, copyDesktopItems
, autoPatchelfHook
, sane-backends
, cups
}:
let
  thisPackage = stdenv.mkDerivation rec {
    inherit pname src version;
    strictDeps = true;

    buildInputs = [
      sane-backends #for libsane.so.1
    ] ++ extraBuildInputs;

    nativeBuildInputs = [
      autoPatchelfHook
      dpkg
      copyDesktopItems
    ];

    desktopItems = [
      (makeDesktopItem {
        name = "${pname}";
        desktopName = desktopName;
        genericName = "View and edit PDF files";
        exec = "${pname} %f";
        icon = "${pname}";
        comment = "Views and edits PDF files";
        mimeTypes = [ "application/pdf" ];
        categories = [ "Office" ];
      })
    ];

    unpackCmd = "dpkg-deb -x $src ./${program}-${version}";
    dontBuild = true;

    postPatch = ''
      substituteInPlace opt/${program}${year}/${program}${year} --replace "# INSTALL4J_JAVA_HOME_OVERRIDE=" "INSTALL4J_JAVA_HOME_OVERRIDE=${jdk.out}"
      substituteInPlace opt/${program}${year}/updater --replace "# INSTALL4J_JAVA_HOME_OVERRIDE=" "INSTALL4J_JAVA_HOME_OVERRIDE=${jdk.out}"
    '';

    installPhase = ''
      runHook preInstall

      mkdir -p $out/{bin,share/pixmaps}
      rm -rf opt/${program}${year}/jre
      cp -r opt/${program}${year} $out/share/
      ln -s $out/share/${program}${year}/.install4j/${program}${year}.png  $out/share/pixmaps/${pname}.png
      ln -s $out/share/${program}${year}/${program}${year} $out/bin/

      runHook postInstall
    '';
  };

in
# Package with cups in FHS sandbox, because JAVA bin expects "/usr/bin/lpr" for printing.
buildFHSEnv {
  name = pname;
  targetPkgs = pkgs: [
    cups
    thisPackage
  ];
  runScript = "${program}${year}";

  # link desktop item and icon into FHS user environment
  extraInstallCommands = ''
    mkdir -p "$out/share/applications"
    mkdir -p "$out/share/pixmaps"
    ln -s ${thisPackage}/share/applications/*.desktop "$out/share/applications/"
    ln -s ${thisPackage}/share/pixmaps/*.png "$out/share/pixmaps/"
  '';

  meta = with lib; {
    homepage = "https://www.qoppa.com/${pname}/";
    description = "An easy to use, full-featured PDF editing software";
    longDescription = longDescription;
    sourceProvenance = with sourceTypes; [
      binaryBytecode
      binaryNativeCode
    ];
    license = licenses.unfree;
    platforms = platforms.linux;
    mainProgram = pname;
    maintainers = [ maintainers.pwoelfel ];
  };
}