@@ -1,8 +1,28 @@
11{ stdenv, fetchurl, pkgconfig, lua5_2, file, ncurses, gmime, pcre-cpp
2−, perl, perlPackages }:
2+, perl, perlPackages
3+, debugBuild ? false
4+, alternativeGlobalConfigFilePath ? null
5+}:
36
47let
5− version = "3.1";
8+ version = "3.1";
9+ binaryName = if debugBuild then "lumail2-debug" else "lumail2";
10+ alternativeConfig = builtins.toFile "lumail2.lua"
11+ (builtins.readFile alternativeGlobalConfigFilePath);
12+
13+ globalConfig = if isNull alternativeGlobalConfigFilePath then ''
14+ mkdir -p $out/etc/lumail2
15+ cp global.config.lua $out/etc/lumail2.lua
16+ for n in ./lib/*.lua; do
17+ cp "$n" $out/etc/lumail2/
18+ done
19+ '' else ''
20+ ln -s ${alternativeConfig} $out/etc/lumail2.lua
21+ '';
22+
23+ getPath = type : "${lua}/lib/?.${type};";
24+ luaPath = getPath "lua";
25+ luaCPath = getPath "so";
626in
727stdenv.mkDerivation {
828 name = "lumail-${version}";
@@ -12,7 +32,9 @@ stdenv.mkDerivation {
1232 sha256 = "0vj7p7f02m3w8wb74ilajcwznc4ai4h2ikkz9ildy0c00aqsi5w4";
1333 };
1434
15− nativeBuildInputs = [ pkgconfig ];
35+ enableParallelBuilding = true;
36+
37+ nativeBuildInputs = [ pkgconfig makeWrapper ];
1638 buildInputs = [
1739 lua5_2 file ncurses gmime pcre-cpp
1840 perl perlPackages.JSON perlPackages.NetIMAPClient
@@ -29,16 +51,26 @@ stdenv.mkDerivation {
2951 sed -e "s|^#\!\(.*/perl.*\)$|#\!\1$perlFlags|" -i perl.d/imap-proxy
3052 '';
3153
54+ buildFlags = if debugBuild then "lumail2-debug" else "";
55+
56+ installPhase = ''
57+ mkdir -p $out/bin || true
58+ install -m755 ${binaryName} $out/bin/
59+ ''
60+ + globalConfig
61+ + ''
62+ wrapProgram $out/bin/${binaryName} \
63+ --prefix LUA_PATH : "${luaPath}" \
64+ --prefix LUA_CPATH : "${luaCPath}"
65+ '';
66+
3267 makeFlags = [
3368 "LVER=lua"
3469 "PREFIX=$(out)"
3570 "SYSCONFDIR=$(out)/etc"
71+ "LUMAIL_LIBS=$(out)/etc/lumail2"
3672 ];
3773
38− postInstall = ''
39− cp lumail2.user.lua $out/etc/lumail2/
40− '';
41−
4274 meta = with stdenv.lib; {
4375 description = "Console-based email client";
4476 homepage = https://lumail.org/;