I am trying to configure nvim-dap in neovim with home manager. How can I have cwd be '${workspaceFolder}' when the init.lua file is created, and not nix trying to find a variable named workspaceFolder?
{
plugin = nvim-dap;
type = "lua";
config = ''
local dap = require('dap')
dap.adapters.codelldb = {
type = 'server',
port = '13000',
host = '127.0.0.1',
executable = {
command = '${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode.lldb/adapter/codelldb',
args = { '--port', '13000' },
},
}
dap.configurations.c = {
{
name = 'Launch',
type = 'codelldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},
},
}
'';
}
Thank you for the answer, but this did not work. Changing the line to cwd = "''${workspaceFolder}" does work however. If I try your suggestion, I get the following error:
error:
… while calling the 'head' builtin
at /nix/store/fs1ai4bxgp47vxx7zn0b7cr1ssz7ghws-source/lib/attrsets.nix:784:11:
783| || pred here (elemAt values 1) (head values) then
784| head values
| ^
785| else
… while evaluating the attribute 'value'
at /nix/store/fs1ai4bxgp47vxx7zn0b7cr1ssz7ghws-source/lib/modules.nix:768:9:
767| in warnDeprecation opt //
768| { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
769| inherit (res.defsFinal') highestPrio;
(stack trace truncated; use '--show-trace' to show the full trace)
error: undefined variable 'workspaceFolder'
at /nix/store/mk49j2pywf5fr21qi22rsnwyg3rx0y9z-source/home/neovim/default.nix:182:26:
181| end,
182| cwd = '''${workspaceFolder}',
| ^
183| stopOnEntry = false,
This isn’t even a valid Nix string. The two string delimiters are " and ''. A single ' is not a string delimiter in Nix. In " strings you can escape a ${ with a \, e.g. \${, and as already mentioned in string literals starting with '' you can use ''${.