flake.nix 4.3 KB

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