From e275224ea8f3182916e715861a09d8a5a13147ca Mon Sep 17 00:00:00 2001 From: Linnnus Date: Tue, 20 Feb 2024 09:08:54 +0100 Subject: reorg: Move muhammed-specific configuration into hosts/muhammed/home --- home/default.nix | 2 - home/iterm2/default.nix | 26 -------- home/neovim/completion.nix | 1 - home/neovim/default.nix | 3 +- home/neovim/editing-plugins.nix | 26 ++++++++ home/neovim/lsp.nix | 109 --------------------------------- home/neovim/plugins.nix | 90 --------------------------- home/noweb/default.nix | 12 ---- hosts/muhammed/configuration.nix | 4 ++ hosts/muhammed/home/default.nix | 10 +++ hosts/muhammed/home/iterm2/default.nix | 26 ++++++++ hosts/muhammed/home/neovim/conjure.nix | 71 +++++++++++++++++++++ hosts/muhammed/home/neovim/default.nix | 8 +++ hosts/muhammed/home/neovim/lsp.nix | 107 ++++++++++++++++++++++++++++++++ hosts/muhammed/home/noweb/default.nix | 12 ++++ 15 files changed, 265 insertions(+), 242 deletions(-) delete mode 100644 home/iterm2/default.nix create mode 100644 home/neovim/editing-plugins.nix delete mode 100644 home/neovim/lsp.nix delete mode 100644 home/neovim/plugins.nix delete mode 100644 home/noweb/default.nix create mode 100644 hosts/muhammed/home/default.nix create mode 100644 hosts/muhammed/home/iterm2/default.nix create mode 100644 hosts/muhammed/home/neovim/conjure.nix create mode 100644 hosts/muhammed/home/neovim/default.nix create mode 100644 hosts/muhammed/home/neovim/lsp.nix create mode 100644 hosts/muhammed/home/noweb/default.nix diff --git a/home/default.nix b/home/default.nix index 93c3720..d02e7b3 100644 --- a/home/default.nix +++ b/home/default.nix @@ -22,8 +22,6 @@ ./git ./dev-utils ./networking-utils - ./iterm2 - ./noweb ] ++ builtins.attrValues flakeOutputs.homeModules; diff --git a/home/iterm2/default.nix b/home/iterm2/default.nix deleted file mode 100644 index d868e57..0000000 --- a/home/iterm2/default.nix +++ /dev/null @@ -1,26 +0,0 @@ -# This file configures iterm2. Note that the actual definition of iTerm2 for -# home-manager is in `modules/home-manager/iterm2`. *That* file declares -# `options.programs.iterm2.enable`. -{ - pkgs, - lib, - ... -}: let - inherit (lib) mkIf; - inherit (pkgs.stdenv) isDarwin; -in { - config = mkIf isDarwin { - home.packages = with pkgs; [imgcat]; - - programs.iterm2 = { - enable = true; - # config = { - # # Use the minimal tab style. - # # See: https://github.com/gnachman/iTerm2/blob/bd40fba0611fa94684dadf2478625f2a93eb6e47/sources/iTermPreferences.h#L29 - # TabStyleWithAutomaticOption = 5; - # }; - - shellIntegration.enableZshIntegration = true; - }; - }; -} diff --git a/home/neovim/completion.nix b/home/neovim/completion.nix index 904491d..3776674 100644 --- a/home/neovim/completion.nix +++ b/home/neovim/completion.nix @@ -43,6 +43,5 @@ cmp-calc cmp-buffer cmp-path - cmp-conjure ]; } diff --git a/home/neovim/default.nix b/home/neovim/default.nix index 1739047..56f6171 100644 --- a/home/neovim/default.nix +++ b/home/neovim/default.nix @@ -1,10 +1,9 @@ # This file contains the HM configuration options for Neovim. {...}: { imports = [ - ./lsp.nix ./filetype.nix ./completion.nix - ./plugins.nix + ./editing-plugins.nix ]; programs.neovim = { diff --git a/home/neovim/editing-plugins.nix b/home/neovim/editing-plugins.nix new file mode 100644 index 0000000..23c7d63 --- /dev/null +++ b/home/neovim/editing-plugins.nix @@ -0,0 +1,26 @@ +# This module sets up and configures various miscellaneous plugins. +# TODO: I fear this file will become the utils.lua of my Neovim configuration. Remove it! +{pkgs, ...}: { + programs.neovim.plugins = [ + { + plugin = pkgs.vimPlugins.vim-localvimrc; + type = "viml"; + config = '' + let g:localvimrc_persistent = 1 + let g:localvimrc_name = [ "local.vim", "editors/local.vim" ] + ''; + } + { + plugin = pkgs.vimPlugins.vim-sneak; + type = "viml"; + config = '' + let g:sneak#s_next = 1 + let g:sneak#use_ic_scs = 1 + map f Sneak_f + map F Sneak_F + map t Sneak_t + map T Sneak_T + ''; + } + ]; +} diff --git a/home/neovim/lsp.nix b/home/neovim/lsp.nix deleted file mode 100644 index 0c2e290..0000000 --- a/home/neovim/lsp.nix +++ /dev/null @@ -1,109 +0,0 @@ -# This module sets up LSP server configurations for Neovim. It is waaay -# overcomplicated as it kind of turned into an experiment in generating Lua -# code from a Nix attrset. -{pkgs, ...}: { - programs.neovim.plugins = [ - { - plugin = pkgs.vimPlugins.nvim-lspconfig; - type = "lua"; - config = '' - local lspconfig = require("lspconfig") - local util = require("lspconfig.util") - - -- Mappings. - -- See `:help vim.diagnostic.*` for documentation on any of the below functions - local opts = { noremap=true, silent=true } - vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) - vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) - vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) - vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) - - -- Use an on_attach function to only map the following keys - -- after the language server attaches to the current buffer - local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap=true, silent=true, buffer=bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) - vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) - vim.keymap.set('n', 's', function() vim.cmd[[ClangdSwitchSourceHeader]] end, bufopts) - end - - -- Use a loop to conveniently call 'setup' on multiple servers and - -- map buffer local keybindings when the language server attaches - local servers = { - pyright = { cmd = { "${pkgs.pyright}/bin/pyright-langserver", "--stdio" } }, - nixd = { cmd = { "${pkgs.nixd}/bin/nixd" } }, - denols = { - init_options = { - enable = true, - unstable = true, - lint = true, - }, - cmd = { "${pkgs.unstable.deno}/bin/deno", "lsp", "--unstable" }, - root_dir = function(startpath) - if util.find_package_json_ancestor(startpath) then - -- This is a Node project; let tsserver handle this one. - return nil - else - -- Otherwise, we try to find the root or - -- default to the current directory. - return util.root_pattern("deno.json", "deno.jsonc", ".git")(startpath) - or util.path.dirname(startpath) - end - end, - }, - clangd = { - cmd = { "${pkgs.clang-tools}/bin/clangd" }, - }, - nimls = { - cmd = { "${pkgs.nimlsp}/bin/nimlsp" }, - }, - }; - for server, config in pairs(servers) do - -- set common options - config.on_attach = on_attach; - config.debounce_text_changes = 150; - - lspconfig[server].setup(config) - end - ''; - } - ]; -} -# I spent like an hour writing this, only to find it was a pretty bad idea. -# -# nixToLua = s: -# if builtins.isAttrs s then -# let -# renderAttr = name: value: "[ [==========[" + name + "]==========] ] = " + (nixToLua value); -# attrsList = map (name: renderAttr name s.${name}) (lib.attrNames s); -# attrsListStr = lib.concatStringsSep ", " attrsList; -# in -# "{ ${attrsListStr} }" -# else if builtins.isList s then -# "{ " + (lib.concatStringsSep ", " (map nixToLua s)) + " }" -# else if builtins.isString s then -# # Oh boy I sure hope `s` doesn't contain "]==========]". -# "[==========[" + s + "]==========]" -# else if builtins.isInt s || builtins.isFloat s then -# toString s -# else -# throw "Cannot convert ${builtins.typeOf s} to Lua value!"; - diff --git a/home/neovim/plugins.nix b/home/neovim/plugins.nix deleted file mode 100644 index 54f6d9d..0000000 --- a/home/neovim/plugins.nix +++ /dev/null @@ -1,90 +0,0 @@ -# This module sets up and configures various miscellaneous plugins. -# TODO: I fear this file will become the utils.lua of my Neovim configuration. Remove it! -{pkgs, ...}: { - programs.neovim.plugins = [ - { - plugin = pkgs.vimPlugins.vim-localvimrc; - type = "viml"; - config = '' - let g:localvimrc_persistent = 1 - let g:localvimrc_name = [ "local.vim", "editors/local.vim" ] - ''; - } - { - plugin = pkgs.vimPlugins.vim-sneak; - type = "viml"; - config = '' - let g:sneak#s_next = 1 - let g:sneak#use_ic_scs = 1 - map f Sneak_f - map F Sneak_F - map t Sneak_t - map T Sneak_T - ''; - } - { - # Add interactive repl-like environment. - # See also the addition of cmp-conjure in `completion.nix`. - # See also the addition of clojure in `dev-utils/default.nix`. - plugin = pkgs.vimPlugins.conjure; - type = "lua"; - config = '' - local start_clj_repl = "StartCljRepl"; - local start_lein_repl = "StartLeinRepl"; - - -- Create a command to launch nRepl for Clojure support. - -- See: https://github.com/Olical/conjure/wiki/Quick-start:-Clojure - vim.api.nvim_create_user_command(start_clj_repl, function() - local id = vim.fn.jobstart({ - "${pkgs.clojure}/bin/clj", - "-Sdeps", - '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.40.0"}}}', - "--main", - "nrepl.cmdline", - "--middleware", - '["cider.nrepl/cider-middleware"]', - "--interactive", - }) - print("Started nRepl job #" .. id) - end, { - desc = "Starts an nRepl session in the current directory using clj.", - }) - - vim.api.nvim_create_user_command(start_lein_repl, function() - local id = vim.fn.jobstart({ - "${pkgs.leiningen}/bin/lein", - "repl", - }) - print("Started nRepl job #" .. id) - end, { - desc = "Starts an nRepl session in the current directory using Lein.", - }) - - -- Launch nRepl when any clojure file is started. - -- vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, { - -- pattern = "*.clj", - -- command = start_clj_repl, - -- }); - - -- Use Guile to evaluate scheme buffers. - local start_guile_repl = "StartGuileRepl"; - local sock_path = "/tmp/guile-repl.sock" - vim.g["conjure#filetype#scheme"] = "conjure.client.guile.socket" - vim.g["conjure#client#guile#socket#pipename"] = sock_path - vim.api.nvim_create_user_command(start_guile_repl, function() - local id = vim.fn.jobstart({ - "${pkgs.guile}/bin/guile", - "--listen=" .. sock_path, - }) - print("Started Guile job #" .. id) - end, { - desc = "Starts an Guile repl session listening on " .. sock_path, - }) - - -- Jump to bottom of log when new evaluation happens - -- See: https://github.com/Olical/conjure/blob/58c46d1f4999679659a5918284b574c266a7ac83/doc/conjure.txt#L872 - vim.cmd [[autocmd User ConjureEval if expand("%:t") =~ "^conjure-log-" | exec "normal G" | endif]] - ''; - } - ]; -} diff --git a/home/noweb/default.nix b/home/noweb/default.nix deleted file mode 100644 index ef67862..0000000 --- a/home/noweb/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{pkgs, ...}: { - home.packages = with pkgs; [ - noweb - texliveFull - yalafi-shell - ]; - - # Prepend nowebs STY files to the search path. I chose to do it globally, - # rather than using `makeWrapper` because I sometimes want to manually invoke - # `pdflatex` and the like on the output of `noweave`. - home.sessionVariables.TEXINPUTS = "${pkgs.noweb.tex}/tex/latex/noweb/:$TEXINPUTS"; -} diff --git a/hosts/muhammed/configuration.nix b/hosts/muhammed/configuration.nix index 9119a55..c629b22 100644 --- a/hosts/muhammed/configuration.nix +++ b/hosts/muhammed/configuration.nix @@ -1,5 +1,9 @@ # This file contains the configuration for my Macbook Pro. {flakeInputs, ...}: { + imports = [ + ./home + ]; + # Specify the location of this configuration file. Very meta. environment.darwinConfig = flakeInputs.self + "/hosts/muhammed/configuration.nix"; diff --git a/hosts/muhammed/home/default.nix b/hosts/muhammed/home/default.nix new file mode 100644 index 0000000..b0b126c --- /dev/null +++ b/hosts/muhammed/home/default.nix @@ -0,0 +1,10 @@ +# Here we extend the HM user defined in `home/default.nix`. All the global HM +# stuff is defined in there. +{...}: { + home-manager.users.linus = { + imports = [ + ./iterm2 + ./noweb + ]; + }; +} diff --git a/hosts/muhammed/home/iterm2/default.nix b/hosts/muhammed/home/iterm2/default.nix new file mode 100644 index 0000000..d868e57 --- /dev/null +++ b/hosts/muhammed/home/iterm2/default.nix @@ -0,0 +1,26 @@ +# This file configures iterm2. Note that the actual definition of iTerm2 for +# home-manager is in `modules/home-manager/iterm2`. *That* file declares +# `options.programs.iterm2.enable`. +{ + pkgs, + lib, + ... +}: let + inherit (lib) mkIf; + inherit (pkgs.stdenv) isDarwin; +in { + config = mkIf isDarwin { + home.packages = with pkgs; [imgcat]; + + programs.iterm2 = { + enable = true; + # config = { + # # Use the minimal tab style. + # # See: https://github.com/gnachman/iTerm2/blob/bd40fba0611fa94684dadf2478625f2a93eb6e47/sources/iTermPreferences.h#L29 + # TabStyleWithAutomaticOption = 5; + # }; + + shellIntegration.enableZshIntegration = true; + }; + }; +} diff --git a/hosts/muhammed/home/neovim/conjure.nix b/hosts/muhammed/home/neovim/conjure.nix new file mode 100644 index 0000000..0acfadd --- /dev/null +++ b/hosts/muhammed/home/neovim/conjure.nix @@ -0,0 +1,71 @@ +{pkgs, ...}: { + programs.neovim.plugins = [ + { + # Add interactive repl-like environment. + # See also the addition of cmp-conjure in `completion.nix`. + # See also the addition of clojure in `dev-utils/default.nix`. + plugin = pkgs.vimPlugins.conjure; + type = "lua"; + config = '' + local start_clj_repl = "StartCljRepl"; + local start_lein_repl = "StartLeinRepl"; + + -- Create a command to launch nRepl for Clojure support. + -- See: https://github.com/Olical/conjure/wiki/Quick-start:-Clojure + vim.api.nvim_create_user_command(start_clj_repl, function() + local id = vim.fn.jobstart({ + "${pkgs.clojure}/bin/clj", + "-Sdeps", + '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.40.0"}}}', + "--main", + "nrepl.cmdline", + "--middleware", + '["cider.nrepl/cider-middleware"]', + "--interactive", + }) + print("Started nRepl job #" .. id) + end, { + desc = "Starts an nRepl session in the current directory using clj.", + }) + + vim.api.nvim_create_user_command(start_lein_repl, function() + local id = vim.fn.jobstart({ + "${pkgs.leiningen}/bin/lein", + "repl", + }) + print("Started nRepl job #" .. id) + end, { + desc = "Starts an nRepl session in the current directory using Lein.", + }) + + -- Launch nRepl when any clojure file is started. + -- vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, { + -- pattern = "*.clj", + -- command = start_clj_repl, + -- }); + + -- Use Guile to evaluate scheme buffers. + local start_guile_repl = "StartGuileRepl"; + local sock_path = "/tmp/guile-repl.sock" + vim.g["conjure#filetype#scheme"] = "conjure.client.guile.socket" + vim.g["conjure#client#guile#socket#pipename"] = sock_path + vim.api.nvim_create_user_command(start_guile_repl, function() + local id = vim.fn.jobstart({ + "${pkgs.guile}/bin/guile", + "--listen=" .. sock_path, + }) + print("Started Guile job #" .. id) + end, { + desc = "Starts an Guile repl session listening on " .. sock_path, + }) + + -- Jump to bottom of log when new evaluation happens + -- See: https://github.com/Olical/conjure/blob/58c46d1f4999679659a5918284b574c266a7ac83/doc/conjure.txt#L872 + vim.cmd [[autocmd User ConjureEval if expand("%:t") =~ "^conjure-log-" | exec "normal G" | endif]] + ''; + } + + # Compe plugin to interact with conjure. + pkgs.vimPlugins.cmp-conjure + ]; +} diff --git a/hosts/muhammed/home/neovim/default.nix b/hosts/muhammed/home/neovim/default.nix new file mode 100644 index 0000000..905896c --- /dev/null +++ b/hosts/muhammed/home/neovim/default.nix @@ -0,0 +1,8 @@ +# Once again we extend the global configuration defined in `home/neovim/` with +# some stuff specific to this host (mainly development stuff). +{...}: { + imports = [ + ./lsp.nix + ./conjure.nix + ]; +} diff --git a/hosts/muhammed/home/neovim/lsp.nix b/hosts/muhammed/home/neovim/lsp.nix new file mode 100644 index 0000000..06745da --- /dev/null +++ b/hosts/muhammed/home/neovim/lsp.nix @@ -0,0 +1,107 @@ +# This module sets up LSP server configurations for Neovim. +{pkgs, ...}: { + programs.neovim.plugins = [ + { + plugin = pkgs.vimPlugins.nvim-lspconfig; + type = "lua"; + config = '' + local lspconfig = require("lspconfig") + local util = require("lspconfig.util") + + -- Mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + local opts = { noremap=true, silent=true } + vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + + -- Use an on_attach function to only map the following keys + -- after the language server attaches to the current buffer + local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + vim.keymap.set('n', 's', function() vim.cmd[[ClangdSwitchSourceHeader]] end, bufopts) + end + + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + local servers = { + pyright = { cmd = { "${pkgs.pyright}/bin/pyright-langserver", "--stdio" } }, + nixd = { cmd = { "${pkgs.nixd}/bin/nixd" } }, + denols = { + init_options = { + enable = true, + unstable = true, + lint = true, + }, + cmd = { "${pkgs.unstable.deno}/bin/deno", "lsp", "--unstable" }, + root_dir = function(startpath) + if util.find_package_json_ancestor(startpath) then + -- This is a Node project; let tsserver handle this one. + return nil + else + -- Otherwise, we try to find the root or + -- default to the current directory. + return util.root_pattern("deno.json", "deno.jsonc", ".git")(startpath) + or util.path.dirname(startpath) + end + end, + }, + clangd = { + cmd = { "${pkgs.clang-tools}/bin/clangd" }, + }, + nimls = { + cmd = { "${pkgs.nimlsp}/bin/nimlsp" }, + }, + }; + for server, config in pairs(servers) do + -- set common options + config.on_attach = on_attach; + config.debounce_text_changes = 150; + + lspconfig[server].setup(config) + end + ''; + } + ]; +} +# I spent like an hour writing this, only to find it was a pretty bad idea. +# +# nixToLua = s: +# if builtins.isAttrs s then +# let +# renderAttr = name: value: "[ [==========[" + name + "]==========] ] = " + (nixToLua value); +# attrsList = map (name: renderAttr name s.${name}) (lib.attrNames s); +# attrsListStr = lib.concatStringsSep ", " attrsList; +# in +# "{ ${attrsListStr} }" +# else if builtins.isList s then +# "{ " + (lib.concatStringsSep ", " (map nixToLua s)) + " }" +# else if builtins.isString s then +# # Oh boy I sure hope `s` doesn't contain "]==========]". +# "[==========[" + s + "]==========]" +# else if builtins.isInt s || builtins.isFloat s then +# toString s +# else +# throw "Cannot convert ${builtins.typeOf s} to Lua value!"; + diff --git a/hosts/muhammed/home/noweb/default.nix b/hosts/muhammed/home/noweb/default.nix new file mode 100644 index 0000000..ef67862 --- /dev/null +++ b/hosts/muhammed/home/noweb/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + home.packages = with pkgs; [ + noweb + texliveFull + yalafi-shell + ]; + + # Prepend nowebs STY files to the search path. I chose to do it globally, + # rather than using `makeWrapper` because I sometimes want to manually invoke + # `pdflatex` and the like on the output of `noweave`. + home.sessionVariables.TEXINPUTS = "${pkgs.noweb.tex}/tex/latex/noweb/:$TEXINPUTS"; +} -- cgit v1.2.3