Skip to content

Commit

Permalink
Added an example of using pckr to download plugins instead of nix fro…
Browse files Browse the repository at this point in the history
…m the same file. (#12)

pckr example is included, 0 nix changes were required, only an extra lua function or 2.

Help added.

All plugins and lsps do work, HOWEVER,

since you arent downloading via nix, you are in charge of dependencies now. Have fun!

But it does actually work great if you get that right. dependencies for nixCats-nvim as-is are included in help file, and in the lua file for pckr itself.
  • Loading branch information
BirdeeHub committed Dec 30, 2023
1 parent 027d7d7 commit ad349a6
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 19 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ The solution:
Create nixCats so the lua may know what categories are packaged
You may optionally have your config in your normal directory as well.
(You will still be able to reference nixCats and the help should you do this.)
I ended up including a way to download via pckr because people seem to want
a way to load their config without nix as an option.
```

#### These are the reasons I wanted to do it this way:

The setup instructions for new plugins are all in Lua so translating them is effort.
I don't even want to translate instructions
into lazy or packer or the others, let alone nix.
instead of lazy, use pckr for emergency downloads without nix.

I didn't want to be forced into creating a new lua file,
writing lua within nix, or creating hooks for a DSL for every new plugin.
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@

-- THIS SETUP AND catPacker ARE FOR
-- pckr THE NEOVIM PLUGIN MANAGER
-- They do nothing if your config is loaded via nix.

-- when using this as a normal nvim config folder
-- default_cat_value is what nixCats('anything')
-- will return.
-- you may also require myLuaConf.isNixCats
-- to determine if this was loaded as a nix config
-- you must set this here at the start
require('nixCatsUtils').setup {
default_cat_value = true,
}

vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

-- load the plugins via pckr
-- YOU are in charge of putting the plugin
-- urls and build steps in there,
-- and you should keep any setup functions
-- OUT of that file, as they are ONLY loaded when this
-- configuration is NOT loaded via nix.
require('nixCatsUtils.catPacker')

-- [[ Setting options ]]
-- See `:help vim.o`
-- NOTE: You can change these options as you wish!
Expand Down
53 changes: 41 additions & 12 deletions lua/myLuaConf/LSPs/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
if not require('nixCatsUtils').isNixCats then
-- mason-lspconfig requires that these setup functions are called in this order
-- before setting up the servers.
require('mason').setup()
require('mason-lspconfig').setup()
end

local servers = {}
if nixCats('neonixdev') then
require('neodev').setup({})
Expand Down Expand Up @@ -28,12 +35,13 @@ if nixCats('neonixdev') then
telemetry = { enabled = false },
filetypes = { 'lua' },
}

servers.nixd = {}
if require('nixCatsUtils').isNixCats then servers.nixd = {}
else servers.rnix = {}
end
servers.nil_ls = {}

end
if nixCats('lspDebugMode') then
if not require('nixCatsUtils').isNixCats and nixCats('lspDebugMode') then
vim.lsp.set_log_level("debug")
end

Expand All @@ -56,13 +64,34 @@ end
-- servers.tsserver = {},
-- servers.html = { filetypes = { 'html', 'twig', 'hbs'} },

for server_name,_ in pairs(servers) do
require('lspconfig')[server_name].setup({
capabilities = require('myLuaConf.LSPs.caps-onattach').get_capabilities(),
on_attach = require('myLuaConf.LSPs.caps-onattach').on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
cmd = (servers[server_name] or {}).cmd,
root_pattern = (servers[server_name] or {}).root_pattern,
})

if not require('nixCatsUtils').isNixCats then
-- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig'

mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}

mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = require('myLuaConf.LSPs.caps-onattach').get_capabilities(),
on_attach = require('myLuaConf.LSPs.caps-onattach').on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end,
}
else
for server_name,_ in pairs(servers) do
require('lspconfig')[server_name].setup({
capabilities = require('myLuaConf.LSPs.caps-onattach').get_capabilities(),
on_attach = require('myLuaConf.LSPs.caps-onattach').on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
cmd = (servers[server_name] or {}).cmd,
root_pattern = (servers[server_name] or {}).root_pattern,
})
end
end
8 changes: 6 additions & 2 deletions lua/myLuaConf/plugins/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
vim.cmd.colorscheme(require('nixCats').get('colorscheme'))
local colorschemeName = nixCats('colorscheme')
if require('nixCatsUtils').isNixCats then
colorschemeName = 'onedark'
end
vim.cmd.colorscheme(colorschemeName)

require('myLuaConf.plugins.telescope')

Expand All @@ -25,7 +29,7 @@ require('fidget').setup()
require('lualine').setup({
options = {
icons_enabled = false,
theme = nixCats('colorscheme'),
theme = colorschemeName,
component_separators = '|',
section_separators = '',
},
Expand Down
117 changes: 117 additions & 0 deletions lua/nixCatsUtils/catPacker.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

-- first you should go ahead and install your dependencies
-- you arent using nix if you are using this.
-- this means you will have to install some stuff manually.

-- so, you will need cmake, gcc, npm, nodejs,
-- ripgrep, fd, <curl or wget>, and git,
-- you will also need rustup and to run rustup toolchain install stable

-- now you see why nix is so great. You dont have to do that every time.

-- so, now for the stuff we can still auto install without nix:
-- first check if we should be loading pckr:
if not require('nixCatsUtils').isNixCats then
-- you can use this same method
-- if you want to install via mason when not in nix
-- or just, anything you want to do only when not using nix

local function bootstrap_pckr()
local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim"

if not vim.loop.fs_stat(pckr_path) then
vim.fn.system({
'git',
'clone',
"--filter=blob:none",
'https://github.com/lewis6991/pckr.nvim',
pckr_path
})
end

vim.opt.rtp:prepend(pckr_path)
end

bootstrap_pckr()

-- ### DONT USE CONFIG VARIABLE ###
-- unless you are ok with that instruction
-- not being ran when used via nix,
-- this file will not be ran when using nix

require('pckr').add{

{ 'joshdick/onedark.vim', },
{ 'nvim-tree/nvim-web-devicons', },

{ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate',
requires = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
},
{'nvim-telescope/telescope.nvim',
requires = {
'nvim-lua/plenary.nvim',
{ 'nvim-telescope/telescope-fzf-native.nvim', run = 'which make && make', }
},
},

{ 'neovim/nvim-lspconfig',
requires = {
{ 'williamboman/mason.nvim', },
{ 'williamboman/mason-lspconfig.nvim', },
{ 'j-hui/fidget.nvim', },
{ 'folke/neodev.nvim', },
{ 'folke/neoconf.nvim', },
},
},

{ 'hrsh7th/nvim-cmp',
requires = {
{ 'onsails/lspkind.nvim', },
{ 'L3MON4D3/LuaSnip', },
{ 'saadparwaiz1/cmp_luasnip', },
{ 'hrsh7th/cmp-nvim-lsp', },
{ 'hrsh7th/cmp-nvim-lua', },
{ 'hrsh7th/cmp-nvim-lsp-signature-help', },
{ 'hrsh7th/cmp-path', },
{ 'rafamadriz/friendly-snippets', },
{ 'hrsh7th/cmp-buffer', },
{ 'hrsh7th/cmp-cmdline', },
{ 'dmitmel/cmp-cmdline-history', },
},
},

{ 'mfussenegger/nvim-dap',
requires = {
{ 'rcarriga/nvim-dap-ui', },
{ 'theHamsta/nvim-dap-virtual-text', },
{ 'jay-babu/mason-nvim-dap.nvim', },
},
},

{ 'm-demare/hlargs.nvim', },
{ 'mbbill/undotree', },
{ 'tpope/vim-fugitive', },
{ 'tpope/vim-rhubarb', },
{ 'tpope/vim-sleuth', },
{ 'folke/which-key.nvim', },
{ 'lewis6991/gitsigns.nvim', },
{ 'nvim-lualine/lualine.nvim', },
{ 'lukas-reineke/indent-blankline.nvim', },
{ 'numToStr/Comment.nvim', },
{ 'kylechui/nvim-surround',
requires = { 'tpope/vim-repeat', },
},
{
"iamcco/markdown-preview.nvim",
run = function() vim.fn["mkdp#util#install"]() end,
},

-- { "iamcco/markdown-preview.nvim", run = "cd app && npm install", setup = function() vim.g.mkdp_filetypes = { "markdown" } end, ft = { "markdown" }, },

-- all the rest of the setup will be done within the normal scheme, thus working regardless of what method loads the plugins.
-- only stuff pertaining to downloading should be added to pckr.

}
end
20 changes: 20 additions & 0 deletions lua/nixCatsUtils/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local M = {}

M.isNixCats, _ = pcall(function() require("nixCats") end)

function M.setup(v)
if not M.isNixCats then
local nixCats_pckr_default
if type(v) == "table" and v.default_cat_value ~= nil then
nixCats_pckr_default = v.default_cat_value
else
nixCats_pckr_default = true
end
package.loaded.nixCats = nil
-- if not in nix, just make it return a boolean
require('_G').nixCats = function(_) return nixCats_pckr_default end
end
end


return M
Loading

0 comments on commit ad349a6

Please sign in to comment.