Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/collection: migrate modules to pkgs.formats #23

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
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
73 changes: 34 additions & 39 deletions modules/collection/programs/ghostty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,26 @@
pkgs,
...
}: let
inherit (lib.attrsets) isAttrs mapAttrs' mapAttrsToList nameValuePair optionalAttrs;
inherit (lib.generators) mkKeyValueDefault mkValueStringDefault toINIWithGlobalSection;
inherit (lib.attrsets) mapAttrs' nameValuePair optionalAttrs;
inherit (lib.generators) mkKeyValueDefault;
inherit (lib.modules) mkIf;
inherit (lib.options) mkEnableOption mkOption mkPackageOption;
inherit (lib.strings) concatStringsSep;
inherit (lib.types) attrs attrsOf;
inherit (lib.types) attrsOf;

mkKeyValue = key: value:
if isAttrs value
# ghostty's configuration format supports (so far) one level of nested keys as key1=key2=value
then concatStringsSep "\n" (mapAttrsToList (k: v: "${key}=${k}=${v}") value)
else (mkKeyValueDefault {mkValueString = mkValueStringDefault {};} "=" key value);

toGhosttyConf = toINIWithGlobalSection {
keyValueSettings = {
listsAsDuplicateKeys = true;
inherit mkKeyValue;
mkKeyValue = mkKeyValueDefault {} " = ";
};

keyValue = pkgs.formats.keyValue keyValueSettings;

mkThemes = themes:
mapAttrs'
(name: value:
nameValuePair
".config/ghostty/themes/${name}"
{
text = toGhosttyConf {globalSection = value.${name};};
source = keyValue.generate "ghostty-${name}-theme" value;
})
themes;

Expand All @@ -40,44 +35,44 @@ in {
package = mkPackageOption pkgs "ghostty" {};

settings = mkOption {
type = attrs;
type = keyValue.type;
default = {};
example = {
theme = "example-theme";
font-size = 10;
keybind = {
"ctrl+h" = "goto_split:left";
"ctrl+l" = "goto_split:right";
};
keybind = [
"ctrl+h=goto_split:left"
"ctrl+l=goto_split:right"
];
};
description = ''
The configuration converted to INI and written to `${config.directory}/.config/ghostty/config`.
Please reference https://ghostty.org/docs/config/reference for config options.
'';
};
themes = mkOption {
type = attrsOf attrs;
type = attrsOf keyValue.type;
default = {};
example = {
example-theme = {
palette = {
"0" = "#51576d";
"1" = "#e78284";
"2" = "#a6d189";
"3" = "#e5c890";
"4" = "#8caaee";
"5" = "#f4b8e4";
"6" = "#81c8be";
"7" = "#a5adce";
"8" = "#626880";
"9" = "#e67172";
"10" = "#8ec772";
"11" = "#d9ba73";
"12" = "#7b9ef0";
"13" = "#f2a4db";
"14" = "#5abfb5";
"15" = "#b5bfe2";
};
palette = [
"0=#51576d"
"1=#e78284"
"2=#a6d189"
"3=#e5c890"
"4=#8caaee"
"5=#f4b8e4"
"6=#81c8be"
"7=#a5adce"
"8=#626880"
"9=#e67172"
"10=#8ec772"
"11=#d9ba73"
"12=#7b9ef0"
"13=#f2a4db"
"14=#5abfb5"
"15=#b5bfe2"
];
background = "#303446";
foreground = "#c6d0f5";
cursor-color = "#f2d5cf";
Expand All @@ -97,8 +92,8 @@ in {
packages = [cfg.package];
files =
{
".config/ghostty/config".text = mkIf (cfg.settings != {}) (
toGhosttyConf {globalSection = cfg.settings;}
".config/ghostty/config".source = mkIf (cfg.settings != {}) (
keyValue.generate "ghostty-config" cfg.settings
);
}
// optionalAttrs (cfg.themes != {}) (mkThemes cfg.themes);
Expand Down
10 changes: 5 additions & 5 deletions modules/collection/programs/vscode.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
}: let
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
inherit (lib.types) attrsOf anything;
inherit (builtins) toJSON;

json = pkgs.formats.json {};

cfg = config.rum.programs.vscode;
in {
Expand All @@ -17,7 +17,7 @@ in {
package = mkPackageOption pkgs "vscode" {};

settings = mkOption {
type = attrsOf anything;
type = json.type;
default = {};
example = {
"editor.fontFamily" = "Fira Code Nerdfont";
Expand All @@ -38,8 +38,8 @@ in {
config = mkIf cfg.enable {
packages = [cfg.package];
files = {
".config/Code/User/settings.json".text = mkIf (cfg.settings != {}) (
toJSON cfg.settings
".config/Code/User/settings.json".source = mkIf (cfg.settings != {}) (
json.generate "settings.json" cfg.settings
);
};
};
Expand Down