nixos-configs/common/home/neovim/langs/nix.nix

76 lines
1.8 KiB
Nix
Raw Permalink Normal View History

{
config,
pkgs,
lib,
nixd,
2024-06-10 22:57:20 -04:00
self,
...
}: let
inherit (lib) getExe hasPrefix mkIf removePrefix;
inherit (config.vars) hostName mainUser neovimIde;
2024-06-10 22:57:20 -04:00
2024-08-02 11:26:15 -04:00
defaultFormatter = self.formatter.${pkgs.system};
nixdPkg = nixd.packages.${pkgs.system}.default;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}";
in
mkIf neovimIde {
assertions = [
{
2024-05-09 15:36:57 -04:00
assertion =
neovimIde
&& hasPrefix "/home/${mainUser}/" flakeEnv
|| !neovimIde;
message = ''
Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the neovim module.
'';
}
];
2024-06-10 22:57:20 -04:00
home.packages = [
2024-08-02 11:26:15 -04:00
defaultFormatter
nixdPkg
];
2024-08-02 11:26:15 -04:00
# nixd by default kinda spams LspLog
home.sessionVariables.NIXD_FLAGS = "-log=error";
xdg.dataFile."${flakeDir}/.nixd.json".text = builtins.toJSON {
nixpkgs = {
expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}";
};
options.nixos = {
expr = "(builtins.getFlake \"${flakeDir}\").nixosConfigurations.${hostName}.options";
};
};
programs = {
neovim = {
extraPackages = [
nixdPkg
];
2024-05-08 23:04:16 -04:00
extraLuaConfig =
2024-06-09 22:49:30 -04:00
# lua
2024-05-08 23:04:16 -04:00
''
require('lspconfig').nixd.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
filetypes = { 'nix', 'in.nix' },
2024-05-09 10:42:45 -04:00
settings = {
nixd = {
2024-06-09 22:49:30 -04:00
formatting = {
-- TODO: Try to find <flake>.formatter
2024-08-02 11:26:15 -04:00
command = { '${getExe defaultFormatter}' },
2024-06-09 22:49:30 -04:00
},
2024-05-09 10:42:45 -04:00
},
},
});
2024-05-08 23:04:16 -04:00
'';
};
};
}