1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 coreutils,
6 lazarus,
7 fpc,
8 libX11,
9
10 # GTK2/3
11 pango,
12 cairo,
13 glib,
14 atk,
15 gtk2,
16 gtk3,
17 gdk-pixbuf,
18 python3,
19
20 # Qt5
21 libsForQt5,
22
23 widgetset ? "qt5",
24 # See https://github.com/Alexey-T/CudaText-lexers
25 additionalLexers ? [ "Nix" ],
26}:
27
28assert builtins.elem widgetset [
29 "gtk2"
30 "gtk3"
31 "qt5"
32];
33
34let
35 deps = lib.mapAttrs (
36 name: spec:
37 fetchFromGitHub {
38 repo = name;
39 inherit (spec) owner rev hash;
40 }
41 ) (lib.importJSON ./deps.json);
42in
43stdenv.mkDerivation rec {
44 pname = "cudatext";
45 version = "1.202.1";
46
47 src = fetchFromGitHub {
48 owner = "Alexey-T";
49 repo = "CudaText";
50 rev = version;
51 hash = "sha256-ZFMO986D4RtrTnLFdcL0a2BNjcsB+9pIolylblku7j4=";
52 };
53
54 patches = [ ./proc_globdata.patch ];
55
56 postPatch = ''
57 substituteInPlace app/proc_globdata.pas \
58 --subst-var out \
59 --subst-var-by python3 ${python3}
60 substituteInPlace app/proc_editor_saving.pas \
61 --replace-fail '/bin/cp' "${coreutils}/bin/cp"
62 '';
63
64 nativeBuildInputs = [
65 lazarus
66 fpc
67 ]
68 ++ lib.optional (widgetset == "qt5") libsForQt5.wrapQtAppsHook;
69
70 buildInputs = [
71 libX11
72 ]
73 ++ lib.optionals (lib.hasPrefix "gtk" widgetset) [
74 pango
75 cairo
76 glib
77 atk
78 gdk-pixbuf
79 ]
80 ++ lib.optional (widgetset == "gtk2") gtk2
81 ++ lib.optional (widgetset == "gtk3") gtk3
82 ++ lib.optional (widgetset == "qt5") libsForQt5.libqtpas;
83
84 NIX_LDFLAGS = "--as-needed -rpath ${lib.makeLibraryPath buildInputs}";
85
86 buildPhase =
87 lib.concatStringsSep "\n" (
88 lib.mapAttrsToList (name: dep: ''
89 cp -r ${dep} ${name}
90 '') deps
91 )
92 + ''
93 # See https://wiki.freepascal.org/CudaText#How_to_compile_CudaText
94 substituteInPlace ATSynEdit/atsynedit/atsynedit_package.lpk \
95 --replace GTK2_IME_CODE _GTK2_IME_CODE
96
97 lazbuild --lazarusdir=${lazarus}/share/lazarus --pcp=./lazarus --ws=${widgetset} \
98 bgrabitmap/bgrabitmap/bgrabitmappack.lpk \
99 EncConv/encconv/encconv_package.lpk \
100 ATBinHex-Lazarus/atbinhex/atbinhex_package.lpk \
101 ATFlatControls/atflatcontrols/atflatcontrols_package.lpk \
102 ATSynEdit/atsynedit/atsynedit_package.lpk \
103 ATSynEdit_Cmp/atsynedit_cmp/atsynedit_cmp_package.lpk \
104 EControl/econtrol/econtrol_package.lpk \
105 ATSynEdit_Ex/atsynedit_ex/atsynedit_ex_package.lpk \
106 Python-for-Lazarus/python4lazarus/python4lazarus_package.lpk \
107 Emmet-Pascal/emmet/emmet_package.lpk \
108 app/cudatext.lpi
109 '';
110
111 installPhase = ''
112 install -Dm755 app/cudatext -t $out/bin
113
114 install -dm755 $out/share/cudatext
115 cp -r app/{data,py,settings_default} $out/share/cudatext
116
117 install -Dm644 setup/debfiles/cudatext-512.png -t $out/share/pixmaps
118 install -Dm644 setup/debfiles/cudatext.desktop -t $out/share/applications
119 ''
120 + lib.concatMapStringsSep "\n" (lexer: ''
121 if [ -d "CudaText-lexers/${lexer}" ]; then
122 install -Dm644 CudaText-lexers/${lexer}/*.{cuda-lexmap,lcf} $out/share/cudatext/data/lexlib
123 else
124 echo "${lexer} lexer not found"
125 exit 1
126 fi
127 '') additionalLexers;
128
129 passthru.updateScript = ./update.sh;
130
131 meta = with lib; {
132 description = "Cross-platform code editor";
133 longDescription = ''
134 Text/code editor with lite UI. Syntax highlighting for 200+ languages.
135 Config system in JSON files. Multi-carets and multi-selections.
136 Search and replace with RegEx. Extendable by Python plugins and themes.
137 '';
138 homepage = "https://cudatext.github.io/";
139 changelog = "https://cudatext.github.io/history.txt";
140 license = licenses.mpl20;
141 maintainers = with maintainers; [ sikmir ];
142 platforms = platforms.linux;
143 mainProgram = "cudatext";
144 };
145}