1{
2 lib,
3 runCommand,
4 writeScriptBin,
5 buildEnv,
6 python3Packages,
7 perlPackages,
8 runtimeShell,
9}:
10
11weechat:
12
13let
14 wrapper =
15 {
16 installManPages ? true,
17 configure ?
18 { availablePlugins, ... }:
19 {
20 # Do not include PHP by default, because it bloats the closure, doesn't
21 # build on Darwin, and there are no official PHP scripts.
22 plugins = builtins.attrValues (builtins.removeAttrs availablePlugins [ "php" ]);
23 },
24 }:
25
26 let
27 perlInterpreter = perlPackages.perl;
28 availablePlugins =
29 let
30 simplePlugin = name: { pluginFile = "${weechat.${name}}/lib/weechat/plugins/${name}.so"; };
31 in
32 rec {
33 python = (simplePlugin "python") // {
34 extraEnv = ''
35 export PATH="${python3Packages.python}/bin:$PATH"
36 '';
37 withPackages =
38 pkgsFun:
39 (
40 python
41 // {
42 extraEnv = ''
43 ${python.extraEnv}
44 export PYTHONHOME="${python3Packages.python.withPackages pkgsFun}"
45 '';
46 }
47 );
48 };
49 perl = (simplePlugin "perl") // {
50 extraEnv = ''
51 export PATH="${perlInterpreter}/bin:$PATH"
52 '';
53 withPackages =
54 pkgsFun:
55 (
56 perl
57 // {
58 extraEnv = ''
59 ${perl.extraEnv}
60 export PERL5LIB=${perlPackages.makeFullPerlPath (pkgsFun perlPackages)}
61 '';
62 }
63 );
64 };
65 tcl = simplePlugin "tcl";
66 ruby = simplePlugin "ruby";
67 guile = simplePlugin "guile";
68 lua = simplePlugin "lua";
69 php = simplePlugin "php";
70 };
71
72 config = configure { inherit availablePlugins; };
73
74 plugins = config.plugins or (builtins.attrValues availablePlugins);
75
76 pluginsDir = runCommand "weechat-plugins" { } ''
77 mkdir -p $out/plugins
78 for plugin in ${lib.concatMapStringsSep " " (p: p.pluginFile) plugins} ; do
79 ln -s $plugin $out/plugins
80 done
81 '';
82
83 init =
84 let
85 init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or "");
86
87 mkScript = drv: lib.forEach drv.scripts (script: "/script load ${drv}/share/${script}");
88
89 scripts = builtins.concatStringsSep ";" (
90 lib.foldl (scripts: drv: scripts ++ mkScript drv) [ ] (config.scripts or [ ])
91 );
92 in
93 "${scripts};${init}";
94
95 mkWeechat =
96 bin:
97 (writeScriptBin bin ''
98 #!${runtimeShell}
99 export WEECHAT_EXTRA_LIBDIR=${pluginsDir}
100 ${lib.concatMapStringsSep "\n" (p: lib.optionalString (p ? extraEnv) p.extraEnv) plugins}
101 exec ${weechat}/bin/${bin} "$@" --run-command ${lib.escapeShellArg init}
102 '')
103 // {
104 inherit (weechat) name man;
105 unwrapped = weechat;
106 outputs = [
107 "out"
108 "man"
109 ];
110 };
111 in
112 buildEnv {
113 name = "weechat-bin-env-${weechat.version}";
114 extraOutputsToInstall = lib.optionals installManPages [ "man" ];
115 paths = [
116 (mkWeechat "weechat")
117 (mkWeechat "weechat-headless")
118 (runCommand "weechat-out-except-bin" { } ''
119 mkdir $out
120 ln -sf ${weechat}/include $out/include
121 ln -sf ${weechat}/lib $out/lib
122 ln -sf ${weechat}/share $out/share
123 '')
124 ];
125 meta = builtins.removeAttrs weechat.meta [ "outputsToInstall" ];
126 };
127
128in
129lib.makeOverridable wrapper