diff --git a/modules/home/console/tools/default.nix b/modules/home/console/tools/default.nix index 45a4b5a..d79fdcf 100644 --- a/modules/home/console/tools/default.nix +++ b/modules/home/console/tools/default.nix @@ -1,6 +1,7 @@ { imports = [ ./bat.nix + ./vale.nix ./networking.nix ./btop.nix ./git.nix diff --git a/modules/home/console/tools/vale.nix b/modules/home/console/tools/vale.nix new file mode 100644 index 0000000..206ed99 --- /dev/null +++ b/modules/home/console/tools/vale.nix @@ -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"; + }; + }; + }; +} diff --git a/outputs/default.nix b/outputs/default.nix index 8104347..560febe 100644 --- a/outputs/default.nix +++ b/outputs/default.nix @@ -8,5 +8,6 @@ ./images.nix ./devshells ./templates + ./modules ]; } diff --git a/outputs/modules/default.nix b/outputs/modules/default.nix new file mode 100644 index 0000000..73b1132 --- /dev/null +++ b/outputs/modules/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./home-manager + ]; +} diff --git a/outputs/modules/home-manager/default.nix b/outputs/modules/home-manager/default.nix new file mode 100644 index 0000000..4304d29 --- /dev/null +++ b/outputs/modules/home-manager/default.nix @@ -0,0 +1,5 @@ +{ + flake.homeManagerModules = { + vale = import ./vale; + }; +} diff --git a/outputs/modules/home-manager/vale/default.nix b/outputs/modules/home-manager/vale/default.nix new file mode 100644 index 0000000..8b26b1e --- /dev/null +++ b/outputs/modules/home-manager/vale/default.nix @@ -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 {}; + }; + }; +}