From cdb627ede815782e6ec9203174321383e119fc49 Mon Sep 17 00:00:00 2001 From: Malte Brandy Date: Sat, 14 Sep 2019 14:00:41 +0200 Subject: [PATCH] Setup coc+ghcide --- cachix.nix | 7 ++- cachix/all-hies.nix | 8 --- cachix/hercules-ci.nix | 12 ++++ home/default.nix | 71 ++++++++++++++--------- lib/default.nix | 2 +- nix/sources.json | 12 ++++ pkgs/default.nix | 21 +++++-- pkgs/nvim/default.nix | 6 +- pkgs/nvim/vimrc | 129 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 224 insertions(+), 44 deletions(-) delete mode 100644 cachix/all-hies.nix create mode 100644 cachix/hercules-ci.nix diff --git a/cachix.nix b/cachix.nix index 64734c30..cce90a32 100644 --- a/cachix.nix +++ b/cachix.nix @@ -1,3 +1,4 @@ + # WARN: this file will get overwritten by $ cachix use { pkgs, lib, ... }: @@ -5,9 +6,9 @@ let folder = ./cachix; toImport = name: value: folder + ("/" + name); filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key; - imports = lib.mapAttrsToList toImport - (lib.filterAttrs filterCaches (builtins.readDir folder)); + imports = lib.mapAttrsToList toImport (lib.filterAttrs filterCaches (builtins.readDir folder)); in { inherit imports; - nix.binaryCaches = [ "https://cache.nixos.org/" ]; + nix.binaryCaches = ["https://cache.nixos.org/"]; } + \ No newline at end of file diff --git a/cachix/all-hies.nix b/cachix/all-hies.nix deleted file mode 100644 index 6f92a68b..00000000 --- a/cachix/all-hies.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ - nix = { - binaryCaches = [ "https://all-hies.cachix.org" ]; - binaryCachePublicKeys = - [ "all-hies.cachix.org-1:JjrzAOEUsD9ZMt8fdFbzo3jNAyEWlPAwdVuHw4RD43k=" ]; - trustedUsers = [ "root" "maralorn" ]; - }; -} diff --git a/cachix/hercules-ci.nix b/cachix/hercules-ci.nix new file mode 100644 index 00000000..a925aa37 --- /dev/null +++ b/cachix/hercules-ci.nix @@ -0,0 +1,12 @@ + +{ + nix = { + binaryCaches = [ + "https://hercules-ci.cachix.org" + ]; + binaryCachePublicKeys = [ + "hercules-ci.cachix.org-1:ZZeDl9Va+xe9j+KqdzoBZMFJHVQ42Uu/c/1/KMC5Lw0=" + ]; + }; +} + \ No newline at end of file diff --git a/home/default.nix b/home/default.nix index 2b27e756..5c798b24 100644 --- a/home/default.nix +++ b/home/default.nix @@ -147,39 +147,56 @@ in { home = { packages = builtins.attrValues my-pkgs.home-pkgs; sessionVariables = { + GITSTATUS_DAEMON = "${my-pkgs.gitstatus}/bin/gitstatusd"; PATH = "$HOME/.cargo/bin:/etc/profiles/per-user/${config.home.username}/bin:$HOME/.nix-profile/bin:$PATH"; - BROWSER = "${pkgs.firefox}/bin/firefox"; - EDITOR = "${pkgs.neovim}/bin/nvim"; - TERMINAL = config.m-0.terminal; - EMAIL = me.mail; - SUDO_ASKPASS = let - print-pw = pkgs.writeShellScriptBin "print-pw" + BROWSER = "${pkgs.firefox}/bin/firefox"; + EDITOR = "${pkgs.neovim}/bin/nvim"; + TERMINAL = config.m-0.terminal; + EMAIL = me.mail; + SUDO_ASKPASS = let + print-pw = pkgs.writeShellScriptBin "print-pw" "pass show eu/m-0/${config.m-0.hostName}/user/${config.home.username}"; - in "${print-pw}/bin/print-pw"; + in "${print-pw}/bin/print-pw"; + }; + file.".config/nvim/coc-settings.json".text = builtins.toJSON { + languageserver = { + haskell = { + command = "ghcide"; + args = [ "--lsp" ]; + rootPatterns = [ + ".stack.yaml" + ".hie-bios" + "BUILD.bazel" + "cabal.config" + "package.yaml" + ]; + filetypes = [ "hs" "lhs" "haskell" ]; + }; }; }; - fonts.fontconfig.enableProfileFonts = true; + }; + fonts.fontconfig.enableProfileFonts = true; - systemd.user = { - startServices = true; - services.lorri-daemon = { - Unit = { Description = "Run lorri daemon"; }; - Service = { - Environment = - "RUST_BACKTRACE=1 PATH=${pkgs.nix}/bin:${pkgs.coreutils}/bin"; - ExecStart = "${lorri}/bin/lorri daemon"; - }; - }; + systemd.user = { + startServices = true; + services.lorri-daemon = { + Unit = { Description = "Run lorri daemon"; }; + Service = { + Environment = + "RUST_BACKTRACE=1 PATH=${pkgs.nix}/bin:${pkgs.coreutils}/bin"; + ExecStart = "${lorri}/bin/lorri daemon"; }; + }; + }; - services = { - gpg-agent = { - enable = true; - defaultCacheTtl = 31536000; # 1year - maxCacheTtl = 31536000; # 1year - }; - }; + services = { + gpg-agent = { + enable = true; + defaultCacheTtl = 31536000; # 1year + maxCacheTtl = 31536000; # 1year + }; + }; - xdg.enable = true; - } + xdg.enable = true; +} diff --git a/lib/default.nix b/lib/default.nix index d3728cef..1874e2f2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -9,7 +9,7 @@ rec { }); shh = unBreak unstable.haskellPackages.shh; ghc = unstable.ghc.withPackages - (p: [ (unBreak p.shh) p.brittany p.hlint p.ghcid ]); + (p: [ (unBreak p.shh) p.brittany p.hlint p.ghcid p.cabal-install ]); haskellList = list: ''["${builtins.concatStringsSep ''", "'' list}"]''; writeHaskellScript = { name ? "haskell-script", bins ? [ pkgs.coreutils ] , libraries ? [ ], imports ? [ ] }: diff --git a/nix/sources.json b/nix/sources.json index f2b23655..11304435 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,6 +11,18 @@ "url": "https://github.com/cachix/cachix/archive/5c7272351c4e87adabfb8a31e5b9c1db2980abf3.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, + "ghcide": { + "branch": "master", + "description": "Nix installation for ghcide", + "homepage": "https://github.com/digital-asset/ghcide", + "owner": "hercules-ci", + "repo": "ghcide-nix", + "rev": "6780371c68756cb103ae5b513b2d9f244581b03b", + "sha256": "05jamp6hajkymvqs1s6ydy0x6dy84qykv27j5y6pyzyrfry2ih9s", + "type": "tarball", + "url": "https://github.com/hercules-ci/ghcide-nix/archive/6780371c68756cb103ae5b513b2d9f244581b03b.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, "home-manager": { "branch": "release-19.03", "description": "Manage a user environment using Nix", diff --git a/pkgs/default.nix b/pkgs/default.nix index 5bd236b8..3cdbb4d1 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -2,8 +2,21 @@ let my-lib = import ../lib; inherit (my-lib) pkgs unstable sources writeHaskellScript gcRetentionDays; in rec { + gitstatus = pkgs.callPackage ./powerlevel10k/gitstatus.nix { + libgit2 = pkgs.libgit2.overrideAttrs (attrs: { + src = pkgs.fetchFromGitHub { + owner = "romkatv"; + repo = "libgit2"; + rev = "a546b232b23814de9c561fc750791363a5ed347e"; + sha256 = "1xx782qa36f5gfjflw64r383g5gh7wgkvxk5q4w0rg8c0xwa3hk6"; + }; + }); + }; + zsh-powerlevel10k = + pkgs.callPackage ./powerlevel10k/zsh-powerlevel10k.nix { }; + ghcide = (import sources.ghcide { }).ghcide-ghc865; tasktree = pkgs.callPackage ./tasktree { }; - neovim = pkgs.neovim.override { + neovim = unstable.neovim.override { vimAlias = true; withPython3 = true; }; @@ -11,7 +24,7 @@ in rec { src = sources.lorri; pkgs = unstable; }; - home-neovim = (import ./nvim) neovim; + home-neovim = (import ./nvim) unstable.neovim; niv = (import sources.niv { }).niv; # pkgs assumed to be present on a non nixos host @@ -153,9 +166,9 @@ in rec { home-pkgs = { nixfmt = import sources.nixfmt { }; inherit (pkgs.pythonPackages) yapf jsbeautifier; - inherit (pkgs) ncmpcpp shfmt htmlTidy astyle; + inherit (pkgs) ncmpcpp shfmt htmlTidy astyle nodejs; inherit (my-lib) ghc; - inherit home-neovim; + inherit home-neovim ghcide; }; accounting-pkgs = { jali = pkgs.callPackage ./jali { }; diff --git a/pkgs/nvim/default.nix b/pkgs/nvim/default.nix index c2e87b65..985b9742 100644 --- a/pkgs/nvim/default.nix +++ b/pkgs/nvim/default.nix @@ -8,7 +8,11 @@ n.override { start = builtins.attrValues { inherit ((import { }).vimPlugins) vim-nix vimtex airline rust-vim fugitive vim-trailing-whitespace - vim-pandoc vim-pandoc-syntax haskell-vim vim-autoformat vim-ledger; + vim-airline-themes vim-pandoc vim-pandoc-syntax haskell-vim + vim-autoformat vim-ledger; + inherit ((import { }).vimPlugins) + coc-nvim coc-python coc-rls coc-yaml coc-vimtex coc-css coc-json + coc-html coc-git; }; }; }; diff --git a/pkgs/nvim/vimrc b/pkgs/nvim/vimrc index f2b4cb84..2bc18e40 100644 --- a/pkgs/nvim/vimrc +++ b/pkgs/nvim/vimrc @@ -51,3 +51,132 @@ let g:formatters_nix = ['my_nix'] au BufWrite * :Autoformat let g:autoformat_autoindent = 0 let g:autoformat_retab = 0 + +" if hidden is not set, TextEdit might fail. +set hidden + +" Some servers have issues with backup files, see #649 +set nobackup +set nowritebackup + +" Better display for messages +set cmdheight=2 + +" You will have bad experience for diagnostic messages when it's default 4000. +set updatetime=300 + +" don't give |ins-completion-menu| messages. +set shortmess+=c + +" always show signcolumns +set signcolumn=yes + +" Use tab for trigger completion with characters ahead and navigate. +" Use command ':verbose imap ' to make sure tab is not mapped by other plugin. +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +" Use to trigger completion. +inoremap coc#refresh() + +" Use to confirm completion, `u` means break undo chain at current position. +" Coc only does snippet and additional edit on confirm. +inoremap pumvisible() ? "\" : "\u\" + +" Use `[g` and `]g` to navigate diagnostics +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +" Remap keys for gotos +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 show_documentation() + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction + +" Highlight symbol under cursor on CursorHold +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Remap for rename current word +nmap rn (coc-rename) + +" Remap for format selected region +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 + +" Remap for do codeAction of selected region, ex: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap for do codeAction of current line +nmap ac (coc-codeaction) +" Fix autofix problem of current line +nmap qf (coc-fix-current) + +" Create mappings for function text object, requires document symbols feature of languageserver. + +xmap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap if (coc-funcobj-i) +omap af (coc-funcobj-a) + +" Use for select selections ranges, needs server support, like: coc-tsserver, coc-python +nmap (coc-range-select) +xmap (coc-range-select) +xmap (coc-range-select-backword) + +" Use `:Format` to format current buffer +command! -nargs=0 Format :call CocAction('format') + +" Use `:Fold` to fold current buffer +command! -nargs=? Fold :call CocAction('fold', ) + +" use `:OR` for organize import of current buffer +command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') + +" Add status line support, for integration with other plugin, checkout `:h coc-status` +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} + +" Using 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