mirror of
https://github.com/nix-community/home-manager.git
synced 2026-09-15 03:09:21 +00:00
Stylua is deterministic formatter for Lua 5.1, 5.2, 5.3, 5.4, LuaJIT, Luau and CfxLua/FiveM Lua, built using full-moon. StyLua is inspired by the likes of prettier, it parses your Lua codebase, and prints it back out from scratch, enforcing a consistent code style.
73 lines
1.7 KiB
Nix
73 lines
1.7 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
config,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.programs.stylua;
|
|
inherit (lib)
|
|
mkOption
|
|
mkEnableOption
|
|
mkPackageOption
|
|
mkIf
|
|
types
|
|
;
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
styluaPackage =
|
|
if cfg.settings != { } then
|
|
pkgs.symlinkJoin {
|
|
name = "stylua-wrapped";
|
|
paths = [ cfg.package ];
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
postBuild = ''
|
|
wrapProgram $out/bin/stylua --add-flags '--search-parent-directories'
|
|
'';
|
|
}
|
|
else
|
|
cfg.package;
|
|
in
|
|
{
|
|
meta.maintainers = [ lib.maintainers.rachitvrma ];
|
|
|
|
options.programs.stylua = {
|
|
enable = mkEnableOption "stylua, a formatter for lua";
|
|
package = mkPackageOption pkgs "stylua" { };
|
|
finalPackage = mkOption {
|
|
readOnly = true;
|
|
visible = false;
|
|
type = types.package;
|
|
description = "Resulting stylua package";
|
|
};
|
|
settings = mkOption {
|
|
inherit (tomlFormat) type;
|
|
default = { };
|
|
example = {
|
|
call_parentheses = "Always";
|
|
collapse_simple_statement = "Always";
|
|
column_width = 85;
|
|
indent_type = "Spaces";
|
|
indent_width = 2;
|
|
line_endings = "Unix";
|
|
quote_style = "AutoPreferSingle";
|
|
};
|
|
description = ''
|
|
Configuration options that are written to {file}`XDG_CONFIG_HOME/stylua/stylua.toml`
|
|
|
|
See <https://github.com/JohnnyMorganz/StyLua#options> for more options.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
home.packages = [ cfg.finalPackage ];
|
|
|
|
programs.stylua.finalPackage = styluaPackage;
|
|
|
|
xdg.configFile."stylua/stylua.toml" = mkIf (cfg.settings != { }) {
|
|
source = tomlFormat.generate "hm_stylua.toml" cfg.settings;
|
|
};
|
|
};
|
|
}
|