style: fmt

This commit is contained in:
Marvin Drescher 2024-01-30 09:09:50 +01:00
parent 8b36fe97d0
commit fa4f77984e

View File

@ -1,8 +1,7 @@
{ { config
config, , pkgs
pkgs, , lib
lib, , ...
...
}: }:
with lib; let with lib; let
rust-analyzer = rust-analyzer =
@ -13,32 +12,33 @@ with lib; let
if config.class ? dev if config.class ? dev
then then
symlinkJoin symlinkJoin
{ {
name = "nvim-fenix"; name = "nvim-fenix";
paths = [ paths = [
(fenix.latest.withComponents [ (fenix.latest.withComponents [
"cargo" "cargo"
"clippy-preview" "clippy-preview"
"rust-src" "rust-src"
"rust-std" "rust-std"
"rustc" "rustc"
"rustfmt-preview" "rustfmt-preview"
]) ])
cargo-watch cargo-watch
]; ];
} }
else else
symlinkJoin { symlinkJoin {
name = "nvim-rust"; name = "nvim-rust";
paths = [rustc cargo rustfmt clippy cargo-watch]; paths = [ rustc cargo rustfmt clippy cargo-watch ];
}; };
in { in
{
programs.neovim = { programs.neovim = {
# https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix # https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix
enable = true; enable = true;
vimAlias = true; vimAlias = true;
withNodeJs = true; withNodeJs = true;
extraPackages = with pkgs; [fzf xclip fish]; extraPackages = with pkgs; [ fzf xclip fish ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
vim-fugitive vim-fugitive
git-blame-nvim git-blame-nvim
@ -87,87 +87,92 @@ in {
telescope-undo-nvim telescope-undo-nvim
oil-nvim oil-nvim
]; ];
extraLuaConfig = let extraLuaConfig =
# tries to compute a package set required to make package resolution in lua let
# via deps["pkg"] work # tries to compute a package set required to make package resolution in lua
inherit (builtins) head tail hasAttr getAttr; # via deps["pkg"] work
pkg = parts: pkgs: let inherit (builtins) head tail hasAttr getAttr;
rem = tail parts; pkg = parts: pkgs:
subset = let
if hasAttr (head parts) pkgs rem = tail parts;
then getAttr (head parts) pkgs subset =
else throw "no attr ${name}"; if hasAttr (head parts) pkgs
in then getAttr (head parts) pkgs
if rem == [] else throw "no attr ${name}";
then subset in
else builtins.addErrorContext "${concatStringsSep "." parts}" (pkg rem subset); if rem == [ ]
getPkg = name: let parts = builtins.split "\\." name; in pkg parts pkgs; then subset
packages = file: let else builtins.addErrorContext "${concatStringsSep "." parts}" (pkg rem subset);
out = builtins.readFile (pkgs.runCommandLocal "extract-deps" getPkg = name: let parts = builtins.split "\\." name; in pkg parts pkgs;
{ packages = file:
nativeBuildInputs = [pkgs.gnused]; let
__contentAddressed = true; out = builtins.readFile (pkgs.runCommandLocal "extract-deps"
} '' {
sed -nr 's/.*(deps\["(.*)_path"\]).*/\2/p' ${file} | uniq > $out nativeBuildInputs = [ pkgs.gnused ];
''); __contentAddressed = true;
names = lib.splitString "\n" out; } ''
in sed -nr 's/.*(deps\["(.*)_path"\]).*/\2/p' ${file} | uniq > $out
filter (name: name != "") names; '');
paths = names = lib.splitString "\n" out;
(listToAttrs (map in
(name: { filter (name: name != "") names;
inherit name; paths =
value = getPkg name; (listToAttrs (map
}) (name: {
(packages "${confDir}/*.lua"))) inherit name;
// { value = getPkg name;
lldb = pkgs.lldb; })
rust_analyzer = rust-analyzer; (packages "${confDir}/*.lua")))
typst_lsp = pkgs.typst-lsp; // {
inherit (pkgs.python3Packages) python-lsp-server; lldb = pkgs.lldb;
inherit (pkgs.luajitPackages) lua-lsp; rust_analyzer = rust-analyzer;
inherit (pkgs.nodePackages) typescript-language-server bash-language-server; typst_lsp = pkgs.typst-lsp;
inherit (pkgs.python3Packages) python-lsp-server;
inherit (pkgs.luajitPackages) lua-lsp;
inherit (pkgs.nodePackages) typescript-language-server bash-language-server;
};
pathsLua = pkgs.writeTextFile {
name = "nvim-deps.lua";
text = ''
deps = {}
${concatStringsSep "\n " (mapAttrsToList (name: path: ''deps["${name}_path"] = "${path}"'') paths)}
return deps
'';
}; };
pathsLua = pkgs.writeTextFile { confDir = lib.sourceFilesBySuffices ./. [ "lua" "vim" ];
name = "nvim-deps.lua"; in
text = ''
deps = {}
${concatStringsSep "\n " (mapAttrsToList (name: path: ''deps["${name}_path"] = "${path}"'') paths)}
return deps
'';
};
confDir = lib.sourceFilesBySuffices ./. ["lua" "vim"];
in
with lib; '' with lib; ''
vim.cmd [[source ${confDir}/init.vim]] vim.cmd [[source ${confDir}/init.vim]]
package.path = package.path .. ";${confDir}/?.lua;${pathsLua};" package.path = package.path .. ";${confDir}/?.lua;${pathsLua};"
dofile("${confDir}/init.lua") dofile("${confDir}/init.lua")
''; '';
}; };
programs.git.ignores = [".nvim_session"]; programs.git.ignores = [ ".nvim_session" ];
xdg.configFile."nvim/coc-settings.json".text = let xdg.configFile."nvim/coc-settings.json".text =
preferProjectEnv = binName: alternate: let
pkgs.writeShellScript "${binName}-switcher" '' preferProjectEnv = binName: alternate:
if command -v ${binName}; then pkgs.writeShellScript "${binName}-switcher" ''
${binName} ''${@} if command -v ${binName}; then
else ${binName} ''${@}
${alternate} ''${@} else
fi ${alternate} ''${@}
''; fi
addSDK = {
name,
lsp,
sdk,
}:
with pkgs;
runCommandLocal name
{
nativeBuildInputs = [makeWrapper];
} ''
makeWrapper ${lsp} $out \
--prefix PATH : ${lib.makeBinPath sdk}
''; '';
in addSDK =
{ name
, lsp
, sdk
,
}:
with pkgs;
runCommandLocal name
{
nativeBuildInputs = [ makeWrapper ];
} ''
makeWrapper ${lsp} $out \
--prefix PATH : ${lib.makeBinPath sdk}
'';
in
builtins.toJSON { builtins.toJSON {
python = { python = {
pythonPath = preferProjectEnv "python3" (pkgs.python3 + "/bin/python3"); pythonPath = preferProjectEnv "python3" (pkgs.python3 + "/bin/python3");
@ -189,55 +194,55 @@ in {
fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582 fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582
snippets = { snippets = {
"return Err(..)" = { "return Err(..)" = {
postfix = ["reterr"]; postfix = [ "reterr" ];
body = ''return Err($${receiver});''; body = ''return Err($${receiver});'';
description = "return expression as Err"; description = "return expression as Err";
scope = "expr"; scope = "expr";
}; };
"format!(..)" = { "format!(..)" = {
postfix = ["fmt"]; postfix = [ "fmt" ];
body = ''format!($${receiver})''; body = ''format!($${receiver})'';
description = "use receiver as format string"; description = "use receiver as format string";
scope = "expr"; scope = "expr";
}; };
"wrap { .. }" = { "wrap { .. }" = {
postfix = ["brace" "wrap"]; postfix = [ "brace" "wrap" ];
body = ''{$${receiver}}''; body = ''{$${receiver}}'';
description = "wrap this type in { .. }"; description = "wrap this type in { .. }";
scope = "expr"; scope = "expr";
}; };
"async move { .. }" = { "async move { .. }" = {
postfix = ["asyncm"]; postfix = [ "asyncm" ];
body = ''async move {$${receiver}}''; body = ''async move {$${receiver}}'';
description = "wrap this type in async move { .. }"; description = "wrap this type in async move { .. }";
scope = "expr"; scope = "expr";
}; };
"try { .. }" = { "try { .. }" = {
postfix = ["try"]; postfix = [ "try" ];
body = ''let result: Result<_,_> = try {$${receiver}};''; body = ''let result: Result<_,_> = try {$${receiver}};'';
description = "wrap this type in try { .. }"; description = "wrap this type in try { .. }";
scope = "expr"; scope = "expr";
}; };
"while let Some(item) = { .. } {}" = { "while let Some(item) = { .. } {}" = {
postfix = ["letwhile"]; postfix = [ "letwhile" ];
body = ''while let Some(item) = $${receiver} {}''; body = ''while let Some(item) = $${receiver} {}'';
description = "wrap this type in while let Some"; description = "wrap this type in while let Some";
scope = "expr"; scope = "expr";
}; };
"let $x = $x.clone()" = { "let $x = $x.clone()" = {
postfix = ["cloned"]; postfix = [ "cloned" ];
body = ''let $${receiver} = $${receiver}.clone();''; body = ''let $${receiver} = $${receiver}.clone();'';
description = "clone a variable into a new binding"; description = "clone a variable into a new binding";
scope = "expr"; scope = "expr";
}; };
"let $x = $x.into()" = { "let $x = $x.into()" = {
postfix = ["into"]; postfix = [ "into" ];
body = ''let $${receiver} = $${receiver}.clone();''; body = ''let $${receiver} = $${receiver}.clone();'';
description = "call into() and create a new binding"; description = "call into() and create a new binding";
scope = "expr"; scope = "expr";
}; };
"assert_eq!($x, .. );" = { "assert_eq!($x, .. );" = {
postfix = ["asseq"]; postfix = [ "asseq" ];
body = ''assert_eq!($${receiver}, );''; body = ''assert_eq!($${receiver}, );'';
description = "create an assertion for the expression"; description = "create an assertion for the expression";
scope = "expr"; scope = "expr";
@ -251,7 +256,7 @@ in {
serverPath = addSDK { serverPath = addSDK {
name = "rust-env"; name = "rust-env";
lsp = "${rust-analyzer}/bin/rust-analyzer"; lsp = "${rust-analyzer}/bin/rust-analyzer";
sdk = [rust-sdk]; sdk = [ rust-sdk ];
}; };
imports.group.enable = true; imports.group.enable = true;
inlayHints = { inlayHints = {
@ -274,7 +279,7 @@ in {
enable = true; enable = true;
experimental.enable = true; experimental.enable = true;
}; };
files.excludeDirs = ["result" "target"]; files.excludeDirs = [ "result" "target" ];
extraEnv = { extraEnv = {
RA_LOG = "debug"; RA_LOG = "debug";
}; };
@ -282,14 +287,14 @@ in {
languageserver = { languageserver = {
ccls = { ccls = {
command = preferProjectEnv "ccls" "${pkgs.ccls}/bin/ccls"; command = preferProjectEnv "ccls" "${pkgs.ccls}/bin/ccls";
filetypes = ["c" "cc" "cpp" "c++" "objc" "objcpp"]; filetypes = [ "c" "cc" "cpp" "c++" "objc" "objcpp" ];
rootPatterns = [".ccls" "compile_commands.json" ".git/" ".hg/"]; rootPatterns = [ ".ccls" "compile_commands.json" ".git/" ".hg/" ];
initializationOptions = { initializationOptions = {
cache = { cache = {
directory = "${config.xdg.cacheHome}/ccls"; directory = "${config.xdg.cacheHome}/ccls";
}; };
}; };
clang.extraOptions = ["-std=c++20"]; clang.extraOptions = [ "-std=c++20" ];
}; };
nix = { nix = {
command = "${pkgs.nil}/bin/nil"; command = "${pkgs.nil}/bin/nil";
@ -299,15 +304,15 @@ in {
autoEvalInputs = true; autoEvalInputs = true;
}; };
maxMemoryMB = 1024 * 4; maxMemoryMB = 1024 * 4;
rootPatterns = ["flake.nix"]; rootPatterns = [ "flake.nix" ];
filetypes = ["nix"]; filetypes = [ "nix" ];
}; };
diagnostic-languageserver = { diagnostic-languageserver = {
filetypes = { filetypes = {
sh = ["${pkgs.shellcheck}/bin/shellcheck"]; sh = [ "${pkgs.shellcheck}/bin/shellcheck" ];
}; };
}; };
cSpell = {diagnosticLevel = "hint";}; cSpell = { diagnosticLevel = "hint"; };
}; };
}; };
home.sessionVariables = rec { home.sessionVariables = rec {