From 7ab1fd262ffae10c85f4100027872d5954e60797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 19 Mar 2022 09:41:32 +0100 Subject: [PATCH 1/5] 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. --- doc/languages-frameworks/vim.section.md | 5 +- .../from_md/release-notes/rl-2205.section.xml | 48 +++++++ .../manual/release-notes/rl-2205.section.md | 9 ++ .../editors/vim/plugins/vim-utils.nix | 126 ++++++++++-------- 4 files changed, 133 insertions(+), 55 deletions(-) diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md index a615d585b151..04cb271a43be 100644 --- a/doc/languages-frameworks/vim.section.md +++ b/doc/languages-frameworks/vim.section.md @@ -18,7 +18,7 @@ Adding custom .vimrc lines can be done using the following code: ```nix 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"; 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`. +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: diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index fc7cb28ffdfd..c128be6423bc 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -794,6 +794,54 @@ 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 diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 2ff5865b7355..b00a4781c4ca 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -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 +- 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 - The F-PROT antivirus (`fprot` package) and its service module were removed because it diff --git a/pkgs/applications/editors/vim/plugins/vim-utils.nix b/pkgs/applications/editors/vim/plugins/vim-utils.nix index 4183b6214351..b291928f25aa 100644 --- a/pkgs/applications/editors/vim/plugins/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix @@ -1,5 +1,6 @@ # 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 , fetchFromGitHub, runtimeShell , hasLuaModule @@ -16,7 +17,7 @@ Install Vim like this eg using nixos option environment.systemPackages which wil vim-with-plugins in PATH: vim_configurable.customize { - name = "vim-with-plugins"; + name = "vim-with-plugins"; # optional # add custom .vimrc lines like this: vimrcConfig.customRC = '' @@ -404,64 +405,81 @@ rec { inherit vimrcContent; inherit packDir; - # shell script with custom name passing [-u vimrc] [-U gvimrc] to vim - vimWithRC = { - vimExecutable, - gvimExecutable, - vimManPages, - wrapManual, - wrapGui, - name ? "vim", - vimrcFile ? null, - gvimrcFile ? null, - vimExecutableName, - gvimExecutableName, - }: - let - rcOption = o: file: lib.optionalString (file != null) "-${o} ${file}"; - vimWrapperScript = writeScriptBin vimExecutableName '' - #!${runtimeShell} - exec ${vimExecutable} ${rcOption "u" vimrcFile} ${rcOption "U" gvimrcFile} "$@" - ''; - gvimWrapperScript = writeScriptBin gvimExecutableName '' - #!${stdenv.shell} - exec ${gvimExecutable} ${rcOption "u" vimrcFile} ${rcOption "U" gvimrcFile} "$@" - ''; - in - buildEnv { - inherit name; - paths = [ - vimWrapperScript - ] ++ lib.optional wrapGui gvimWrapperScript - ++ lib.optional wrapManual vimManPages - ; - }; + makeCustomizable = let + mkVimrcFile = vimrcFile; # avoid conflict with argument name + in vim: vim // { + # Returns a customized vim that uses the specified vimrc configuration. + customize = + { # The name of the derivation. + name ? "vim" + , # A shell word used to specify the names of the customized executables. + # The shell variable $exe can be used to refer to the wrapped executable's name. + # Examples: "my-$exe", "$exe-with-plugins", "\${exe/vim/v1m}" + executableName ? + if lib.hasInfix "vim" name then + lib.replaceStrings [ "vim" ] [ "$exe" ] name + else + "\${exe/vim/${lib.escapeShellArg name}}" + , # A custom vimrc configuration, treated as an argument to vimrcContent (see the documentation in this file). + vimrcConfig ? null + , # A custom vimrc file. + vimrcFile ? null + , # A custom gvimrc file. + gvimrcFile ? null + , # If set to true, return the *vim wrappers only. + # If set to false, overlay the wrappers on top of the original vim derivation. + # This ensures that things like man pages and .desktop files are available. + standalone ? name != "vim" && wrapManual != true - # add a customize option to a vim derivation - makeCustomizable = vim: vim // { - customize = { - name, - vimrcConfig, - wrapManual ? true, - wrapGui ? false, - vimExecutableName ? name, - gvimExecutableName ? (lib.concatStrings [ "g" name ]), - }: vimWithRC { - vimExecutable = "${vim}/bin/vim"; - gvimExecutable = "${vim}/bin/gvim"; - inherit name wrapManual wrapGui vimExecutableName gvimExecutableName; - vimrcFile = vimrcFile vimrcConfig; - vimManPages = buildEnv { - name = "vim-doc"; - paths = [ vim ]; - pathsToLink = [ "/share/man" ]; - }; - }; + , # deprecated arguments (TODO: remove eventually) + wrapManual ? null, wrapGui ? null, vimExecutableName ? null, gvimExecutableName ? null, + }: + lib.warnIf (wrapManual != null) '' + vim.customize: wrapManual is deprecated: the manual is now included by default if `name == "vim"`. + ${if wrapManual == true && name != "vim" then "Set `standalone = false` to include the manual." + else if wrapManual == false && name == "vim" then "Set `standalone = true` to get the *vim wrappers only." + else ""}'' + lib.warnIf (wrapGui != null) + "vim.customize: wrapGui is deprecated: gvim is now automatically included if present" + lib.throwIfNot (vimExecutableName == null && gvimExecutableName == null) + "vim.customize: (g)vimExecutableName is deprecated: use executableName instead (see source code for examples)" + (let + vimrc = + if vimrcFile != null then vimrcFile + else if vimrcConfig != null then mkVimrcFile vimrcConfig + else throw "at least one of vimrcConfig and vimrcFile must be specified"; + 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); overrideAttrs = f: makeCustomizable (vim.overrideAttrs f); }; + vimWithRC = throw "vimWithRC was removed, please use vim.customize instead"; + pluginnames2Nix = {name, namefiles} : vim_configurable.customize { inherit name; vimrcConfig.vam.knownPlugins = vimPlugins; From 65a6e2cb0df39aafa8d14b1b5e752688d0ba9290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 19 Mar 2022 20:04:20 +0100 Subject: [PATCH 2/5] vim_configurable: don't rewrap See discussion at https://github.com/NixOS/nixpkgs/commit/40dea2488fec71f6224944c1b9dae280c2fcc2dc#commitcomment-68982753 Also remove the patchelf call on gvim since it's a symlink now. --- .../applications/editors/vim/configurable.nix | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/pkgs/applications/editors/vim/configurable.nix b/pkgs/applications/editors/vim/configurable.nix index 01561f4c2722..9f17bfa767e7 100644 --- a/pkgs/applications/editors/vim/configurable.nix +++ b/pkgs/applications/editors/vim/configurable.nix @@ -3,7 +3,7 @@ , libX11, libXext, libSM, libXpm, libXt, libXaw, libXau, libXmu , libICE , vimPlugins -, makeWrapper +, makeWrapper, makeBinaryWrapper , wrapGAppsHook , runtimeShell @@ -134,7 +134,9 @@ in stdenv.mkDerivation rec { ++ lib.optional wrapPythonDrv makeWrapper ++ lib.optional nlsSupport gettext ++ lib.optional perlSupport perl - ++ lib.optional (guiSupport == "gtk3") wrapGAppsHook + # Make the inner wrapper binary to avoid double wrapping issues with wrapPythonDrv + # (https://github.com/NixOS/nixpkgs/pull/164163) + ++ lib.optional (guiSupport == "gtk3") (wrapGAppsHook.override { makeWrapper = makeBinaryWrapper; }) ; buildInputs = [ @@ -177,37 +179,13 @@ in stdenv.mkDerivation rec { patchelf --set-rpath \ "$(patchelf --print-rpath $out/bin/vim):${lib.makeLibraryPath buildInputs}" \ "$out"/bin/vim - if [[ -e "$out"/bin/gvim ]]; then - patchelf --set-rpath \ - "$(patchelf --print-rpath $out/bin/vim):${lib.makeLibraryPath buildInputs}" \ - "$out"/bin/gvim - fi ln -sfn '${nixosRuntimepath}' "$out"/share/vim/vimrc - '' + lib.optionalString wrapPythonDrv '' + ''; + + postFixup = lib.optionalString wrapPythonDrv '' wrapProgram "$out/bin/vim" --prefix PATH : "${python3}/bin" \ --set NIX_PYTHONPATH "${python3}/${python3.sitePackages}" - '' + lib.optionalString (guiSupport == "gtk3") '' - - rewrap () { - rm -f "$out/bin/$1" - echo -e '#!${runtimeShell}\n"'"$out/bin/vim"'" '"$2"' "$@"' > "$out/bin/$1" - chmod a+x "$out/bin/$1" - } - - rewrap ex -e - rewrap view -R - rewrap gvim -g - rewrap gex -eg - rewrap gview -Rg - rewrap rvim -Z - rewrap rview -RZ - rewrap rgvim -gZ - rewrap rgview -RgZ - rewrap evim -y - rewrap eview -yR - rewrap vimdiff -d - rewrap gvimdiff -gd ''; dontStrip = true; From 0eb92176bf486dab758ce55c494623f24937e45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 19 Mar 2022 22:56:44 +0100 Subject: [PATCH 3/5] vim_configurable: don't accept arbitrary arguments This hides potential errors. --- pkgs/applications/editors/vim/configurable.nix | 1 - pkgs/top-level/all-packages.nix | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/applications/editors/vim/configurable.nix b/pkgs/applications/editors/vim/configurable.nix index 9f17bfa767e7..b436c5db5b2d 100644 --- a/pkgs/applications/editors/vim/configurable.nix +++ b/pkgs/applications/editors/vim/configurable.nix @@ -25,7 +25,6 @@ , ximSupport ? config.vim.xim or true # less than 15KB, needed for deadkeys , darwinSupport ? config.vim.darwin or false # Enable Darwin support , ftNixSupport ? config.vim.ftNix or true # Add .nix filetype detection and minimal syntax highlighting support -, ... }: diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e8e159718ce4..62a8598c8ea9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24717,7 +24717,7 @@ with pkgs; assign-lb-ip = callPackage ../applications/networking/cluster/assign-lb-ip { }; astroid = callPackage ../applications/networking/mailreaders/astroid { - vim = vim_configurable.override { features = "normal"; gui = "auto"; }; + vim = vim_configurable.override { features = "normal"; }; }; aucatctl = callPackage ../applications/audio/aucatctl { }; @@ -29721,8 +29721,6 @@ with pkgs; vim_configurable = vimUtils.makeCustomizable (callPackage ../applications/editors/vim/configurable.nix { inherit (darwin.apple_sdk.frameworks) CoreServices Cocoa Foundation CoreData; inherit (darwin) libobjc; - gtk2 = if stdenv.isDarwin then gtk2-x11 else gtk2; - gtk3 = if stdenv.isDarwin then gtk3-x11 else gtk3; }); vim-darwin = (vim_configurable.override { From e6ff028cfa9990336a9ae4ee094c1513d7796d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sun, 20 Mar 2022 10:55:20 +0100 Subject: [PATCH 4/5] vim_configurable: drop patchelf It doesn't seem to change the RPATH even with all features enabled. --- pkgs/applications/editors/vim/configurable.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkgs/applications/editors/vim/configurable.nix b/pkgs/applications/editors/vim/configurable.nix index b436c5db5b2d..bc317b91597e 100644 --- a/pkgs/applications/editors/vim/configurable.nix +++ b/pkgs/applications/editors/vim/configurable.nix @@ -175,10 +175,6 @@ in stdenv.mkDerivation rec { postInstall = '' ln -s $out/bin/vim $out/bin/vi '' + lib.optionalString stdenv.isLinux '' - patchelf --set-rpath \ - "$(patchelf --print-rpath $out/bin/vim):${lib.makeLibraryPath buildInputs}" \ - "$out"/bin/vim - ln -sfn '${nixosRuntimepath}' "$out"/share/vim/vimrc ''; From 21e45db6f1b196678e967b516a0761922bdf5dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 19 Mar 2022 20:03:47 +0100 Subject: [PATCH 5/5] vim: make customizable --- pkgs/top-level/all-packages.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 62a8598c8ea9..f91166a3bc41 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -29706,9 +29706,9 @@ with pkgs; veusz = libsForQt5.callPackage ../applications/graphics/veusz { }; - vim = callPackage ../applications/editors/vim { + vim = vimUtils.makeCustomizable (callPackage ../applications/editors/vim { inherit (darwin.apple_sdk.frameworks) Carbon Cocoa; - }; + }); vimiv = callPackage ../applications/graphics/vimiv { };