diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 310fdaa..9515b04 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -73,6 +73,7 @@ with lib; let "diffview-nvim" "todo-comments" "flutter-tools" + "flutter-tools-patched" "hop-nvim" "leap-nvim" "modes-nvim" diff --git a/modules/default.nix b/modules/default.nix index f7abc9e..1e06398 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -25,13 +25,13 @@ inputs: { // extraSpecialArgs; }; - buildPlug = name: - buildVimPluginFrom2Nix rec { - pname = name; - version = "master"; - src = assert lib.asserts.assertMsg (name != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter."; - getAttr pname inputs; - }; + buildPlug = {pname, ...} @ args: + assert lib.asserts.assertMsg (pname != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter."; + buildVimPluginFrom2Nix (args + // { + version = "master"; + src = getAttr pname inputs; + }); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); @@ -45,7 +45,13 @@ inputs: { ( if (plug == "nvim-treesitter") then (buildTreesitterPlug vimOptions.treesitter.grammars) - else (buildPlug plug) + else if (plug == "flutter-tools-patched") + then + (buildPlug { + pname = "flutter-tools"; + patches = [../patches/flutter-tools.patch]; + }) + else (buildPlug {pname = plug;}) ) else plug )) diff --git a/modules/languages/dart/config.nix b/modules/languages/dart/config.nix index ff19ede..82b061d 100644 --- a/modules/languages/dart/config.nix +++ b/modules/languages/dart/config.nix @@ -35,7 +35,10 @@ in { }) (mkIf (ftcfg.enable) { - vim.startPlugins = ["flutter-tools"]; + vim.startPlugins = + if ftcfg.enableNoResolvePatch + then ["flutter-tools-patched"] + else ["flutter-tools"]; vim.luaConfigRC.flutter-tools = nvim.dag.entryAnywhere '' require('flutter-tools').setup { diff --git a/modules/languages/dart/dart.nix b/modules/languages/dart/dart.nix index 728e64d..f6694ad 100644 --- a/modules/languages/dart/dart.nix +++ b/modules/languages/dart/dart.nix @@ -56,6 +56,16 @@ in { default = config.vim.languages.enableLSP; }; + enableNoResolvePatch = mkOption { + description = '' + Patch flutter-tools so that it doesn't resolve symlinks when detecting flutter path. + This is required if you want to use a flutter package built with nix. + If you are using a flutter SDK installed from a different source and encounter the error "`dart` missing from PATH", disable this option. + ''; + type = types.bool; + default = true; + }; + color = { enable = mkEnableOption "Whether or mot to highlight color variables at all"; diff --git a/patches/flutter-tools.patch b/patches/flutter-tools.patch new file mode 100644 index 0000000..b8315fe --- /dev/null +++ b/patches/flutter-tools.patch @@ -0,0 +1,41 @@ +diff --git a/lua/flutter-tools/executable.lua b/lua/flutter-tools/executable.lua +index 3807a4f..3345760 100644 +--- a/lua/flutter-tools/executable.lua ++++ b/lua/flutter-tools/executable.lua +@@ -31,12 +31,12 @@ local function _dart_sdk_root(paths) + end + + if utils.executable("flutter") then +- local flutter_path = fn.resolve(fn.exepath("flutter")) ++ local flutter_path = fn.exepath("flutter") + local flutter_bin = fn.fnamemodify(flutter_path, ":h") + return path.join(flutter_bin, dart_sdk) + end + +- if utils.executable("dart") then return fn.resolve(fn.exepath("dart")) end ++ if utils.executable("dart") then return fn.exepath("dart") end + + return "" + end +@@ -50,10 +50,10 @@ end + ---Get paths for flutter and dart based on the binary locations + ---@return table + local function get_default_binaries() +- local flutter_bin = fn.resolve(fn.exepath("flutter")) ++ local flutter_bin = fn.exepath("flutter") + return { + flutter_bin = flutter_bin, +- dart_bin = fn.resolve(fn.exepath("dart")), ++ dart_bin = fn.exepath("dart"), + flutter_sdk = _flutter_sdk_root(flutter_bin), + } + end +@@ -119,7 +119,7 @@ function M.get(callback) + end + + if config.flutter_path then +- local flutter_path = fn.resolve(config.flutter_path) ++ local flutter_path = config.flutter_path + _paths = { flutter_bin = flutter_path, flutter_sdk = _flutter_sdk_root(flutter_path) } + _paths.dart_sdk = _dart_sdk_root(_paths) + _paths.dart_bin = _flutter_sdk_dart_bin(_paths.flutter_sdk)