diff --git a/flake.nix b/flake.nix index ac7c38d..95c4482 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ flake = { lib = { - inherit (import ./lib/stdlib-extended.nix input:s nixpkgs.lib) nvim; + inherit (import ./lib/stdlib-extended.nix inputs nixpkgs.lib) nvim; inherit (import ./configuration.nix inputs) neovimConfiguration; }; diff --git a/lib/binds.nix b/lib/binds.nix new file mode 100644 index 0000000..c2feb27 --- /dev/null +++ b/lib/binds.nix @@ -0,0 +1,66 @@ +{lib}: rec { + mkLuaBinding = key: action: desc: + lib.mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; + }; + }; + + mkExprBinding = key: action: desc: + lib.mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; + expr = true; + }; + }; + + mkBinding = key: action: desc: + lib.mkIf (key != null) { + "${key}" = { + inherit action desc; + silent = true; + }; + }; + + mkMappingOption = description: default: + lib.mkOption { + type = lib.types.nullOrlib.types.str; + inherit default description; + }; + + # Utility function that takes two attrsets: + # { someKey = "some_value" } and + # { someKey = { description = "Some Description"; }; } + # and merges them into + # { someKey = { value = "some_value"; description = "Some Description"; }; } + addDescriptionsToMappings = actualMappings: mappingDefinitions: + lib.attrsets.mapAttrs (name: value: let + isNested = lib.isAttrs value; + returnedValue = + if isNested + then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" + else { + value = value; + description = mappingDefinitions."${name}".description; + }; + in + returnedValue) + actualMappings; + + mkSetBinding = binding: action: + mkBinding binding.value action binding.description; + + mkSetExprBinding = binding: action: + mkExprBinding binding.value action binding.description; + + mkSetLuaBinding = binding: action: + mkLuaBinding binding.value action binding.description; + + # For forward compatibility. + literalExpression = lib.literalExpression or lib.literalExample; + literalDocBook = lib.literalDocBook or lib.literalExample; +} diff --git a/lib/stdlib-extended.nix b/lib/stdlib-extended.nix index a54e5e9..4ead7ab 100644 --- a/lib/stdlib-extended.nix +++ b/lib/stdlib-extended.nix @@ -4,71 +4,6 @@ nixpkgsLib: let mkNvimLib = import ./.; in - nixpkgsLib.extend (self: super: rec { + nixpkgsLib.extend (self: super: { nvim = mkNvimLib {lib = self;}; - - mkLuaBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - lua = true; - silent = true; - }; - }; - - mkExprBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - lua = true; - silent = true; - expr = true; - }; - }; - - mkBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - silent = true; - }; - }; - - mkMappingOption = description: default: - self.mkOption { - type = self.types.nullOr self.types.str; - inherit default description; - }; - - # Utility function that takes two attrsets: - # { someKey = "some_value" } and - # { someKey = { description = "Some Description"; }; } - # and merges them into - # { someKey = { value = "some_value"; description = "Some Description"; }; } - addDescriptionsToMappings = actualMappings: mappingDefinitions: - self.attrsets.mapAttrs (name: value: let - isNested = self.isAttrs value; - returnedValue = - if isNested - then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" - else { - value = value; - description = mappingDefinitions."${name}".description; - }; - in - returnedValue) - actualMappings; - - mkSetBinding = binding: action: - mkBinding binding.value action binding.description; - - mkSetExprBinding = binding: action: - mkExprBinding binding.value action binding.description; - - mkSetLuaBinding = binding: action: - mkLuaBinding binding.value action binding.description; - - # For forward compatibility. - literalExpression = super.literalExpression or super.literalExample; - literalDocBook = super.literalDocBook or super.literalExample; }) diff --git a/lib/types/default.nix b/lib/types/default.nix index bfaa38d..2824a3a 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -1,6 +1,9 @@ -{lib}: let +{ + inputs, + lib, +}: let typesDag = import ./dag.nix {inherit lib;}; - typesPlugin = import ./plugins.nix {inherit lib;}; + typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesLanguage = import ./languages.nix {inherit lib;}; in { inherit (typesDag) dagOf; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index ccbde55..3ae5f03 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -1,102 +1,17 @@ {lib}: with lib; let - # Plugin must be same as input name from flake.nix - availablePlugins = [ - # TODO: sort by category - "nvim-treesitter-context" - "gitsigns-nvim" - "plenary-nvim" - "nvim-lspconfig" - "nvim-treesitter" - "lspsaga" - "lspkind" - "nvim-lightbulb" - "lsp-signature" - "nvim-tree-lua" - "nvim-bufferline-lua" - "lualine" - "nvim-compe" - "nvim-autopairs" - "nvim-ts-autotag" - "nvim-web-devicons" - "tokyonight" - "bufdelete-nvim" - "nvim-cmp" - "cmp-nvim-lsp" - "cmp-buffer" - "cmp-vsnip" - "cmp-path" - "cmp-treesitter" - "crates-nvim" - "vim-vsnip" - "nvim-code-action-menu" - "trouble" - "null-ls" - "which-key" - "indent-blankline" - "nvim-cursorline" - "sqls-nvim" - "glow-nvim" - "telescope" - "rust-tools" - "onedark" - "catppuccin" - "dracula" - "minimap-vim" - "dashboard-nvim" - "alpha-nvim" - "scrollbar-nvim" - "codewindow-nvim" - "nvim-notify" - "cinnamon-nvim" - "cheatsheet-nvim" - "ccc" - "cellular-automaton" - "presence-nvim" - "icon-picker-nvim" - "dressing-nvim" - "orgmode-nvim" - "obsidian-nvim" - "vim-markdown" - "tabular" - "toggleterm-nvim" - "noice-nvim" - "nui-nvim" - "copilot-lua" - "tabnine-nvim" - "nvim-session-manager" - "gesture-nvim" - "comment-nvim" - "kommentary" - "mind-nvim" - "fidget-nvim" - "diffview-nvim" - "todo-comments" - "flutter-tools" - "flutter-tools-patched" - "hop-nvim" - "leap-nvim" - "modes-nvim" - "vim-repeat" - "smartcolumn" - "project-nvim" - "elixir-ls" - "elixir-tools" - "nvim-colorizer-lua" - "vim-illuminate" - "nvim-surround" - "nvim-dap" - "nvim-dap-ui" - "nvim-navic" - "nvim-navbuddy" - "copilot-cmp" - ]; - # You can either use the name of the plugin or a package. + fromInputs = inputs: prefix: + mapAttrs' + (n: v: nameValuePair (removePrefix prefix n) {src = v;}) + (filterAttrs (n: _: hasPrefix prefix n) inputs); + + rawPlugins = fromInputs inputs "plugin-"; + pluginType = with types; nullOr ( either package - (enum availablePlugins) + (enum rawPlugins) ); pluginsType = types.listOf pluginType;