modules: vale init

This commit is contained in:
ooks-io 2025-01-29 23:16:46 +11:00
parent 46cf664bb5
commit f55e861fdd
6 changed files with 160 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{ {
imports = [ imports = [
./bat.nix ./bat.nix
./vale.nix
./networking.nix ./networking.nix
./btop.nix ./btop.nix
./git.nix ./git.nix

View file

@ -0,0 +1,29 @@
{self, ...}: {
imports = [
self.homeManagerModules.vale
];
programs.vale = {
enable = true;
styles = [
"microsoft"
"write-good"
"alex"
"readability"
"proselint"
];
globalSettings = {
MinAlertLevel = "suggestion";
};
formatSettings = {
"*.{md,txt,tex}" = {
BasedOnStyles = [
"proselint"
"alex"
"Readability"
"Microsoft"
];
"Microsoft.Acronyms" = "NO";
};
};
};
}

View file

@ -8,5 +8,6 @@
./images.nix ./images.nix
./devshells ./devshells
./templates ./templates
./modules
]; ];
} }

View file

@ -0,0 +1,5 @@
{
imports = [
./home-manager
];
}

View file

@ -0,0 +1,5 @@
{
flake.homeManagerModules = {
vale = import ./vale;
};
}

View file

@ -0,0 +1,119 @@
{
lib,
pkgs,
config,
...
}: let
inherit (lib) filterAttrs mapAttrs mkEnableOption mkOption mkIf;
inherit (lib.generators) toINIWithGlobalSection;
inherit (lib.types) attrsOf submodule listOf str enum package nullOr;
filterNullRec = let
# helper to check if a value should be kept
isNonNull = value:
if builtins.isAttrs value
then filterNullRec value != {}
else value != null;
in
attrs:
filterAttrs
(_: isNonNull)
(mapAttrs (
name: value:
if builtins.isAttrs value
then filterNullRec value
else value
)
attrs);
listToStr = list: builtins.concatStringsSep "," list;
availableStyles = [
"alex"
"google"
"joblint"
"proselint"
"write-good"
"readability"
"microsoft"
];
formatOptions = submodule {
freeformType = attrsOf str;
options = {
BasedOnStyles = mkOption {
type = nullOr (listOf str);
default = null;
apply = listToStr;
};
BlockIgnores = mkOption {
type = nullOr str;
default = null;
};
TokenIgnores = mkOption {
type = nullOr str;
default = null;
};
CommentDelimiters = mkOption {
type = nullOr str;
default = null;
};
Transform = mkOption {
type = nullOr str;
default = null;
};
};
};
cfg = config.programs.vale;
in {
options.programs.vale = {
enable = mkEnableOption "Enable vale linter";
package = mkOption {
type = package;
default = pkgs.vale;
};
styles = mkOption {
type = listOf (enum availableStyles);
default = [];
description = "Style packages to include.";
};
globalSettings = {
MinAlertLevel = mkOption {
type = enum [
"suggestion"
"warning"
"error"
];
default = "suggestion";
description = "Set the minimum alert level that Vale will report.";
};
IgnoredScopes = mkOption {
type = nullOr (listOf str);
default = null;
description = "Specifies inline-level HTML tags to ignore.";
apply = v:
if v != null
then listToStr
else null;
};
};
formatSettings = mkOption {
type = nullOr (attrsOf formatOptions);
default = null;
};
};
config = mkIf cfg.enable {
home.packages = [
(cfg.package.withStyles (
styles:
map (name: styles.${name}) config.programs.vale.styles
))
];
xdg.configFile."vale/.vale.ini".text = toINIWithGlobalSection {} {
globalSection = filterNullRec cfg.globalSettings;
sections =
if cfg.formatSettings != null
then filterNullRec cfg.formatSettings
else {};
};
};
}