flake.nix 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. description = "Neovim flake";
  3. inputs = {
  4. nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  5. flake-utils.url = "github:numtide/flake-utils";
  6. };
  7. outputs = { self, nixpkgs, flake-utils }:
  8. {
  9. overlay = final: prev: rec {
  10. neovim-unwrapped = prev.neovim-unwrapped.override ({
  11. libvterm-neovim = prev.libvterm-neovim.overrideAttrs (old: {
  12. version = "0.3";
  13. src = builtins.fetchTarball {
  14. url = "https://www.leonerd.org.uk/code/libvterm/libvterm-0.3.tar.gz";
  15. sha256 = "0zg6sn5brwrnqaab883pdj0l2swk5askbbwbdam0zq55ikbrzgar";
  16. };
  17. });
  18. });
  19. neovim = final.neovim-unwrapped.overrideAttrs (oa: {
  20. version = "master";
  21. src = ../.;
  22. buildInputs = oa.buildInputs
  23. ++ final.lib.optionals final.stdenv.isDarwin
  24. (with final.darwin.apple_sdk.frameworks; [ CoreServices ]);
  25. });
  26. # a development binary to help debug issues
  27. neovim-debug = let
  28. stdenv = if final.stdenv.isLinux then
  29. final.llvmPackages_latest.stdenv
  30. else
  31. final.stdenv;
  32. in ((neovim.override {
  33. lua = final.luajit;
  34. inherit stdenv;
  35. }).overrideAttrs (oa: {
  36. dontStrip = true;
  37. NIX_CFLAGS_COMPILE = " -ggdb -Og";
  38. cmakeBuildType = "Debug";
  39. cmakeFlags = oa.cmakeFlags ++ [ "-DMIN_LOG_LEVEL=0" ];
  40. disallowedReferences = [ ];
  41. }));
  42. # for neovim developers, beware of the slow binary
  43. neovim-developer = let luacheck = final.luaPackages.luacheck;
  44. in (neovim-debug.override ({
  45. doCheck = final.stdenv.isLinux;
  46. })).overrideAttrs (oa: {
  47. cmakeFlags = oa.cmakeFlags ++ [
  48. "-DLUACHECK_PRG=${luacheck}/bin/luacheck"
  49. "-DMIN_LOG_LEVEL=0"
  50. "-DENABLE_LTO=OFF"
  51. ] ++ final.lib.optionals final.stdenv.isLinux [
  52. # https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
  53. # https://clang.llvm.org/docs/AddressSanitizer.html#symbolizing-the-reports
  54. "-DCLANG_ASAN_UBSAN=ON"
  55. ];
  56. });
  57. };
  58. } // flake-utils.lib.eachDefaultSystem (system:
  59. let
  60. pkgs = import nixpkgs {
  61. overlays = [ self.overlay ];
  62. inherit system;
  63. };
  64. lua = pkgs.lua5_1;
  65. pythonEnv = pkgs.python3.withPackages (ps: [
  66. ps.msgpack
  67. ps.flake8 # for 'make pylint'
  68. ]);
  69. in {
  70. packages = with pkgs; {
  71. default = neovim;
  72. inherit neovim neovim-debug neovim-developer;
  73. };
  74. checks = {
  75. pylint = pkgs.runCommand "pylint" {
  76. nativeBuildInputs = [ pythonEnv ];
  77. preferLocalBuild = true;
  78. } "make -C ${./..} pylint > $out";
  79. shlint = pkgs.runCommand "shlint" {
  80. nativeBuildInputs = [ pkgs.shellcheck ];
  81. preferLocalBuild = true;
  82. } "make -C ${./..} shlint > $out";
  83. };
  84. # kept for backwards-compatibility
  85. defaultPackage = pkgs.neovim;
  86. devShells = {
  87. default = pkgs.neovim-developer.overrideAttrs (oa: {
  88. buildInputs = with pkgs;
  89. oa.buildInputs ++ [
  90. cmake
  91. lua.pkgs.luacheck
  92. sumneko-lua-language-server
  93. pythonEnv
  94. include-what-you-use # for scripts/check-includes.py
  95. jq # jq for scripts/vim-patch.sh -r
  96. shellcheck # for `make shlint`
  97. doxygen # for script/gen_vimdoc.py
  98. clang-tools # for clangd to find the correct headers
  99. ];
  100. shellHook = oa.shellHook + ''
  101. export NVIM_PYTHON_LOG_LEVEL=DEBUG
  102. export NVIM_LOG_FILE=/tmp/nvim.log
  103. export ASAN_SYMBOLIZER_PATH=${pkgs.llvm_11}/bin/llvm-symbolizer
  104. # ASAN_OPTIONS=detect_leaks=1
  105. export ASAN_OPTIONS="log_path=./test.log:abort_on_error=1"
  106. export UBSAN_OPTIONS=print_stacktrace=1
  107. mkdir -p build/runtime/parser
  108. # nvim looks into CMAKE_INSTALL_DIR. Hack to avoid errors
  109. # when running the functionaltests
  110. mkdir -p outputs/out/share/nvim/syntax
  111. touch outputs/out/share/nvim/syntax/syntax.vim
  112. # for treesitter functionaltests
  113. mkdir -p runtime/parser
  114. cp -f ${pkgs.tree-sitter.builtGrammars.tree-sitter-c}/parser runtime/parser/c.so
  115. '';
  116. });
  117. };
  118. });
  119. }