diff options
author | aszlig <aszlig@nix.build> | 2022-02-09 17:10:33 +0100 |
---|---|---|
committer | aszlig <aszlig@nix.build> | 2022-02-09 23:12:53 +0100 |
commit | 33f7b7172cf5623942eefb215e7d9a440bf5dd3e (patch) | |
tree | 44278b814ddf09c9ac7f311f82cb99f2139a9cc3 /pkgs/aszlig/rustfmt/default.nix | |
parent | 11e5a5ec1c78badb7d87ea39f7794337780064de (diff) |
pkgs/vim: Add rustfmt with custom default config
Since I do have a lot of projects where I use rustfmt, it gets pretty tedious to manually run "cargo fmt". Using g:rustfmt_autosave should make this less tedious but it might annoy me in the future, let's see. In addition to setting rustfmt I also added a default path for rustc, which is used whenever there is no rustc in path. This is because I usually switch between several projects which use different Rust versions and this way it will use the rustc version that is in PATH during "nix develop". For the rustfmt part I also added a small default configuration which represents my opinion on how I think Rust code should be formatted. The file is used whenever a project doesn't have a "rustfmt.toml" or ".rustfmt.toml". Unfortunately, RustFmt is broken in Vim right now[1], so I'm using the upstream project until the issue has been resolved. [1]: https://github.com/rust-lang/rust.vim/issues/446 Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/aszlig/rustfmt/default.nix')
-rw-r--r-- | pkgs/aszlig/rustfmt/default.nix | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkgs/aszlig/rustfmt/default.nix b/pkgs/aszlig/rustfmt/default.nix new file mode 100644 index 00000000..cde4d010 --- /dev/null +++ b/pkgs/aszlig/rustfmt/default.nix @@ -0,0 +1,31 @@ +{ rustfmt, runCommand, remarshal }: + +let + defaultConfig = { + format_code_in_doc_comments = true; + format_macro_matchers = true; + format_strings = true; + group_imports = "StdExternalCrate"; + match_block_trailing_comma = true; + max_width = 79; + newline_style = "Unix"; + normalize_doc_attributes = true; + overflow_delimited_expr = true; + reorder_impl_items = true; + unstable_features = true; + use_field_init_shorthand = true; + use_try_shorthand = true; + wrap_comments = true; + }; + +in rustfmt.overrideAttrs (drv: { + patches = (drv.patches or []) ++ [ ./config.patch ]; + patchFlags = [ "-p1" "-d" "src/tools/rustfmt" ]; + DEFAULT_CONFIG_FILE = runCommand "rustfmt.conf" { + nativeBuildInputs = [ remarshal ]; + value = builtins.toJSON defaultConfig; + passAsFile = [ "value" ]; + } '' + json2toml "$valuePath" "$out" + ''; +}) |