1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 pkg-config,
6 autoconf,
7 makeDesktopItem,
8 nixosTests,
9 vte,
10 harfbuzz, # can be replaced with libotf
11 fribidi,
12 m17n_lib,
13 libssh2, # build-in ssh
14 fcitx5,
15 fcitx5-gtk,
16 ibus,
17 uim, # IME
18 wrapGAppsHook3, # color picker in mlconfig
19 gdk-pixbuf,
20 gtk3,
21 gtk ? gtk3,
22 # List of gui libraries to use. According to `./configure --help` ran on
23 # release 3.9.3, options are: (xlib|win32|fb|quartz|console|wayland|sdl2|beos)
24 enableGuis ? {
25 xlib = enableX11;
26 # From some reason, upstream's ./configure script disables compilation of the
27 # external tool `mlconfig` if `enableGuis.fb == true`. This behavior is not
28 # documentd in `./configure --help`, and it is reported here:
29 # https://github.com/arakiken/mlterm/issues/73
30 fb = false;
31 quartz = stdenv.hostPlatform.isDarwin;
32 wayland = stdenv.hostPlatform.isLinux;
33 sdl2 = true;
34 },
35 libxkbcommon,
36 wayland, # for the "wayland" --with-gui option
37 SDL2, # for the "sdl" --with-gui option
38 # List of typing engines, the default list enables compiling all of the
39 # available ones, as recorded on release 3.9.3
40 enableTypeEngines ? {
41 xcore = false; # Considered legacy
42 xft = enableX11;
43 cairo = true;
44 },
45 libX11,
46 libXft,
47 cairo,
48 # List of external tools to create, this default list includes all default
49 # tools, as recorded on release 3.9.3.
50 enableTools ? {
51 mlclient = true;
52 mlconfig = true;
53 mlcc = true;
54 mlterm-menu = true;
55 # Note that according to upstream's ./configure script, to disable
56 # mlimgloader you have to disable _all_ tools. See:
57 # https://github.com/arakiken/mlterm/issues/69
58 mlimgloader = true;
59 registobmp = true;
60 mlfc = true;
61 },
62 # Whether to enable the X window system
63 enableX11 ? stdenv.hostPlatform.isLinux,
64 # Most of the input methods and other build features are enabled by default,
65 # the following attribute set can be used to disable some of them. It's parsed
66 # when we set `configureFlags`. If you find other configure Flags that require
67 # dependencies, it'd be nice to make that contribution here.
68 enableFeatures ? {
69 uim = !stdenv.hostPlatform.isDarwin;
70 ibus = !stdenv.hostPlatform.isDarwin;
71 fcitx = !stdenv.hostPlatform.isDarwin;
72 m17n = !stdenv.hostPlatform.isDarwin;
73 ssh2 = true;
74 bidi = true;
75 # Open Type layout support, (substituting glyphs with opentype fonts)
76 otl = true;
77 },
78 # Configure the Exec directive in the generated .desktop file
79 desktopBinary ? (
80 if enableGuis.xlib then
81 "mlterm"
82 else if enableGuis.wayland then
83 "mlterm-wl"
84 else if enableGuis.sdl2 then
85 "mlterm-sdl2"
86 else
87 throw "mlterm: couldn't figure out what desktopBinary to use."
88 ),
89}:
90
91let
92 # Returns a --with-feature=<comma separated string list of all `true`
93 # attributes>, or `--without-feature` if all attributes are false or don't
94 # exist. Used later in configureFlags
95 withFeaturesList =
96 featureName: attrset:
97 let
98 commaSepList = lib.concatStringsSep "," (builtins.attrNames (lib.filterAttrs (n: v: v) attrset));
99 in
100 lib.withFeatureAs (commaSepList != "") featureName commaSepList;
101in
102stdenv.mkDerivation (finalAttrs: {
103 pname = "mlterm";
104 version = "3.9.4";
105
106 src = fetchFromGitHub {
107 owner = "arakiken";
108 repo = "mlterm";
109 tag = finalAttrs.version;
110 sha256 = "sha256-YogapVTmW4HAyVgvhR4ZvW4Q6v0kGiW11CCxN6SpPCY=";
111 };
112
113 nativeBuildInputs = [
114 pkg-config
115 autoconf
116 ]
117 ++ lib.optionals enableTools.mlconfig [
118 wrapGAppsHook3
119 ];
120 buildInputs = [
121 gtk
122 vte
123 gdk-pixbuf
124 ]
125 ++ lib.optionals enableTypeEngines.xcore [
126 libX11
127 ]
128 ++ lib.optionals enableTypeEngines.xft [
129 libXft
130 ]
131 ++ lib.optionals enableTypeEngines.cairo [
132 cairo
133 ]
134 ++ lib.optionals enableGuis.wayland [
135 libxkbcommon
136 wayland
137 ]
138 ++ lib.optionals enableGuis.sdl2 [
139 SDL2
140 ]
141 ++ lib.optionals enableFeatures.otl [
142 harfbuzz
143 ]
144 ++ lib.optionals enableFeatures.bidi [
145 fribidi
146 ]
147 ++ lib.optionals enableFeatures.ssh2 [
148 libssh2
149 ]
150 ++ lib.optionals enableFeatures.m17n [
151 m17n_lib
152 ]
153 ++ lib.optionals enableFeatures.fcitx [
154 fcitx5
155 fcitx5-gtk
156 ]
157 ++ lib.optionals enableFeatures.ibus [
158 ibus
159 ]
160 ++ lib.optionals enableFeatures.uim [
161 uim
162 ];
163
164 #bad configure.ac and Makefile.in everywhere
165 preConfigure = ''
166 sed -i -e 's;-L/usr/local/lib -R/usr/local/lib;;g' \
167 main/Makefile.in \
168 tool/mlfc/Makefile.in \
169 tool/mlimgloader/Makefile.in \
170 tool/mlconfig/Makefile.in \
171 uitoolkit/libtype/Makefile.in \
172 uitoolkit/libotl/Makefile.in
173 sed -i -e 's;cd ..srcdir. && rm -f ...lang..gmo.*;;g' \
174 tool/mlconfig/po/Makefile.in.in
175 #utmp and mlterm-fb
176 substituteInPlace configure.in \
177 --replace "-m 2755 -g utmp" " " \
178 --replace "-m 4755 -o root" " "
179 substituteInPlace configure \
180 --replace "-m 2755 -g utmp" " " \
181 --replace "-m 4755 -o root" " "
182 '';
183
184 env = lib.optionalAttrs stdenv.cc.isClang {
185 NIX_CFLAGS_COMPILE = "-Wno-error=int-conversion -Wno-error=incompatible-function-pointer-types";
186 };
187
188 configureFlags = [
189 (withFeaturesList "type-engines" enableTypeEngines)
190 (withFeaturesList "tools" enableTools)
191 (withFeaturesList "gui" enableGuis)
192 (lib.withFeature enableX11 "x")
193 ]
194 ++ lib.optionals (gtk != null) [
195 "--with-gtk=${lib.versions.major gtk.version}.0"
196 ]
197 ++ (lib.mapAttrsToList (n: v: lib.enableFeature v n) enableFeatures)
198 ++ [
199 ];
200
201 enableParallelBuilding = true;
202
203 postInstall = ''
204 install -D contrib/icon/mlterm-icon.svg "$out/share/icons/hicolor/scalable/apps/mlterm.svg"
205 install -D contrib/icon/mlterm-icon-gnome2.png "$out/share/icons/hicolor/48x48/apps/mlterm.png"
206 install -D -t $out/share/applications $desktopItem/share/applications/*
207 ''
208 + lib.optionalString stdenv.hostPlatform.isDarwin ''
209 mkdir -p $out/Applications/
210 cp -a cocoa/mlterm.app $out/Applications/
211 install $out/bin/mlterm -Dt $out/Applications/mlterm.app/Contents/MacOS/
212 '';
213
214 desktopItem = makeDesktopItem {
215 name = "mlterm";
216 exec = "${desktopBinary} %U";
217 icon = "mlterm";
218 type = "Application";
219 comment = "Multi Lingual TERMinal emulator";
220 desktopName = "mlterm";
221 genericName = "Terminal emulator";
222 categories = [
223 "System"
224 "TerminalEmulator"
225 ];
226 startupNotify = false;
227 };
228
229 passthru = {
230 tests.test = nixosTests.terminal-emulators.mlterm;
231 inherit
232 enableTypeEngines
233 enableTools
234 enableGuis
235 enableFeatures
236 ;
237 };
238
239 meta = {
240 description = "Multi Lingual TERMinal emulator";
241 homepage = "https://mlterm.sourceforge.net/";
242 license = lib.licenses.bsd3;
243 maintainers = with lib.maintainers; [
244 ramkromberg
245 atemu
246 doronbehar
247 ];
248 platforms = lib.platforms.all;
249 mainProgram = desktopBinary;
250 };
251})