Compare commits

...

1 commit

Author SHA1 Message Date
Anthony Rodriguez
235a130cd9
modules/languages/nix: change nixpkgs-fmt to nixfmt (rfc-style) 2024-10-18 19:58:57 +02:00
2 changed files with 24 additions and 6 deletions

View file

@ -196,3 +196,7 @@ everyone.
[Soliprem](https://github.com/Soliprem)
- Add LSP and Treesitter support for R under `vim.languages.R`.
[nezia1](https://github.com/nezia1):
- Replace [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) with [nixfmt](https://github.com/NixOS/nixfmt) (nixfmt-rfc-style).

View file

@ -5,6 +5,7 @@
...
}: let
inherit (builtins) attrNames;
inherit (lib) concatStringsSep;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
@ -62,10 +63,10 @@
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
},
''}
${optionalString (cfg.format.type == "nixpkgs-fmt")
${optionalString (cfg.format.type == "nixfmt")
''
formatting = {
command = {"${cfg.format.package}/bin/nixpkgs-fmt"},
command = {"${cfg.format.package}/bin/nixfmt"},
},
''}
},
@ -90,9 +91,16 @@
'';
};
nixpkgs-fmt = {
package = pkgs.nixpkgs-fmt;
# Never need to use null-ls for nixpkgs-fmt
nixfmt = {
package = pkgs.nixfmt-rfc-style;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.nixfmt.with({
command = "${cfg.format.package}/bin/nixfmt"
})
)
'';
};
};
@ -152,7 +160,7 @@ in {
type = mkOption {
description = "Nix formatter to use";
type = enum (attrNames formats);
type = enum (attrNames formats ++ ["nixpkgs-fmt"]); # temporary, so it can be asserted against
default = defaultFormat;
};
package = mkOption {
@ -175,6 +183,12 @@ in {
config = mkIf cfg.enable (mkMerge [
{
assertions = [
{
assertion = cfg.format.type != "nixpkgs-fmt";
message = "nixpkgs-fmt has been archived and replaced with nixfmt. Please use one of the following instead: ${concatStringsSep ", " (attrNames formats)}";
}
];
vim.pluginRC.nix = ''
vim.api.nvim_create_autocmd("FileType", {
pattern = "nix",