1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-31 04:04:32 +00:00

godot: init module and lib

This adds the `programs.godot` module with support for editor
configurations and text editor themes. It's accompanied by the `godot`
library module which exposes constructors for godot data types.
This commit is contained in:
bricked 2025-02-26 19:41:10 +01:00
parent 74f0a8546e
commit 2f0999538a
No known key found for this signature in database
GPG key ID: 7B4D2A02BB0EC28C
4 changed files with 215 additions and 0 deletions

View file

@ -15,4 +15,5 @@ rec {
shell = import ./shell.nix { inherit lib; };
zsh = import ./zsh.nix { inherit lib; };
nushell = import ./nushell.nix { inherit lib; };
godot = import ./godot.nix { inherit lib; };
}

76
modules/lib/godot.nix Normal file
View file

@ -0,0 +1,76 @@
{ lib }:
let
inherit (lib)
concatMapStringsSep escape replaceStrings boolToString floatToString
concatStringsSep mapAttrsToList;
inherit (builtins) mapAttrs;
mkPrimitive = t: v: {
_type = "godotData";
type = t;
value = v;
__toString = self: toString self.value;
};
in rec {
isGodotData = v: v._type or "" == "godotData";
mkValue = v:
if builtins.isBool v then
mkBool v
else if builtins.isInt v then
mkInt v
else if builtins.isFloat v then
mkFloat v
else if builtins.isString v then
mkString v
else if builtins.isList v then
mkList v
else if builtins.isAttrs v && (v._type or "") == "godotData" then
v
else if builtins.isAttrs v then
mkAttrs v
else
null;
mkList = elems:
mkPrimitive "list" (map mkValue elems) // {
__toString = self: "[${concatMapStringsSep ", " toString self.value}]";
};
mkAttrs = attrs:
mkPrimitive "attrs" (mapAttrs (name: mkValue) attrs) // {
__toString = self:
"{${
concatStringsSep ", "
(mapAttrsToList (name: value: "${mkString name}: ${value}")
self.value)
}}";
};
mkBool = v:
mkPrimitive "bool" v // {
__toString = self: boolToString self.value;
};
mkString = v:
let
sanitize = s: replaceStrings [ "\n" ] [ "\\n" ] (escape [ ''"'' "\\" ] s);
in mkPrimitive "string" v // {
__toString = self: ''"${sanitize self.value}"'';
};
mkInt = mkPrimitive "int";
mkFloat = mkPrimitive "float";
mkCall = name: args:
mkPrimitive "call" { inherit name args; } // {
__toString = self:
"${self.value.name}(${
concatMapStringsSep ", " toString self.value.args
})";
};
}

View file

@ -118,6 +118,7 @@ let
./programs/gnome-shell.nix
./programs/gnome-terminal.nix
./programs/go.nix
./programs/godot.nix
./programs/gpg.nix
./programs/gradle.nix
./programs/granted.nix

137
modules/programs/godot.nix Normal file
View file

@ -0,0 +1,137 @@
{ config, lib, pkgs, ... }:
let
inherit (lib)
literalExpression mkEnableOption mkOption mkIf types hm mapAttrsToList
splitString mkOptionDefault singleton concatMapStringsSep mkMerge mapAttrs'
nameValuePair;
inherit (hm.godot) mkValue;
inherit (builtins) concatStringsSep typeOf toString head;
cfg = config.programs.godot;
primitiveType = with types; oneOf [ str int float bool attrs ];
primitiveTypeOrAttrs = with types;
either primitiveType (attrsOf primitiveType);
composedType = with types;
either primitiveTypeOrAttrs (listOf primitiveTypeOrAttrs);
dataType = with types; coercedTo composedType mkValue attrs;
# See https://docs.godotengine.org/en/latest/contributing/development/file_formats/tscn.html.
genResources = concatMapStringsSep "\n\n" genResource;
genResource = { type, attributes ? { }, data ? { } }:
concatStringsSep "\n" ([
(genHeader { inherit type attributes; })
] ++ (mapAttrsToList (name: value: "${name} = ${value}") data));
genHeader = { type, attributes }:
"[${
concatStringsSep " " ([ type ]
++ (mapAttrsToList (name: val: "${name}=${mkValue val}") attributes))
}]";
in {
meta.maintainers = [ hm.maintainers.bricked ];
options.programs.godot = {
enable = mkEnableOption "Godot";
package = lib.mkPackageOption pkgs "godot_4" { };
version = lib.mkOption {
type = types.str;
description = ''
Semantic version of the Godot package.
'';
internal = true;
};
settings = mkOption {
type = with types; nullOr (attrsOf dataType);
description = ''
Attribute set of godot editor settings.
For a list of available options see https://docs.godotengine.org/en/stable/classes/class_editorsettings.html.
Primitive values, lists and attrs work as expected. For function calls, 'lib.hm.godot.mkCall name args' is used.
'';
example = literalExpression ''
{
"resource_local_to_scene" = false;
"interface/editor/editor_language" = "en";
"interface/editor/main_font_size" = 14;
"interface/theme/accent_color" = lib.hm.godot.mkCall "Color" [ 0.5, 0.5, 1.0, 1.0 ];
"text_editor/theme/color_theme" = "Dracula";
}'';
};
textThemes = mkOption {
type = with types;
attrsOf (submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
description = ''
The name of the text editor theme.
'';
example = "Dracula";
default = name;
};
settings = mkOption {
type = with types; attrsOf dataType;
description = ''
Attribute set of text editor theme data.
'';
example = {
text_color = "cdd6f4ff";
number_color = "fab387ff";
};
};
};
}));
description = ''
Attribute set of text editor themes.
The default text editor theme can be defined using the "text_editor/theme/color_theme" setting.
'';
default = { };
};
};
config = mkIf cfg.enable {
programs.godot.version =
mkOptionDefault (head (splitString "-" cfg.package.version));
home.packages = [ cfg.package ];
xdg.configFile = {
"godot/editor_settings-${cfg.version}.tres".text =
mkIf (cfg.settings != null) (genResources [
{
type = "gd_resource";
attributes = {
type = "EditorSettings";
format = 3;
};
}
{
type = "resource";
data = cfg.settings;
}
]);
} // mapAttrs' (name: theme:
nameValuePair "godot/text_editor_themes/${theme.name}.tet" {
text = genResource {
type = "color_theme";
data = theme.settings;
};
}) cfg.textThemes;
};
}