about summary refs log tree commit diff
path: root/pkgs/tools/graphics/ploticus/default.nix
blob: e83c57aa5ca377c4695bbb786e80f0b5ad354fbd (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
{ lib
, stdenv
, fetchurl
, zlib
, libX11
, libpng
, libjpeg
, gd
, freetype
, runCommand
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "ploticus";
  version = "2.42";

  src = fetchurl {
    url = "mirror://sourceforge/ploticus/ploticus/${finalAttrs.version}/ploticus${lib.replaceStrings [ "." ] [ "" ] finalAttrs.version}_src.tar.gz";
    sha256 = "PynkufQFIDqT7+yQDlgW2eG0OBghiB4kHAjKt91m4LA=";
  };

  patches = [
    # Replace hardcoded FHS path with $out.
    ./ploticus-install.patch

    # Set the location of the PREFABS directory.
    ./set-prefabs-dir.patch

    # Use gd from Nixpkgs instead of the vendored one.
    # This is required for non-ASCII fonts to work:
    # https://ploticus.sourceforge.net/doc/fonts.html
    ./use-gd-package.patch
  ];

  buildInputs = [
    zlib
    libX11
    libpng
    gd
    freetype
    libjpeg
  ];

  hardeningDisable = [ "format" ];

  postPatch = ''
    substituteInPlace src/pl.h --subst-var out
  '';

  preBuild = ''
    cd src
  '';

  makeFlags = [ "CC:=$(CC)" ];

  preInstall = ''
    mkdir -p "$out/bin"
  '';

  postInstall = ''
    cd ..

    # Install the “prefabs”.
    mkdir -p "$out/share/ploticus/prefabs"
    cp -rv prefabs/* "$out/share/ploticus/prefabs"

    # Add aliases for backwards compatibility.
    ln -s "pl" "$out/bin/ploticus"
  '';

  passthru.tests = {
    prefab = runCommand "ploticus-prefab-test" {
      nativeBuildInputs = [ finalAttrs.finalPackage ];
    } ''
      # trivial test to see if the prefab path munging works
      mkdir $out/
      pl -prefab scat inlinedata="A 1 2" x=2 y=3 -png -o $out/out.png
    '';
  };

  meta = with lib; {
    description = "A non-interactive software package for producing plots and charts";
    longDescription = ''
      Ploticus is a free, GPL'd, non-interactive
      software package for producing plots, charts, and graphics from
      data.  Ploticus is good for automated or just-in-time graph
      generation, handles date and time data nicely, and has basic
      statistical capabilities.  It allows significant user control
      over colors, styles, options and details.
    '';
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ pSub ];
    homepage = "https://ploticus.sourceforge.net/";
    platforms = with platforms; linux ++ darwin;
  };
})