Skip to content
Open
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
41 changes: 40 additions & 1 deletion programs/alejandra.nix
Original file line number Diff line number Diff line change
@@ -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 = [ ];

Expand All @@ -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)
];
};
}