From 8066d73df086f38a866645967655ef84db6bbd86 Mon Sep 17 00:00:00 2001 From: anders130 <93037023+anders130@users.noreply.github.com> Date: Mon, 18 May 2026 13:09:45 +0200 Subject: [PATCH] feat(alejandra): add settings option for indentation config --- programs/alejandra.nix | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/programs/alejandra.nix b/programs/alejandra.nix index 74f9b449..c779e557 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) + ]; + }; }