diff --git a/programs/alejandra.nix b/programs/alejandra.nix index 74f9b44..c779e55 100644 --- a/programs/alejandra.nix +++ b/programs/alejandra.nix @@ -1,4 +1,16 @@ -{ mkFormatterModule, ... }: +{ + lib, + pkgs, + config, + mkFormatterModule, + ... +}: +let + inherit (lib) mkOption types; + + cfg = config.programs.alejandra; + configFormat = pkgs.formats.toml { }; +in { meta.maintainers = [ ]; @@ -8,4 +20,31 @@ includes = [ "*.nix" ]; }) ]; + + options.programs.alejandra.settings = { + indentation = mkOption { + description = "Indentation style to use when formatting Nix files."; + type = types.nullOr ( + types.enum [ + "TwoSpaces" + "FourSpaces" + "Tabs" + ] + ); + default = null; + example = "FourSpaces"; + }; + }; + + config = lib.mkIf cfg.enable { + settings.formatter.alejandra.options = + let + settings = lib.filterAttrsRecursive (_: v: v != null) cfg.settings; + configFile = configFormat.generate "alejandra.toml" settings; + in + lib.optionals (settings != { }) [ + "--experimental-config" + (toString configFile) + ]; + }; }