diff --git a/flake.lock b/flake.lock index ace26e2..2ca12ac 100644 --- a/flake.lock +++ b/flake.lock @@ -113,11 +113,11 @@ ] }, "locked": { - "lastModified": 1683813037, - "narHash": "sha256-UMEXfYLVcI4p0JUHQD07UWglqj7XUw6xhdJqqNRu4KY=", + "lastModified": 1687204608, + "narHash": "sha256-rZ0e0iAIQM7vlsMd2/pcGfymZzNBRawObFgqIpxE94c=", "owner": "nix-community", "repo": "home-manager", - "rev": "d97e8f8861a7ad3cb2f72adf5b2cd14ab302c593", + "rev": "f06a43dca05fb7f1aa44742bf861d9c827b45122", "type": "github" }, "original": { @@ -177,11 +177,11 @@ }, "nixunstable": { "locked": { - "lastModified": 1686020360, - "narHash": "sha256-Wee7lIlZ6DIZHHLiNxU5KdYZQl0iprENXa/czzI6Cj4=", + "lastModified": 1686960236, + "narHash": "sha256-AYCC9rXNLpUWzD9hm+askOfpliLEC9kwAo7ITJc4HIw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4729ffac6fd12e26e5a8de002781ffc49b0e94b7", + "rev": "04af42f3b31dba0ef742d254456dc4c14eedac86", "type": "github" }, "original": { diff --git a/home/init.lua b/home/init.lua new file mode 100644 index 0000000..a5477aa --- /dev/null +++ b/home/init.lua @@ -0,0 +1,242 @@ +-- Core vim settings +vim.opt.background="dark" +vim.opt.copyindent=true +vim.opt.expandtab=false +vim.opt.hidden=true +vim.opt.ignorecase=true +vim.opt.mouse="a" +vim.opt.number=true +vim.opt.relativenumber=true +vim.opt.shiftwidth=4 +vim.opt.smartcase=true +vim.opt.tabstop=4 +vim.opt.preserveindent=true +vim.opt.softtabstop=0 +vim.opt.wrap=false +vim.opt.showcmd=true +vim.opt.cursorline=true +vim.opt.lazyredraw=true +vim.opt.showmatch=true +vim.opt.hlsearch=true +vim.opt.backup=false +vim.opt.writebackup=false +vim.opt.signcolumn="yes" +vim.opt.listchars="tab:→ ,extends:→,precedes:←,trail:·,eol:¬" +vim.opt.list=true + +-- dunno about these? +-- syntax enable -- on by default in neovim +vim.cmd [[colorscheme gruvbox]] + +-- ====================================================================== +-- +-- nvim-cmp configuration +-- +-- ====================================================================== +--local cmp = require'cmp' + +--cmp.setup({ + --snippet = { + --expand = function(args) + --vim.fn["vsnip#anonymous"](args.body) + --end, + --}, + --window = { + ---- completion = cmp.config.window.bordered(), + ---- documentation = cmp.config.window.bordered(), + --}, + --mapping = cmp.mapping.preset.insert({ + --[''] = cmp.mapping.scroll_docs(-4), + --[''] = cmp.mapping.scroll_docs(4), + --[''] = cmp.mapping.complete(), + --[''] = cmp.mapping.abort(), + --[''] = cmp.mapping.confirm({ select = true }), + --}), + --sources = cmp.config.sources({ + --{ name = 'nvim_lspconfig' }, + --{ name = 'vsnip' }, + --},{ + --{ name = 'buffer' } + --}) +--}) +-- +--cmp.setup.filetype('gitcommit', { + --sources = cmp.config.sources({ + --{ name = 'git' } + --},{ + --{ name = 'buffer' } + --}) +--}) +-- +--cmp.setup.cmdline({ '/', '?' }, { + --mapping = cmp.mapping.preset.cmdline(), + --sources = { { name = 'buffer' } } +--}) +-- +--cmp.setup.cmdline(':', { + --mapping = cmp.mapping.preset.cmdline(), + --sources = cmp.config.sources({ + --{ name = 'path' } + --},{ + --{ name = 'cmdline' } + --}) +--}) +-- +--local capabilities = require('cmp_nvim_lsp').default_capabilities() +--local lspconfig = require('lspconfig') +---- Add each LSP that you have configured here +----require('lspconfig')[''].setup { +---- capabilities = capabilities +----} +----lspconfig.pyright.setup { capabilities = capabilities } +--lspconfig.ansiblels.setup { capabilities = capabilities } +--lspconfig.jedi_language_server.setup { capabilities = capabilities } + +-- ====================================================================== +-- +-- automatic commands +-- +-- ====================================================================== +local api = vim.api + +-- Highlights bad whitespace +--api.nvim_create_autocmd("ColorScheme", { command = "highlight ExtraWhitespace ctermbg=red guibg=red" }) +--api.nvim_create_autocmd("BufWinEnter", { command = "match ExtraWhitespace /\s\+$/" }) +--api.nvim_create_autocmd("InsertEnter", { command = "match ExtraWhitespace /\s\+\%#\@ \be +-- imap \be +vim.keymap.set(all, "", "\\be") +-- map :NERDTreeToggle +vim.keymap.set(all, "", ":NERDTreeToggle") +-- Which file list to pop up +-- silent !git rev-parse --is-inside-work-tree +-- if v:shell_error == 0 +-- map :GFiles --cached --others --exclude-standard +-- map :GFiles? +--else +-- map :Files +--endif +if api.nvim_command_output("!git rev-parse --is-inside-work-tree") == true then + vim.keymap.set(all, "", ":GFiles --cached --others --exclude-standard") + vim.keymap.set(all, "", ":GFiles?") +else + vim.keymap.set(all, "", ":Files") +end +-- map :Files +vim.keymap.set(all, "", ":Files") + +-- Allows navigating splits +-- map j +-- map k +-- map h +-- map l +vim.keymap.set(all, "", "j") +vim.keymap.set(all, "", "k") +vim.keymap.set(all, "", "h") +vim.keymap.set(all, "", "l") + +-- ============================================================================ +-- User functions to just make life easier +-- ============================================================================ +-- Creates the directory for a file if it doesn't already exist. +bufWritePres = vim.cmd [[ + function! s:MkNonExDir(file, buf) + if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/' + let dir=fnamemodify(a:file, ':h') + if !isdirectory(dir) + call mkdir(dir, 'p') + endif + endif + endfunction + augroup BWCCreateDir + autocmd! + autocmd BufWritePre * :call s:MkNonExDir(expand(''), +expand('')) + augroup END +]] + +-- Return indent (all whitespace at start of a line), converted from +-- tabs to spaces if what = 1, or from spaces to tabs otherwise. +-- When converting to tabs, result has no redundant spaces. +vim.cmd [[ +function! Indenting(indent, what, cols) + let spccol = repeat(' ', a:cols) + let result = substitute(a:indent, spccol, '\t', 'g') + let result = substitute(result, ' \+\ze\t', ''', 'g') + if a:what == 1 + let result = substitute(result, '\t', spccol, 'g') + endif + return result +endfunction +]] + +--Convert whitespace used for indenting (before first non-whitespace). +--what = 0 (convert spaces to tabs), or 1 (convert tabs to spaces). +--cols = string with number of columns per tab, or empty to use 'tabstop'. +--The cursor position is restored, but the cursor will be in a different +--column when the number of characters in the indent of the line is changed. +vim.cmd [[ +function! IndentConvert(line1, line2, what, cols) + let savepos = getpos('.') + let cols = empty(a:cols) ? &tabstop : a:cols + execute a:line1 . ',' . a:line2 . 's/^\s\+/\=Indenting(submatch(0), a:what, cols)/e' + call histdel('search', -1) + call setpos('.', savepos) +endfunction +command! -nargs=? -range=% Space2Tab call IndentConvert(,,0,) +command! -nargs=? -range=% Tab2Space call IndentConvert(,,1,) +command! -nargs=? -range=% RetabIndent call IndentConvert(,,&et,) +]] diff --git a/home/vim.nix b/home/vim.nix index e8da4cd..60a7e50 100644 --- a/home/vim.nix +++ b/home/vim.nix @@ -22,6 +22,11 @@ let }; in { + home.packages = with pkgs; [ + ansible-language-server + pyright + ]; + programs.neovim = { enable = true; viAlias = true; @@ -30,24 +35,17 @@ in plugins = with pkgs.vimPlugins; [ ansible-vim bufexplorer - coc-cmake - coc-css - coc-go - coc-highlight - coc-html - coc-java - coc-json - coc-lists - coc-markdownlint - coc-nvim - coc-pyright - coc-tslint - coc-vimtex - coc-yaml + + #cmp-nvim-lsp + #cmp-vsnip + #nvim-lspconfig + #nvim-cmp + context-vim direnv-vim fzf-vim nerdtree + nvim-notify vim-airline vim-gitgutter vim-flake8 @@ -58,6 +56,10 @@ in vim-xonsh gruvbox ]; - extraConfig = builtins.readFile ./vimrc; + #extraConfig = builtins.readFile ./vimrc; + extraLuaConfig = builtins.readFile ./init.lua; + coc = { + enable = true; + }; }; } diff --git a/home/vimrc b/home/vimrc index cd20046..075335a 100644 --- a/home/vimrc +++ b/home/vimrc @@ -29,153 +29,68 @@ set updatetime=300 set listchars=tab:→\ ,extends:→,precedes:←,trail:·,eol:¬ set list -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -""""""""""" coc.nnim configuration """"""""""""""""""""""""""""""""""""" -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" https://github.com/neoclide/coc.nvim -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: There's always complete item selected by default, you may want to enable -" no select by `"suggest.noselect": true` in your configuration file. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap - \ coc#pum#visible() ? coc#pum#next(1) : - \ CheckBackspace() ? "\" : - \ coc#refresh() -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" - -" Make to accept selected completion item or notify coc.nvim to format -" u breaks current undo, please make your own choice. -inoremap coc#pum#visible() ? coc#pum#confirm() - \: "\u\\=coc#on_enter()\" - -function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -if has('nvim') - inoremap coc#refresh() -else - inoremap coc#refresh() -endif - -" Use `[g` and `]g` to navigate diagnostics -" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window. -nnoremap K :call ShowDocumentation() - -function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor. -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Symbol renaming. -nmap rn (coc-rename) - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) - -augroup mygroup - autocmd! - " Setup formatexpr specified filetype(s). - autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') - " Update signature help on jump placeholder. - autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') -augroup end - -" Applying codeAction to the selected region. -" Example: `aap` for current paragraph -xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) - -" Remap keys for applying codeAction to the current buffer. -nmap ac (coc-codeaction) -" Apply AutoFix to problem on the current line. -nmap qf (coc-fix-current) - -" Run the Code Lens action on the current line. -nmap cl (coc-codelens-action) - -" Map function and class text objects -" NOTE: Requires 'textDocument.documentSymbol' support from the language server. -xmap if (coc-funcobj-i) -omap if (coc-funcobj-i) -xmap af (coc-funcobj-a) -omap af (coc-funcobj-a) -xmap ic (coc-classobj-i) -omap ic (coc-classobj-i) -xmap ac (coc-classobj-a) -omap ac (coc-classobj-a) - -" Remap and for scroll float windows/popups. -if has('nvim-0.4.0') || has('patch-8.2.0750') - nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" -endif - -" Use CTRL-S for selections ranges. -" Requires 'textDocument/selectionRange' support of language server. -nmap (coc-range-select) -xmap (coc-range-select) - -" Add `:Format` command to format current buffer. -command! -nargs=0 Format :call CocActionAsync('format') - -" Add `:Fold` command to fold current buffer. -command! -nargs=? Fold :call CocAction('fold', ) - -" Add `:OR` command for organize imports of the current buffer. -command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') - -" Add (Neo)Vim's native statusline support. -" NOTE: Please see `:h coc-status` for integrations with external plugins that -" provide custom statusline: lightline.vim, vim-airline. -set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} - -" Mappings for CoCList -" Show all diagnostics. -nnoremap a :CocList diagnostics -" Manage extensions. -nnoremap e :CocList extensions -" Show commands. -nnoremap c :CocList commands -" Find symbol of current document. -nnoremap o :CocList outline -" Search workspace symbols. -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list. -nnoremap p :CocListResume +" nvim-cmp configuration " -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -""""""""""" END coc.nnim configuration """"""""""""""""""""""""""""""""" -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +lua <'] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lspconfig' }, + { name = 'vsnip' }, + },{ + { name = 'buffer' } + }) + }) + + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' } + },{ + { name = 'buffer' } + }) + }) + + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { { name = 'buffer' } } + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + },{ + { name = 'cmdline' } + }) + }) + + local capabilities = require('cmp_nvim_lsp').default_capabilities() + local lspconfig = require('lspconfig') + -- Add each LSP that you have configured here + --require('lspconfig')[''].setup { + -- capabilities = capabilities + --} + --lspconfig.pyright.setup { capabilities = capabilities } + lspconfig.ansiblels.setup { capabilities = capabilities } + lspconfig.jedi_language_server.setup { capabilities = capabilities } +EOF " Set filetype to the way I want it let g:nix_recommended_style = 0 @@ -203,6 +118,7 @@ let g:diffget_upstream_map = 'gu' " Key mappings map \be +imap \be map :NERDTreeToggle silent !git rev-parse --is-inside-work-tree if v:shell_error == 0 diff --git a/overlays/default.nix b/overlays/default.nix index d46b68d..a85ef62 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -10,6 +10,7 @@ let flake8 ipython jedi + jedi-language-server mypy pylint pyyaml @@ -48,14 +49,21 @@ let }); in rec { - #python3 = final.unstable.python3; gregpy = myPython; + ## Testing adding python packages in the correct manner + pythonPackagesExtensions = (prev.pythonPackagesExtensions or []) ++ [ + (python-final: python-prev: { + django-rapyd-modernauth = python-final.callPackage ./django-rapyd-modernauth.nix {}; + xonsh-apipenv = cp ./xonsh-apipenv.nix {}; + xonsh-direnv = cp ./xonsh-direnv.nix {}; + }) + ]; + my-py-addons = rec { copier = cp ./copier.nix { inherit iteration-utilities jinja2-ansible-filters - pydantic pyyaml-include ; }; @@ -63,7 +71,6 @@ in rec { jinja2-ansible-filters = cp ./jinja2-ansible-filters.nix {}; pydantic = cp ./pydantic.nix {}; pyyaml-include = cp ./pyyaml-include.nix {}; - xonsh-direnv = cp ./xonsh-direnv.nix {}; }; #fcitx-engines = if ! prev.stdenv.isDarwin then prev.fcitx5 else prev.fcitx-engines; @@ -79,7 +86,10 @@ in rec { xonsh = prev.xonsh.overridePythonAttrs (old: rec{ python3 = final.gregpy; - propagatedBuildInputs = old.propagatedBuildInputs ++ [ my-py-addons.xonsh-direnv ]; + propagatedBuildInputs = with final.gregpy.pkgs; old.propagatedBuildInputs ++ [ + xonsh-apipenv + xonsh-direnv + ]; }); bitwarden = macOver ./mac/bitwarden.nix "bitwarden"; diff --git a/overlays/django-rapyd-modernauth.nix b/overlays/django-rapyd-modernauth.nix new file mode 100644 index 0000000..dd637b2 --- /dev/null +++ b/overlays/django-rapyd-modernauth.nix @@ -0,0 +1,45 @@ +{ lib, buildPythonPackage, fetchPypi, pkgs}: + +let + pydeps = pypkgs: with pypkgs; [ + click + django + python-dotenv + pytz + setuptools + sqlparse + zipp + ]; +in buildPythonPackage rec { + pname = "django-rapyd-modernauth"; + version = "0.0.4"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-kDZjI32LcKsmLI38ruINKOUfi6lWTIqXF5qIQHi0LeQ="; + }; + + meta = with lib; { + description = "A Django application that provides a custom User model where the username is the email address."; + homepage = "https://github.com/karthicraghupathi/django_rapyd_modernauth"; + license = licenses.afl20; + maintainers = []; + }; + + doCheck = false; + + buildInputs = with pkgs; [ + #(python3.withPackages pydeps) + click + django + python-dotenv + pytz + setuptools + sqlparse + zipp + ]; + + nativeBuildInputs = with pkgs; [ + #(python3.withPackages pydeps) + ]; +} diff --git a/overlays/packages.nix b/overlays/packages.nix index 6ec6270..c98d5cb 100644 --- a/overlays/packages.nix +++ b/overlays/packages.nix @@ -14,6 +14,10 @@ flake-utils.lib.eachDefaultSystemMap (system: brew = pkgs.callPackage ./homebrew.nix {}; + django-rapyd-modernauth = pkgs.callPackage ./django-rapyd-modernauth.nix { + buildPythonPackage = pkgs.python3.pkgs.buildPythonPackage; + }; + xonsh-direnv = pkgs.callPackage ./xonsh-direnv.nix { buildPythonPackage = pkgs.python3.pkgs.buildPythonPackage; fetchPypi = pkgs.python.pkgs.fetchPypi; diff --git a/overlays/pydantic.nix b/overlays/pydantic.nix deleted file mode 100644 index 9e97e0b..0000000 --- a/overlays/pydantic.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ lib, buildPythonPackage, fetchPypi, pkgs, -typing-extensions -}: - -let - pydeps = [ - typing-extensions - ]; -in buildPythonPackage rec { - pname = "pydantic"; - version = "1.10.2"; - - src = fetchPypi { - inherit pname version; - sha256 = "sha256-kbjiGIUu9gB8K5jNhhYBxqCfGqMru7dPq1scM9Sh5BA="; - }; - - meta = with lib; { - description = "Data validation and settings management using Python type hints."; - homepage = "https://github.com/pydantic/pydantic"; - license = licenses.mit; - maintainers = []; - }; - - doCheck = false; - - propagatedBuildInputs = pydeps; - - buildInputs = []; - - nativeBuildInputs = with pkgs; [ - ]; -} diff --git a/overlays/xonsh-apipenv.nix b/overlays/xonsh-apipenv.nix new file mode 100644 index 0000000..0b5e2c0 --- /dev/null +++ b/overlays/xonsh-apipenv.nix @@ -0,0 +1,29 @@ +{ lib, buildPythonPackage, fetchFromGitHub, pkgs}: + +buildPythonPackage rec { + pname = "xonsh-apipenv"; + version = "0.4.0"; + + src = fetchFromGitHub { + owner = "deeuu"; + repo = "xontrib-apipenv"; + rev = "0.4.0"; + sha256 = "sha256-uFn3kF7P4wykd72XkQx6cPWLhBOh2SDQBcI3Idc2rFM="; + }; + + meta = with lib; { + description = "Auto pipenv support for Xonsh"; + homepage = "https://github.com/deeuu/xontrib-apipenv"; + license = licenses.mit; + maintainers = []; + }; + + doCheck = false; + + buildInputs = with pkgs; [ + pipenv + ]; + + nativeBuildInputs = [ + ]; +}