Skip to content

Commit c2cef1e

Browse files
Rachit Kumar Vermakhaneliman
authored andcommitted
dprint: add module
1 parent 63bd543 commit c2cef1e

6 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
time = "2026-04-14T09:20:21+00:00";
3+
condition = true;
4+
message = ''
5+
A new module is available: 'programs.dprint'.
6+
7+
dprint is a code formatter written in rust.
8+
It allows formatting toml, markdown, yaml, and many other filetypes.
9+
See https://dprint.dev/ for more.
10+
'';
11+
}

modules/programs/dprint.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
pkgs,
3+
config,
4+
lib,
5+
...
6+
}:
7+
let
8+
inherit (lib) mkIf mkOption;
9+
cfg = config.programs.dprint;
10+
jsonFormat = pkgs.formats.json { };
11+
in
12+
{
13+
meta.maintainers = [ lib.maintainers.rachitvrma ];
14+
options.programs.dprint = {
15+
enable = lib.mkEnableOption ''
16+
dprint: a code formatter for common filetypes like markdown, toml, yaml,
17+
and many more. See https://dprint.dev/
18+
'';
19+
package = lib.mkPackageOption pkgs "dprint" { nullable = true; };
20+
settings = mkOption {
21+
inherit (jsonFormat) type;
22+
default = { };
23+
description = ''
24+
Settings to add to {file}`$XDG_CONFIG_HOME/dprint/dprint.json`.
25+
'';
26+
example = lib.literalExpression ''
27+
{
28+
excludes = [
29+
"**/node_modules"
30+
"**/*-lock.json"
31+
];
32+
plugins = [
33+
"https://plugins.dprint.dev/typescript-0.96.1.wasm"
34+
"''${pkgs.dprint-plugins.g-plane-pretty_yaml}/plugin.wasm"
35+
];
36+
json = { };
37+
malva = { };
38+
markdown = { };
39+
toml = { };
40+
typescript = { };
41+
yaml = { };
42+
}
43+
'';
44+
};
45+
};
46+
config = mkIf cfg.enable {
47+
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
48+
xdg.configFile."dprint/dprint.json" = mkIf (cfg.settings != { }) {
49+
source = jsonFormat.generate "hm_dprintdprint.json" cfg.settings;
50+
};
51+
};
52+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
dprint-example-settings = ./example-dprint.nix;
3+
dprint-empty-settings = ./empty-dprint.nix;
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
programs.dprint.enable = true;
3+
nmt.script = ''
4+
assertPathNotExists home-files/.config/dprint
5+
'';
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
programs.dprint = {
3+
enable = true;
4+
settings = {
5+
excludes = [ "**/*-lock.json" ];
6+
json = {
7+
indentWidth = 2;
8+
};
9+
lineWidth = 80;
10+
plugins = [
11+
"https://plugins.dprint.dev/typescript-0.96.1.wasm"
12+
"https://plugins.dprint.dev/json-0.23.0.wasm"
13+
"https://plugins.dprint.dev/markdown-0.22.1.wasm"
14+
];
15+
typescript = {
16+
"binaryExpression.operatorPosition" = "sameLine";
17+
quoteStyle = "preferSingle";
18+
};
19+
};
20+
};
21+
nmt.script = ''
22+
assertFileContent \
23+
home-files/.config/dprint/dprint.json \
24+
${./expected-dprint.json}
25+
'';
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"excludes": [
3+
"**/*-lock.json"
4+
],
5+
"json": {
6+
"indentWidth": 2
7+
},
8+
"lineWidth": 80,
9+
"plugins": [
10+
"https://plugins.dprint.dev/typescript-0.96.1.wasm",
11+
"https://plugins.dprint.dev/json-0.23.0.wasm",
12+
"https://plugins.dprint.dev/markdown-0.22.1.wasm"
13+
],
14+
"typescript": {
15+
"binaryExpression.operatorPosition": "sameLine",
16+
"quoteStyle": "preferSingle"
17+
}
18+
}

0 commit comments

Comments
 (0)