From 185d017d327cace733feee704a0588590114e17a Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Fri, 21 May 2021 19:29:37 +0200 Subject: [PATCH] asdf --- nixpkgs/.config/nixpkgs/modules/base.nix | 3 +- nixpkgs/.config/nixpkgs/modules/desktop.nix | 1 + nixpkgs/.config/nixpkgs/modules/direnvrc | 151 ++++++++++++++++++++ nvim/.config/nvim/fnl/dots/plugins.fnl | 14 +- nvim/.config/nvim/fnl/dots/plugins/lsp.fnl | 83 ++++++++++- profile/.profile | 1 + xmonad/.xmonad/lib/Config.hs | 2 + 7 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 nixpkgs/.config/nixpkgs/modules/direnvrc diff --git a/nixpkgs/.config/nixpkgs/modules/base.nix b/nixpkgs/.config/nixpkgs/modules/base.nix index 48aa25b..5f0236b 100644 --- a/nixpkgs/.config/nixpkgs/modules/base.nix +++ b/nixpkgs/.config/nixpkgs/modules/base.nix @@ -125,7 +125,8 @@ in enable = true; enableFishIntegration = cfg.enableFish; enableZshIntegration = cfg.enableZsh; - enableNixDirenvIntegration = true; + # enableNixDirenvIntegration = true; + stdlib = (builtins.readFile ./direnvrc); }; }; diff --git a/nixpkgs/.config/nixpkgs/modules/desktop.nix b/nixpkgs/.config/nixpkgs/modules/desktop.nix index bf2a520..7c83a30 100644 --- a/nixpkgs/.config/nixpkgs/modules/desktop.nix +++ b/nixpkgs/.config/nixpkgs/modules/desktop.nix @@ -27,6 +27,7 @@ in #hyper-haskell font-manager + haskellPackages.arbtt sqlite-web #flameshot diff --git a/nixpkgs/.config/nixpkgs/modules/direnvrc b/nixpkgs/.config/nixpkgs/modules/direnvrc new file mode 100644 index 0000000..ee5fe03 --- /dev/null +++ b/nixpkgs/.config/nixpkgs/modules/direnvrc @@ -0,0 +1,151 @@ +# Usage: use_nix [...] +# +# Load environment variables from `nix-shell`. +# If you have a `default.nix` or `shell.nix` one of these will be used and +# the derived environment will be stored at ./.direnv/env- +# and symlink to it will be created at ./.direnv/default. +# Dependencies are added to the GC roots, such that the environment remains persistent. +# +# The resulting environment is cached for better performance. +# +# To trigger switch to a different environment: +# `rm -f .direnv/default` +# +# To derive a new environment: +# `rm -rf .direnv/env-$(md5sum {shell,default}.nix 2> /dev/null | cut -c -32)` +# +# To remove cache: +# `rm -f .direnv/dump-*` +# +# To remove all environments: +# `rm -rf .direnv/env-*` +# +# To remove only old environments: +# `find .direnv -name 'env-*' -and -not -name `readlink .direnv/default` -exec rm -rf {} +` +# + +set -eo pipefail + +use_nix() { + # define all local variables + local shell f env_hash dir default wd drv dump path_backup + local files_to_watch=() + + declare opt + declare OPTARG + declare OPTIND + + while getopts ":s:w:" opt; do + case "${opt}" in + s) + shell="${OPTARG}" + files_to_watch=("${files_to_watch[@]}" "${shell}") + ;; + w) + files_to_watch=("${files_to_watch[@]}" "${OPTARG}") + ;; + :) + >&2 echo "Invalid option: $OPTARG requires an argument" + ;; + \?) + >&2 echo "Invalid option: $OPTARG" + exit 1 + ;; + esac + done + shift $((OPTIND -1)) + + if [[ -z "${shell}" ]]; then + >&2 echo "ERR: no shell was given" + exit 1 + fi + + for f in "${files_to_watch[@]}"; do + if ! [[ -f "${f}" ]]; then + >&2 echo "cannot watch file ${f} because it does not exist" + exit 1 + fi + done + + # compute the hash of all the files that makes up the development environment + env_hash="$(hashContents "${files_to_watch[@]}")" + + dir="$(direnv_layout_dir)" + default="${dir}/default" + if [[ ! -L "${default}" ]] || [[ ! -d $(readlink "${default}") ]]; then + wd="${dir}/env-${env_hash}" + mkdir -p "${wd}" + + drv="${wd}/env.drv" + if [[ ! -f "${drv}" ]]; then + log_status "use nix: deriving new environment" + IN_NIX_SHELL=1 nix-instantiate --add-root "${drv}" --indirect "${shell}" > /dev/null + nix-store -r $(nix-store --query --references "${drv}") --add-root "${wd}/dep" --indirect > /dev/null + fi + + rm -f "${default}" + ln -s $(basename "${wd}") "${default}" + fi + + drv=$(readlink "${default}/env.drv") + dump="${dir}/dump-$(hashFile ".envrc")-$(hashFile ${drv})" + + if [[ ! -f "${dump}" ]] || [[ "${XDG_CONFIG_DIR}/direnv/direnvrc" -nt "${dump}" ]]; then + log_status "use nix: updating cache" + + old=$(find "${dir}" -name 'dump-*') + nix-shell --pure "${drv}" --show-trace --run "$(join_args "$direnv" dump bash)" > "${dump}" + rm -f ${old} + fi + + # evaluate the dump created by nix-shell earlier, but have to merge the PATH + # with the current PATH + # NOTE: we eval the dump here as opposed to direnv_load it because we don't + # want to persist environment variables coming from the shell at the time of + # the dump. See https://github.com/direnv/direnv/issues/405 for context. + path_backup="${PATH}" + eval $(cat "${dump}") + export PATH="${PATH}:${path_backup}" + + for f in "${files_to_watch[@]}"; do + watch_file "${f}" + done +} + +hashContents() { + if has md5sum; then + cat "${@}" | md5sum | cut -c -32 + elif has md5; then + cat "${@}" | md5 -q + fi +} + +hashFile() { + if has md5sum; then + md5sum "${@}" | cut -c -32 + elif has md5; then + md5 -q "${@}" + fi +} + +fail() { + log_error "${@}" + exit 1 +} + +validateVersion() { + local version="$("${direnv}" version)" + local major="$(echo "${version}" | cut -d. -f1)" + local minor="$(echo "${version}" | cut -d. -f2)" + local patch="$(echo "${version}" | cut -d. -f3)" + + if [[ "${major}" -gt 2 ]]; then return 0; fi + if [[ "${major}" -eq 2 ]] && [[ "${minor}" -gt 18 ]]; then return 0; fi + if [[ "${major}" -eq 2 ]] && [[ "${minor}" -eq 18 ]] && [[ "${patch}" -ge 2 ]]; then return 0; fi + return 1 +} + +if ! validateVersion; then + echo "This .envrc requires direnv version 2.18.2 or above." + exit 1 +fi diff --git a/nvim/.config/nvim/fnl/dots/plugins.fnl b/nvim/.config/nvim/fnl/dots/plugins.fnl index 047f066..ab8fc46 100644 --- a/nvim/.config/nvim/fnl/dots/plugins.fnl +++ b/nvim/.config/nvim/fnl/dots/plugins.fnl @@ -5,6 +5,7 @@ "/home/leon/coding/projects/nvim-gehzu" {} :elkowar/kmonad.vim {} + :lifepillar/vim-gruvbox8 {:opt false :config #(do (set vim.g.gruvbox_italics 0) (set vim.g.gruvbox_italicise_strings 0) @@ -29,6 +30,12 @@ ;:romgrk/nvim-treesitter-context {} + ;:code-biscuits/nvim-biscuits {:requires [:nvim-treesitter/nvim-treesitter] + ;:event ["BufReadPost"] + ;:config #((. (require "nvim-biscuits") :setup) {})} + + + :jiangmiao/auto-pairs {} :folke/which-key.nvim {} @@ -96,6 +103,7 @@ :glepnir/lspsaga.nvim {:after "vim-gruvbox8" :mod "dots.plugins.lspsaga"} + ;; -------------------- :Olical/conjure {} :tami5/compe-conjure {:requires [:Olical/conjure]} @@ -135,13 +143,15 @@ :rust-lang/rust.vim {:ft ["rust"] :requires ["mattn/webapi-vim"]} - :simrat39/rust-tools.nvim {:ft ["rust"]} + :simrat39/rust-tools.nvim {} :qnighy/lalrpop.vim {} - + :edwinb/idris2-vim {:ft ["idris2"]} :vmchale/ats-vim {:ft ["ats" "dats" "sats"]} :bakpakin/fennel.vim {}) + + ; >>> diff --git a/nvim/.config/nvim/fnl/dots/plugins/lsp.fnl b/nvim/.config/nvim/fnl/dots/plugins/lsp.fnl index b84db23..4d742ab 100644 --- a/nvim/.config/nvim/fnl/dots/plugins/lsp.fnl +++ b/nvim/.config/nvim/fnl/dots/plugins/lsp.fnl @@ -1,11 +1,14 @@ (module dots.plugins.lsp {autoload {a aniseed.core lsp lspconfig - lsp-configs lspconfig.configs + lsp-configs lspconfig/configs utils dots.utils} require-macros [macros]}) + +; TODO check https://github.com/neovim/nvim-lspconfig/blob/master/ADVANCED_README.md for default config for all of them + (fn on_attach [client bufnr] (pkg lsp_signature.nvim [lsp_signature (require "lsp_signature")] (lsp_signature.on_attach {:bind true @@ -80,7 +83,85 @@ (vim.fn.expand "$VIMRUNTIME/lua/vim/lsp") true}} :telemetry false}}})) +(when (not lsp.prolog_lsp) + (tset lsp-configs :prolog_lsp + {:default_config {:cmd ["swipl" "-g" "use_module(library(lsp_server))." "-g" "lsp_server:main" "-t" "halt" "--" "stdio"] + :filetypes ["prolog"] + :root_dir (fn [fname] (or (lsp.util.find_git_ancestor fname) (vim.loop.os_homedir))) + :settings {}}})) +(lsp.prolog_lsp.setup {}) + + + +; Idris2 ----------------------------------------------------------- <<<<< + +(def autostart-semantic-highlighting true) +(defn refresh-semantic-highlighting [] + (when autostart-semantic-highlighting + (vim.lsp.buf_request 0 + :textDocument/semanticTokens/full + {:textDocument (vim.lsp.util.make_text_document_params)} + nil))) + +(when (not lsp.idris2_lsp) + (set lsp-configs.idris2_lsp + {:default_config + {:cmd [:idris2-lsp] + :filetypes [:idris2] + :on_new_config (fn [new-config new-root-dir] + (set new-config.cmd {1 :idris2-lsp}) + (set new-config.capabilities.workspace.semanticTokens {:refreshSupport true})) + :root_dir (fn [fname] + (local scandir (require :plenary.scandir)) + (fn find-ipkg-ancestor [fname] + (lsp.util.search_ancestors + fname + (fn [path] + (local res (scandir.scan_dir path {:depth 1 :search_pattern ".+%.ipkg"})) + (when (not (vim.tbl_isempty res)) path)))) + + (or (or (find-ipkg-ancestor fname) + (lsp.util.find_git_ancestor fname)) + (vim.loop.os_homedir))) + :settings {}}})) +(lsp.idris2_lsp.setup + {:on_attach refresh-semantic-highlighting + :autostart true + :handlers {:workspace/semanticTokens/refresh refresh-semantic-highlighting + :textDocument/semanticTokens/full + (fn [err method result client-id bufnr config] + (let [client (vim.lsp.get_client_by_id client-id) + legend client.server_capabilities.semanticTokensProvider.legend + token-types legend.tokenTypes + data result.data + ns (vim.api.nvim_create_namespace :nvim-lsp-semantic)] + (vim.api.nvim_buf_clear_namespace bufnr ns 0 (- 1)) + (local tokens {}) + (var (prev-line prev-start) (values nil 0)) + (for [i 1 (length data) 5] + (local delta-line (. data i)) + (set prev-line + (or (and prev-line (+ prev-line delta-line)) + delta-line)) + (local delta-start (. data (+ i 1))) + (set prev-start (or (and (= delta-line 0) (+ prev-start delta-start)) + delta-start)) + (local token-type (. token-types (+ (. data (+ i 3)) 1))) + (vim.api.nvim_buf_add_highlight bufnr + ns + (.. :LspSemantic_ token-type) + prev-line + prev-start + (+ prev-start (. data (+ i 2)))))))}}) + +(vim.cmd "highlight link LspSemantic_type Include") +(vim.cmd "highlight link LspSemantic_function Identifier") +(vim.cmd "highlight link LspSemantic_struct Number") +(vim.cmd "highlight LspSemantic_variable guifg=gray") +(vim.cmd "highlight link LspSemantic_keyword Structure") + +; --------------------------------- >>>>> (se signcolumn "yes") diff --git a/profile/.profile b/profile/.profile index 462dfe1..2b7622d 100644 --- a/profile/.profile +++ b/profile/.profile @@ -35,3 +35,4 @@ export LOCALE_ARCHIVE=$(nix-build '' --no-out-link -A glibcLocales)/lib export _JAVA_AWT_WM_NONREPARENTING=1 + diff --git a/xmonad/.xmonad/lib/Config.hs b/xmonad/.xmonad/lib/Config.hs index 2f2899b..5bacb56 100644 --- a/xmonad/.xmonad/lib/Config.hs +++ b/xmonad/.xmonad/lib/Config.hs @@ -265,6 +265,8 @@ myStartupHook = do spawnOnce "xfce4-clipman &" --spawnOnce "redshift -P -O 5000 &" spawn "xset r rate 300 50 &" -- make key repeat quicker + spawn "setxkbmap de nodeadkeys" + spawn "arbtt-capture" --spawn "/home/leon/.screenlayout/dualscreen-stacked.sh" spawn "/home/leon/.screenlayout/tripplescreen-fixed.sh" spawnOnce "xsetroot -cursor_name left_ptr"