3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/applications/networking/irc/weechat/wrapper.nix
Maximilian Bosch 681b1d8061
weechat: install all outputs into the final store path
Resolves #59300

Until now only `$out/bin/weechat` and `$out/bin/weechat-headless` were installed
into the store path that will be used when running i.e. `nix-env -iA weechat`.

Further outputs like icons (`$out/share/icons`), man pages (`$man`) or the HTML
documentation (`$out/share/doc/weechat`) are omitted at the moment. As
this can be fairly confusing I figured that it's better to copy those
files into the environment as well.

As `buildEnv` doesn't appear to support output splitting (you can only
install additional outputs of `paths` using `extraOutputsToInstall`),
it's easier for now to always install the `man` output by
default.

Man page installation can be turned off like this now:

```
weechat.override { installManPages = false; }
```
2019-04-14 17:52:58 +02:00

90 lines
2.8 KiB
Nix

{ stdenv, lib, runCommand, writeScriptBin, buildEnv
, pythonPackages, perlPackages, runtimeShell
}:
weechat:
let
wrapper = {
installManPages ? true
, configure ? { availablePlugins, ... }: { plugins = builtins.attrValues availablePlugins; }
}:
let
perlInterpreter = perlPackages.perl;
availablePlugins = let
simplePlugin = name: {pluginFile = "${weechat.${name}}/lib/weechat/plugins/${name}.so";};
in rec {
python = {
pluginFile = "${weechat.python}/lib/weechat/plugins/python.so";
withPackages = pkgsFun: (python // {
extraEnv = ''
export PYTHONHOME="${pythonPackages.python.withPackages pkgsFun}"
'';
});
};
perl = (simplePlugin "perl") // {
extraEnv = ''
export PATH="${perlInterpreter}/bin:$PATH"
'';
withPackages = pkgsFun: (perl // {
extraEnv = ''
${perl.extraEnv}
export PERL5LIB=${perlPackages.makeFullPerlPath (pkgsFun perlPackages)}
'';
});
};
tcl = simplePlugin "tcl";
ruby = simplePlugin "ruby";
guile = simplePlugin "guile";
lua = simplePlugin "lua";
};
config = configure { inherit availablePlugins; };
plugins = config.plugins or (builtins.attrValues availablePlugins);
pluginsDir = runCommand "weechat-plugins" {} ''
mkdir -p $out/plugins
for plugin in ${lib.concatMapStringsSep " " (p: p.pluginFile) plugins} ; do
ln -s $plugin $out/plugins
done
'';
init = let
init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or "");
mkScript = drv: lib.flip map drv.scripts (script: "/script load ${drv}/share/${script}");
scripts = builtins.concatStringsSep ";" (lib.foldl (scripts: drv: scripts ++ mkScript drv)
[ ] (config.scripts or []));
in "${scripts};${init}";
mkWeechat = bin: (writeScriptBin bin ''
#!${runtimeShell}
export WEECHAT_EXTRA_LIBDIR=${pluginsDir}
${lib.concatMapStringsSep "\n" (p: lib.optionalString (p ? extraEnv) p.extraEnv) plugins}
exec ${weechat}/bin/${bin} "$@" --run-command ${lib.escapeShellArg init}
'') // {
inherit (weechat) name man;
unwrapped = weechat;
outputs = [ "out" "man" ];
};
in buildEnv {
name = "weechat-bin-env-${weechat.version}";
extraOutputsToInstall = lib.optionals installManPages [ "man" ];
paths = [
(mkWeechat "weechat")
(mkWeechat "weechat-headless")
(runCommand "weechat-out-except-bin" { } ''
mkdir $out
ln -sf ${weechat}/include $out/include
ln -sf ${weechat}/lib $out/lib
ln -sf ${weechat}/share $out/share
'')
];
meta = builtins.removeAttrs weechat.meta [ "outputsToInstall" ];
};
in lib.makeOverridable wrapper