vimUtils.makeCustomizable: rewrite to include more things

The current wrapper only includes vim, gvim and the man pages
(optionally). This rewrite distinguishes two scenarios, which I expect
cover the majority of use cases:

- standalone mode, when `name != "vim"`, means the user already has a
  vim in scope and only wants to add a customized version with a
  different name. In this case we only include wrappers for `/bin/*vim`.
- non-standalone mode, when `name == "vim"`, means the user expects a
  normal vim package that uses the specified configuration. In this case
  we include everything in the original derivation, with wrappers for
  all the executables that accept a vimrc.
This commit is contained in:
Naïm Favier 2022-03-19 09:41:32 +01:00
parent 488869f602
commit 7ab1fd262f
No known key found for this signature in database
GPG key ID: 49B07322580B7EE2
4 changed files with 133 additions and 55 deletions

View file

@ -18,7 +18,7 @@ Adding custom .vimrc lines can be done using the following code:
```nix ```nix
vim_configurable.customize { vim_configurable.customize {
# `name` specifies the name of the executable and package # `name` optionally specifies the name of the executable and package
name = "vim-with-plugins"; name = "vim-with-plugins";
vimrcConfig.customRC = '' vimrcConfig.customRC = ''
@ -28,6 +28,9 @@ vim_configurable.customize {
``` ```
This configuration is used when Vim is invoked with the command specified as name, in this case `vim-with-plugins`. This configuration is used when Vim is invoked with the command specified as name, in this case `vim-with-plugins`.
You can also omit `name` to customize Vim itself. See the
[definition of `vimUtils.makeCustomizable`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/vim-utils.nix#L408)
for all supported options.
For Neovim the `configure` argument can be overridden to achieve the same: For Neovim the `configure` argument can be overridden to achieve the same:

View file

@ -794,6 +794,54 @@
LGPL3+ and BSD3 with optional unfree unRAR licensed code LGPL3+ and BSD3 with optional unfree unRAR licensed code
</para> </para>
</listitem> </listitem>
<listitem>
<para>
The <literal>vim.customize</literal> function produced by
<literal>vimUtils.makeCustomizable</literal> now has a
slightly different interface:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
The wrapper now includes everything in the given Vim
derivation if <literal>name</literal> is
<literal>&quot;vim&quot;</literal> (the default). This
makes the <literal>wrapManual</literal> argument obsolete,
but this behavior can be overriden by setting the
<literal>standalone</literal> argument.
</para>
</listitem>
<listitem>
<para>
All the executables present in the given derivation (or,
in <literal>standalone</literal> mode, only the
<literal>*vim</literal> ones) are wrapped. This makes the
<literal>wrapGui</literal> argument obsolete.
</para>
</listitem>
<listitem>
<para>
The <literal>vimExecutableName</literal> and
<literal>gvimExecutableName</literal> arguments were
replaced by a single <literal>executableName</literal>
argument in which the shell variable
<literal>$exe</literal> can be used to refer to the
wrapped executables name.
</para>
</listitem>
</itemizedlist>
<para>
See the comments in
<literal>pkgs/applications/editors/vim/plugins/vim-utils.nix</literal>
for more details.
</para>
<para>
<literal>vimUtils.vimWithRC</literal> was removed. You should
instead use <literal>customize</literal> on a Vim derivation,
which now accepts <literal>vimrcFile</literal> and
<literal>gvimrcFile</literal> arguments.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
<literal>tilp2</literal> was removed together with its module <literal>tilp2</literal> was removed together with its module

View file

@ -315,6 +315,15 @@ In addition to numerous new and upgraded packages, this release has the followin
- `pkgs._7zz` is now correctly licensed as LGPL3+ and BSD3 with optional unfree unRAR licensed code - `pkgs._7zz` is now correctly licensed as LGPL3+ and BSD3 with optional unfree unRAR licensed code
- The `vim.customize` function produced by `vimUtils.makeCustomizable` now has a slightly different interface:
* The wrapper now includes everything in the given Vim derivation if `name` is `"vim"` (the default). This makes the `wrapManual` argument obsolete, but this behavior can be overriden by setting the `standalone` argument.
* All the executables present in the given derivation (or, in `standalone` mode, only the `*vim` ones) are wrapped. This makes the `wrapGui` argument obsolete.
* The `vimExecutableName` and `gvimExecutableName` arguments were replaced by a single `executableName` argument in which the shell variable `$exe` can be used to refer to the wrapped executable's name.
See the comments in `pkgs/applications/editors/vim/plugins/vim-utils.nix` for more details.
`vimUtils.vimWithRC` was removed. You should instead use `customize` on a Vim derivation, which now accepts `vimrcFile` and `gvimrcFile` arguments.
- `tilp2` was removed together with its module - `tilp2` was removed together with its module
- The F-PROT antivirus (`fprot` package) and its service module were removed because it - The F-PROT antivirus (`fprot` package) and its service module were removed because it

View file

@ -1,5 +1,6 @@
# tests available at pkgs/test/vim # tests available at pkgs/test/vim
{ lib, stdenv, vim, vimPlugins, vim_configurable, buildEnv, writeText, writeScriptBin { lib, stdenv, vim, vimPlugins, vim_configurable, buildEnv, writeText
, runCommand, makeWrapper
, nix-prefetch-hg, nix-prefetch-git , nix-prefetch-hg, nix-prefetch-git
, fetchFromGitHub, runtimeShell , fetchFromGitHub, runtimeShell
, hasLuaModule , hasLuaModule
@ -16,7 +17,7 @@ Install Vim like this eg using nixos option environment.systemPackages which wil
vim-with-plugins in PATH: vim-with-plugins in PATH:
vim_configurable.customize { vim_configurable.customize {
name = "vim-with-plugins"; name = "vim-with-plugins"; # optional
# add custom .vimrc lines like this: # add custom .vimrc lines like this:
vimrcConfig.customRC = '' vimrcConfig.customRC = ''
@ -404,64 +405,81 @@ rec {
inherit vimrcContent; inherit vimrcContent;
inherit packDir; inherit packDir;
# shell script with custom name passing [-u vimrc] [-U gvimrc] to vim makeCustomizable = let
vimWithRC = { mkVimrcFile = vimrcFile; # avoid conflict with argument name
vimExecutable, in vim: vim // {
gvimExecutable, # Returns a customized vim that uses the specified vimrc configuration.
vimManPages, customize =
wrapManual, { # The name of the derivation.
wrapGui, name ? "vim"
name ? "vim", , # A shell word used to specify the names of the customized executables.
vimrcFile ? null, # The shell variable $exe can be used to refer to the wrapped executable's name.
gvimrcFile ? null, # Examples: "my-$exe", "$exe-with-plugins", "\${exe/vim/v1m}"
vimExecutableName, executableName ?
gvimExecutableName, if lib.hasInfix "vim" name then
}: lib.replaceStrings [ "vim" ] [ "$exe" ] name
let else
rcOption = o: file: lib.optionalString (file != null) "-${o} ${file}"; "\${exe/vim/${lib.escapeShellArg name}}"
vimWrapperScript = writeScriptBin vimExecutableName '' , # A custom vimrc configuration, treated as an argument to vimrcContent (see the documentation in this file).
#!${runtimeShell} vimrcConfig ? null
exec ${vimExecutable} ${rcOption "u" vimrcFile} ${rcOption "U" gvimrcFile} "$@" , # A custom vimrc file.
''; vimrcFile ? null
gvimWrapperScript = writeScriptBin gvimExecutableName '' , # A custom gvimrc file.
#!${stdenv.shell} gvimrcFile ? null
exec ${gvimExecutable} ${rcOption "u" vimrcFile} ${rcOption "U" gvimrcFile} "$@" , # If set to true, return the *vim wrappers only.
''; # If set to false, overlay the wrappers on top of the original vim derivation.
in # This ensures that things like man pages and .desktop files are available.
buildEnv { standalone ? name != "vim" && wrapManual != true
inherit name;
paths = [
vimWrapperScript
] ++ lib.optional wrapGui gvimWrapperScript
++ lib.optional wrapManual vimManPages
;
};
# add a customize option to a vim derivation , # deprecated arguments (TODO: remove eventually)
makeCustomizable = vim: vim // { wrapManual ? null, wrapGui ? null, vimExecutableName ? null, gvimExecutableName ? null,
customize = { }:
name, lib.warnIf (wrapManual != null) ''
vimrcConfig, vim.customize: wrapManual is deprecated: the manual is now included by default if `name == "vim"`.
wrapManual ? true, ${if wrapManual == true && name != "vim" then "Set `standalone = false` to include the manual."
wrapGui ? false, else if wrapManual == false && name == "vim" then "Set `standalone = true` to get the *vim wrappers only."
vimExecutableName ? name, else ""}''
gvimExecutableName ? (lib.concatStrings [ "g" name ]), lib.warnIf (wrapGui != null)
}: vimWithRC { "vim.customize: wrapGui is deprecated: gvim is now automatically included if present"
vimExecutable = "${vim}/bin/vim"; lib.throwIfNot (vimExecutableName == null && gvimExecutableName == null)
gvimExecutable = "${vim}/bin/gvim"; "vim.customize: (g)vimExecutableName is deprecated: use executableName instead (see source code for examples)"
inherit name wrapManual wrapGui vimExecutableName gvimExecutableName; (let
vimrcFile = vimrcFile vimrcConfig; vimrc =
vimManPages = buildEnv { if vimrcFile != null then vimrcFile
name = "vim-doc"; else if vimrcConfig != null then mkVimrcFile vimrcConfig
paths = [ vim ]; else throw "at least one of vimrcConfig and vimrcFile must be specified";
pathsToLink = [ "/share/man" ]; bin = runCommand "${name}-bin" { buildInputs = [ makeWrapper ]; } ''
}; vimrc=${lib.escapeShellArg vimrc}
}; gvimrc=${if gvimrcFile != null then lib.escapeShellArg gvimrcFile else ""}
mkdir -p "$out/bin"
for exe in ${
if standalone then "{,g,r,rg,e}vim {,g}vimdiff"
else "{,g,r,rg,e}{vim,view} {,g}vimdiff ex"
}; do
if [[ -e ${vim}/bin/$exe ]]; then
dest="$out/bin/${executableName}"
if [[ -e $dest ]]; then
echo "ambiguous executableName: ''${dest##*/} already exists"
continue
fi
makeWrapper ${vim}/bin/"$exe" "$dest" \
--add-flags "-u ''${vimrc@Q} ''${gvimrc:+-U ''${gvimrc@Q}}"
fi
done
'';
in if standalone then bin else
buildEnv {
inherit name;
paths = [ (lib.lowPrio vim) bin ];
});
override = f: makeCustomizable (vim.override f); override = f: makeCustomizable (vim.override f);
overrideAttrs = f: makeCustomizable (vim.overrideAttrs f); overrideAttrs = f: makeCustomizable (vim.overrideAttrs f);
}; };
vimWithRC = throw "vimWithRC was removed, please use vim.customize instead";
pluginnames2Nix = {name, namefiles} : vim_configurable.customize { pluginnames2Nix = {name, namefiles} : vim_configurable.customize {
inherit name; inherit name;
vimrcConfig.vam.knownPlugins = vimPlugins; vimrcConfig.vam.knownPlugins = vimPlugins;