Have DAPs work in way that allows being shadowed by nix-shell/direnv.

main
Joshua Potter 2023-11-22 06:11:41 -07:00
parent 85b82055d3
commit af9f2f6b10
11 changed files with 158 additions and 77 deletions

View File

@ -1,11 +1,23 @@
{ pkgs, ... }: { config, pkgs, lib, ... }:
{ {
options.home.extraPythonPackages = lib.mkOption {
type = lib.types.listOf lib.types.string;
example = ''
[ debugpy mccabe ]
'';
description = lib.mdDoc ''
Extra Python packages that should be linked to the topmost Python
interpreter.
'';
};
imports = [ imports = [
./git.nix ./git.nix
./neovim ./neovim
./wezterm ./wezterm
]; ];
config = {
home = { home = {
username = "jrpotter"; username = "jrpotter";
homeDirectory = "/home/jrpotter"; homeDirectory = "/home/jrpotter";
@ -13,11 +25,13 @@
packages = with pkgs; [ packages = with pkgs; [
anki-bin anki-bin
bitwarden bitwarden
clang
elan elan
firefox firefox
gnumake gnumake
mullvad-vpn mullvad-vpn
python3 (python3.withPackages
(ps: builtins.map (s: ps.${s}) config.home.extraPythonPackages))
unzip unzip
wezterm wezterm
zotero zotero
@ -41,4 +55,5 @@
# See the Home Manager release notes for a list of state # See the Home Manager release notes for a list of state
# version changes in each release. # version changes in each release.
home.stateVersion = "23.05"; home.stateVersion = "23.05";
};
} }

View File

@ -32,6 +32,7 @@ let
plugin = (pkgs.vimPlugins.nvim-treesitter.withPlugins ( plugin = (pkgs.vimPlugins.nvim-treesitter.withPlugins (
ps: with ps; [ ps: with ps; [
bash bash
c
elixir elixir
lua lua
nix nix
@ -67,8 +68,19 @@ in
}; };
}; };
# Notice that within our imports we use `home.packages` instead of
# `extraPackages`. The latter is preferable but comes with `$PATH`-related
# problems.
#
# Specifically, Home Manager appends paths specifed in `extraPackages` to the
# end of `$PATH` meaning any already defined instance of some package will be
# used instead. Prepending is not an option either since that would break
# environments like those produced by `direnv` or `nix-shell`.
#
# https://github.com/nix-community/home-manager/pull/1756
imports = [ imports = [
./lang/bash.nix ./lang/bash.nix
./lang/c.nix
./lang/elixir.nix ./lang/elixir.nix
./lang/lean.nix ./lang/lean.nix
./lang/lua.nix ./lang/lua.nix

View File

@ -1,13 +1,13 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs; [
nodePackages.bash-language-server
shellcheck
];
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').bashls) {} require('init.lsp').setup(require('lspconfig').bashls) {}
''; '';
extraPackages = with pkgs; [
nodePackages.bash-language-server
shellcheck
];
}; };
} }

View File

@ -0,0 +1,23 @@
{ pkgs, ... }:
{
home.packages = with pkgs; [
clang-tools
vscode-extensions.vadimcn.vscode-lldb
];
programs.neovim = {
nvim-dap = ''
require('init.c').nvim_dap({
command = '${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb'
})
'';
nvim-lspconfig = ''
require('init.c').nvim_lspconfig()
'';
};
xdg.configFile."nvim/after/ftplugin/c.lua".text = ''
require('init.dap').buffer_map()
'';
}

View File

@ -1,14 +1,14 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs; [
elixir-ls
];
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').elixirls) { require('init.lsp').setup(require('lspconfig').elixirls) {
cmd = { 'elixir-ls' }, cmd = { 'elixir-ls' },
} }
''; '';
extraPackages = with pkgs; [
elixir-ls
];
}; };
} }

View File

@ -1,10 +1,12 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs;[
lua-language-server
];
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lua').nvim_lspconfig() require('init.lua').nvim_lspconfig()
''; '';
extraPackages = [ pkgs.lua-language-server ];
}; };
} }

View File

@ -1,10 +1,12 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs; [
nil
];
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').nil_ls) {} require('init.lsp').setup(require('lspconfig').nil_ls) {}
''; '';
extraPackages = [ pkgs.nil ];
}; };
} }

View File

@ -1,15 +1,14 @@
{ pkgs, ... }: { ... }:
let
venv = pkgs.python3.withPackages (ps: with ps; [
debugpy
mccabe
pycodestyle
pyflakes
python-lsp-server
python-lsp-black
]);
in
{ {
home.extraPythonPackages = [
"debugpy"
"mccabe"
"pycodestyle"
"pyflakes"
"python-lsp-server"
"python-lsp-black"
];
programs.neovim = { programs.neovim = {
nvim-dap = '' nvim-dap = ''
require('init.python').nvim_dap() require('init.python').nvim_dap()
@ -18,8 +17,6 @@ in
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.python').nvim_lspconfig() require('init.python').nvim_lspconfig()
''; '';
extraPackages = [ venv ];
}; };
xdg.configFile."nvim/after/ftplugin/python.lua".text = '' xdg.configFile."nvim/after/ftplugin/python.lua".text = ''

View File

@ -1,13 +1,13 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs; [
nodePackages.typescript-language-server
];
programs.neovim = { programs.neovim = {
nvim-lspconfig = '' nvim-lspconfig = ''
require('init.lsp').setup(require('lspconfig').tsserver) {} require('init.lsp').setup(require('lspconfig').tsserver) {}
''; '';
extraPackages = with pkgs; [
nodePackages.typescript-language-server
];
}; };
} }

View File

@ -0,0 +1,32 @@
local M = {}
function M.nvim_dap(options)
local dap = require('dap')
local key = 'codelldb'
dap.adapters[key] = {
type = 'server',
port = '${port}',
executable = {
command = options.command,
args = {'--port', '${port}'},
},
}
dap.configurations.c = dap.configurations.c or {}
table.insert(dap.configurations.c, {
name = 'Launch Executable',
type = key,
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
})
end
function M.nvim_lspconfig()
require('init.lsp').setup(require('lspconfig').clangd) {}
end
return M

View File

@ -2,23 +2,21 @@ local M = {}
function M.nvim_dap() function M.nvim_dap()
local dap = require('dap') local dap = require('dap')
local key = 'debugpy'
dap.adapters.python = function(callback, config) dap.adapters[key] = {
callback({
name = 'debugpy',
type = 'executable', type = 'executable',
command = 'python3', command = 'python3',
args = { '-m', 'debugpy.adapter' }, args = { '-m', 'debugpy.adapter' },
options = { options = {
source_filetype = 'python', source_filetype = 'python',
}, },
}) }
end
dap.configurations.python = dap.configurations.python or {} dap.configurations.python = dap.configurations.python or {}
table.insert(dap.configurations.python, { table.insert(dap.configurations.python, {
name = 'Launch', name = 'Launch File',
type = 'python', type = key,
request = 'launch', request = 'launch',
program = '${file}', program = '${file}',
cwd = '${workspaceFolder}', cwd = '${workspaceFolder}',