From 233aa7648d529534cf8786abac63ac1af00bd630 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 31 Oct 2024 10:42:05 +0100 Subject: [PATCH 1/2] neovim: format derivation --- pkgs/by-name/ne/neovim-unwrapped/package.nix | 338 +++++++++++-------- 1 file changed, 201 insertions(+), 137 deletions(-) diff --git a/pkgs/by-name/ne/neovim-unwrapped/package.nix b/pkgs/by-name/ne/neovim-unwrapped/package.nix index cec84b5d60f75..9fbf3572cbb7e 100644 --- a/pkgs/by-name/ne/neovim-unwrapped/package.nix +++ b/pkgs/by-name/ne/neovim-unwrapped/package.nix @@ -1,69 +1,92 @@ -{ lib, stdenv, fetchFromGitHub, removeReferencesTo, cmake, gettext, msgpack-c, darwin -, libuv, lua, pkg-config -, unibilium -, libvterm-neovim -, tree-sitter -, fetchurl -, buildPackages -, treesitter-parsers ? import ./treesitter-parsers.nix { inherit fetchurl; } -, fixDarwinDylibNames -, glibcLocales ? null, procps ? null - -# now defaults to false because some tests can be flaky (clipboard etc), see -# also: https://github.com/neovim/neovim/issues/16233 -, nodejs ? null, fish ? null, python3 ? null +{ + lib, + stdenv, + fetchFromGitHub, + removeReferencesTo, + cmake, + gettext, + msgpack-c, + darwin, + libuv, + lua, + pkg-config, + unibilium, + libvterm-neovim, + tree-sitter, + fetchurl, + buildPackages, + treesitter-parsers ? import ./treesitter-parsers.nix { inherit fetchurl; }, + fixDarwinDylibNames, + glibcLocales ? null, + procps ? null, + + # now defaults to false because some tests can be flaky (clipboard etc), see + # also: https://github.com/neovim/neovim/issues/16233 + nodejs ? null, + fish ? null, + python3 ? null, }: -stdenv.mkDerivation (finalAttrs: +stdenv.mkDerivation ( + finalAttrs: let - nvim-lpeg-dylib = luapkgs: if stdenv.hostPlatform.isDarwin - then (luapkgs.lpeg.overrideAttrs (oa: { - preConfigure = '' - # neovim wants clang .dylib - sed -i makefile -e "s/CC = gcc/CC = clang/" - sed -i makefile -e "s/-bundle/-dynamiclib/" - ''; - preBuild = '' - # there seems to be implicit calls to Makefile from luarocks, we need to - # add a stage to build our dylib - make macosx - mkdir -p $out/lib - mv lpeg.so $out/lib/lpeg.dylib - ''; - nativeBuildInputs = - oa.nativeBuildInputs - ++ ( - lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames - ); - })) - else luapkgs.lpeg; - requiredLuaPkgs = ps: (with ps; [ - (nvim-lpeg-dylib ps) - luabitop - mpack - ] ++ lib.optionals finalAttrs.finalPackage.doCheck [ - luv - coxpcall - busted - luafilesystem - penlight - inspect - ] - ); - neovimLuaEnv = lua.withPackages requiredLuaPkgs; - neovimLuaEnvOnBuild = lua.luaOnBuild.withPackages requiredLuaPkgs; - codegenLua = - if lua.luaOnBuild.pkgs.isLuaJIT - then - let deterministicLuajit = - lua.luaOnBuild.override { + nvim-lpeg-dylib = + luapkgs: + if stdenv.hostPlatform.isDarwin then + (luapkgs.lpeg.overrideAttrs (oa: { + preConfigure = '' + # neovim wants clang .dylib + sed -i makefile -e "s/CC = gcc/CC = clang/" + sed -i makefile -e "s/-bundle/-dynamiclib/" + ''; + preBuild = '' + # there seems to be implicit calls to Makefile from luarocks, we need to + # add a stage to build our dylib + make macosx + mkdir -p $out/lib + mv lpeg.so $out/lib/lpeg.dylib + ''; + nativeBuildInputs = + oa.nativeBuildInputs ++ (lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames); + })) + else + luapkgs.lpeg; + requiredLuaPkgs = + ps: + ( + with ps; + [ + (nvim-lpeg-dylib ps) + luabitop + mpack + ] + ++ lib.optionals finalAttrs.finalPackage.doCheck [ + luv + coxpcall + busted + luafilesystem + penlight + inspect + ] + ); + neovimLuaEnv = lua.withPackages requiredLuaPkgs; + neovimLuaEnvOnBuild = lua.luaOnBuild.withPackages requiredLuaPkgs; + codegenLua = + if lua.luaOnBuild.pkgs.isLuaJIT then + let + deterministicLuajit = lua.luaOnBuild.override { deterministicStringIds = true; self = deterministicLuajit; }; - in deterministicLuajit.withPackages(ps: [ ps.mpack (nvim-lpeg-dylib ps) ]) - else lua.luaOnBuild; + in + deterministicLuajit.withPackages (ps: [ + ps.mpack + (nvim-lpeg-dylib ps) + ]) + else + lua.luaOnBuild; - -in { + in + { pname = "neovim-unwrapped"; version = "0.10.2"; @@ -86,26 +109,39 @@ in { dontFixCmake = true; inherit lua; - treesitter-parsers = treesitter-parsers // - { markdown = treesitter-parsers.markdown // { location = "tree-sitter-markdown"; }; } // - { markdown_inline = treesitter-parsers.markdown // { language = "markdown_inline"; location = "tree-sitter-markdown-inline"; }; } - ; - - buildInputs = [ - libuv - libvterm-neovim - # This is actually a c library, hence it's not included in neovimLuaEnv, - # see: - # https://github.com/luarocks/luarocks/issues/1402#issuecomment-1080616570 - # and it's definition at: pkgs/development/lua-modules/overrides.nix - lua.pkgs.libluv - msgpack-c - neovimLuaEnv - tree-sitter - unibilium - ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.libutil ] - ++ lib.optionals finalAttrs.finalPackage.doCheck [ glibcLocales procps ] - ; + treesitter-parsers = + treesitter-parsers + // { + markdown = treesitter-parsers.markdown // { + location = "tree-sitter-markdown"; + }; + } + // { + markdown_inline = treesitter-parsers.markdown // { + language = "markdown_inline"; + location = "tree-sitter-markdown-inline"; + }; + }; + + buildInputs = + [ + libuv + libvterm-neovim + # This is actually a c library, hence it's not included in neovimLuaEnv, + # see: + # https://github.com/luarocks/luarocks/issues/1402#issuecomment-1080616570 + # and it's definition at: pkgs/development/lua-modules/overrides.nix + lua.pkgs.libluv + msgpack-c + neovimLuaEnv + tree-sitter + unibilium + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.libutil ] + ++ lib.optionals finalAttrs.finalPackage.doCheck [ + glibcLocales + procps + ]; doCheck = false; @@ -125,66 +161,87 @@ in { ]; # extra programs test via `make functionaltest` - nativeCheckInputs = let - pyEnv = python3.withPackages(ps: with ps; [ pynvim msgpack ]); - in [ - fish - nodejs - pyEnv # for src/clint.py - ]; + nativeCheckInputs = + let + pyEnv = python3.withPackages ( + ps: with ps; [ + pynvim + msgpack + ] + ); + in + [ + fish + nodejs + pyEnv # for src/clint.py + ]; # nvim --version output retains compilation flags and references to build tools - postPatch = '' - substituteInPlace src/nvim/version.c --replace NVIM_VERSION_CFLAGS ""; - '' + lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' - sed -i runtime/CMakeLists.txt \ - -e "s|\".*/bin/nvim|\${stdenv.hostPlatform.emulator buildPackages} &|g" - sed -i src/nvim/po/CMakeLists.txt \ - -e "s|\$ Date: Thu, 31 Oct 2024 10:44:30 +0100 Subject: [PATCH 2/2] neovim: improve lpeg patch for darwin Co-authored-by: Carlos Hernandez --- pkgs/by-name/ne/neovim-unwrapped/package.nix | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/ne/neovim-unwrapped/package.nix b/pkgs/by-name/ne/neovim-unwrapped/package.nix index 9fbf3572cbb7e..bc61215ad4e91 100644 --- a/pkgs/by-name/ne/neovim-unwrapped/package.nix +++ b/pkgs/by-name/ne/neovim-unwrapped/package.nix @@ -32,18 +32,26 @@ stdenv.mkDerivation ( nvim-lpeg-dylib = luapkgs: if stdenv.hostPlatform.isDarwin then + let + luaLibDir = "$out/lib/lua/${lib.versions.majorMinor luapkgs.lua.luaversion}"; + in (luapkgs.lpeg.overrideAttrs (oa: { preConfigure = '' # neovim wants clang .dylib - sed -i makefile -e "s/CC = gcc/CC = clang/" - sed -i makefile -e "s/-bundle/-dynamiclib/" + substituteInPlace Makefile \ + --replace-fail "CC = gcc" "CC = clang" \ + --replace-fail "-bundle" "-dynamiclib" \ + --replace-fail "lpeg.so" "lpeg.dylib" ''; preBuild = '' # there seems to be implicit calls to Makefile from luarocks, we need to # add a stage to build our dylib make macosx - mkdir -p $out/lib - mv lpeg.so $out/lib/lpeg.dylib + mkdir -p ${luaLibDir} + mv lpeg.dylib ${luaLibDir}/lpeg.dylib + ''; + postInstall = '' + rm -f ${luaLibDir}/lpeg.so ''; nativeBuildInputs = oa.nativeBuildInputs ++ (lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames);