Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenv, lib, fetchurl, makeWrapper, writeText
2, fpc, gtk2, glib, pango, atk, gdk-pixbuf
3, libXi, xorgproto, libX11, libXext
4, gdb, gnumake, binutils
5, withQt ? false, qtbase ? null, libqt5pas ? null, wrapQtAppsHook ? null
6}:
7
8# TODO:
9# 1. the build date is embedded in the binary through `$I %DATE%` - we should dump that
10
11let
12 version = "2.2.2-0";
13
14 # as of 2.0.10 a suffix is being added. That may or may not disappear and then
15 # come back, so just leave this here.
16 majorMinorPatch = v:
17 builtins.concatStringsSep "." (lib.take 3 (lib.splitVersion v));
18
19 overrides = writeText "revision.inc" (lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v:
20 "const ${k} = '${v}';") {
21 # this is technically the SVN revision but as we don't have that replace
22 # it with the version instead of showing "Unknown"
23 RevisionStr = version;
24 }));
25
26in
27stdenv.mkDerivation rec {
28 pname = "lazarus-${LCL_PLATFORM}";
29 inherit version;
30
31 src = fetchurl {
32 url = "mirror://sourceforge/lazarus/Lazarus%20Zip%20_%20GZip/Lazarus%20${majorMinorPatch version}/lazarus-${version}.tar.gz";
33 sha256 = "a9832004cffec8aca69de87290441d54772bf95d5d04372249d5a5491fb674c4";
34 };
35
36 postPatch = ''
37 cp ${overrides} ide/${overrides.name}
38 '';
39
40 buildInputs = [
41 # we need gtk2 unconditionally as that is the default target when building applications with lazarus
42 fpc gtk2 glib libXi xorgproto
43 libX11 libXext pango atk
44 stdenv.cc gdk-pixbuf
45 ]
46 ++ lib.optionals withQt [ libqt5pas qtbase ];
47
48 # Disable parallel build, errors:
49 # Fatal: (1018) Compilation aborted
50 enableParallelBuilding = false;
51
52 nativeBuildInputs = [
53 makeWrapper
54 ] ++ lib.optional withQt wrapQtAppsHook;
55
56 makeFlags = [
57 "FPC=fpc"
58 "PP=fpc"
59 "LAZARUS_INSTALL_DIR=${placeholder "out"}/share/lazarus/"
60 "INSTALL_PREFIX=${placeholder "out"}/"
61 "REQUIRE_PACKAGES+=tachartlazaruspkg"
62 "bigide"
63 ];
64
65 LCL_PLATFORM = if withQt then "qt5" else "gtk2";
66
67 NIX_LDFLAGS = lib.concatStringsSep " " ([
68 "-L${stdenv.cc.cc.lib}/lib"
69 "-lX11"
70 "-lXext"
71 "-lXi"
72 "-latk-1.0"
73 "-lc"
74 "-lcairo"
75 "-lgcc_s"
76 "-lgdk-x11-2.0"
77 "-lgdk_pixbuf-2.0"
78 "-lglib-2.0"
79 "-lgtk-x11-2.0"
80 "-lpango-1.0"
81 ]
82 ++ lib.optionals withQt [
83 "-L${lib.getLib libqt5pas}/lib"
84 "-lQt5Pas"
85 ]);
86
87 preBuild = ''
88 mkdir -p $out/share "$out/lazarus"
89 tar xf ${fpc.src} --strip-components=1 -C $out/share -m
90 substituteInPlace ide/include/unix/lazbaseconf.inc \
91 --replace '/usr/fpcsrc' "$out/share/fpcsrc"
92 '';
93
94 postInstall = let
95 ldFlags = ''$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')'';
96 in ''
97 wrapProgram $out/bin/startlazarus \
98 --prefix NIX_LDFLAGS ' ' "${ldFlags}" \
99 --prefix NIX_LDFLAGS_${binutils.suffixSalt} ' ' "${ldFlags}" \
100 --prefix LCL_PLATFORM ' ' "$LCL_PLATFORM" \
101 --prefix PATH ':' "${lib.makeBinPath [ fpc gdb gnumake binutils ]}"
102 '';
103
104 meta = with lib; {
105 description = "Graphical IDE for the FreePascal language";
106 homepage = "https://www.lazarus.freepascal.org";
107 license = licenses.gpl2Plus ;
108 maintainers = with maintainers; [ raskin ];
109 platforms = platforms.linux;
110 };
111}