Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdformat: maintainer add; add settings: end-of-line, number, wrapper #294

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions programs/mdformat.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{ mkFormatterModule, ... }:
{
meta.maintainers = [ ];
config,
lib,
mkFormatterModule,
...
}:
let
cfg = config.programs.mdformat;
in
{
meta.maintainers = [ "sebaszv" ];

imports = [
(mkFormatterModule {
Expand All @@ -12,4 +20,79 @@
includes = [ "*.md" ];
})
];

/*
The options and descriptions were taken from the mdformat README
on the project's GitHub page:
<https://github.com/hukkin/mdformat>
*/
options.programs.mdformat.settings =
let
inherit (lib.types)
bool
enum
int
nullOr
oneOf
;
in
{
end-of-line = lib.mkOption {
description = ''
Output file line ending mode.
'';
type = nullOr (enum [
"crlf"
"lf"
"keep"
]);
example = "lf";
default = null;
};

number = lib.mkOption {
description = ''
Apply consecutive numbering to ordered lists.
'';
type = bool;
example = false;
default = false;
};

wrap = lib.mkOption {
description = ''
Paragraph word wrap mode.
Set to an INTEGER to wrap at that length.
'';
type = nullOr (oneOf [
int
(enum [
"keep"
"no"
])
]);
example = "keep";
default = null;
};
};

config = lib.mkIf cfg.enable {
settings.formatter.mdformat.options =
let
inherit (cfg.settings)
end-of-line
number
wrap
;
in
(lib.optionals (end-of-line != null) [
"--end-of-line"
end-of-line
])
++ (lib.optional number "--number")
++ (lib.optionals (wrap != null) [
"--wrap"
(toString wrap)
]);
};
}