Files
home-manager/modules/programs/dprint.nix
Rachit Kumar Verma c2cef1e7e0 dprint: add module
2026-08-05 10:21:22 -05:00

53 lines
1.4 KiB
Nix

{
pkgs,
config,
lib,
...
}:
let
inherit (lib) mkIf mkOption;
cfg = config.programs.dprint;
jsonFormat = pkgs.formats.json { };
in
{
meta.maintainers = [ lib.maintainers.rachitvrma ];
options.programs.dprint = {
enable = lib.mkEnableOption ''
dprint: a code formatter for common filetypes like markdown, toml, yaml,
and many more. See https://dprint.dev/
'';
package = lib.mkPackageOption pkgs "dprint" { nullable = true; };
settings = mkOption {
inherit (jsonFormat) type;
default = { };
description = ''
Settings to add to {file}`$XDG_CONFIG_HOME/dprint/dprint.json`.
'';
example = lib.literalExpression ''
{
excludes = [
"**/node_modules"
"**/*-lock.json"
];
plugins = [
"https://plugins.dprint.dev/typescript-0.96.1.wasm"
"''${pkgs.dprint-plugins.g-plane-pretty_yaml}/plugin.wasm"
];
json = { };
malva = { };
markdown = { };
toml = { };
typescript = { };
yaml = { };
}
'';
};
};
config = mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."dprint/dprint.json" = mkIf (cfg.settings != { }) {
source = jsonFormat.generate "hm_dprintdprint.json" cfg.settings;
};
};
}