From ea9d9495e5726d1c97ba4ba95d3db2f061af1158 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Tue, 18 Jun 2024 11:07:11 +0300 Subject: [PATCH] Home : Use lib.generators for configs. --- user/common/default.nix | 12 +++--- user/common/editorconfig/default.nix | 45 +++++++++++--------- user/common/foot/default.nix | 31 ++++++++------ user/common/keyd/default.nix | 4 +- user/common/keyd/module/DRG.nix | 61 ++++++++++++++------------- user/common/keyd/module/Firefox.nix | 45 ++++++++++---------- user/common/keyd/module/Jetbrains.nix | 49 ++++++++++----------- user/common/mako/default.nix | 28 ++++++------ user/common/top/btop/default.nix | 2 +- user/common/top/htop/default.nix | 2 +- 10 files changed, 148 insertions(+), 131 deletions(-) diff --git a/user/common/default.nix b/user/common/default.nix index e2f70e7f..8ce767c4 100644 --- a/user/common/default.nix +++ b/user/common/default.nix @@ -28,13 +28,13 @@ in { homeDirectory = homeDir; stateVersion = const.stateVersion; file = { - ".config/btop/btop.conf".text = btop.config; - ".config/foot/foot.ini".text = foot.config; + ".config/btop/btop.conf".text = btop.text; + ".config/foot/foot.ini".text = foot.text; ".config/gtk-3.0/bookmarks".text = gtk3.bookmarks; - ".config/htop/htoprc".text = htop.config; - ".config/keyd/app.conf".text = keyd.config; - ".config/mako/config".text = mako.config; - ".editorconfig".text = editorconfig.config; + ".config/htop/htoprc".text = htop.text; + ".config/keyd/app.conf".text = keyd.text; + ".config/mako/config".text = mako.text; + ".editorconfig".text = editorconfig.text; ".parallel/will-cite".text = ""; "media/template".source = ./template; }; diff --git a/user/common/editorconfig/default.nix b/user/common/editorconfig/default.nix index 6d1207b9..f29627f7 100644 --- a/user/common/editorconfig/default.nix +++ b/user/common/editorconfig/default.nix @@ -1,25 +1,32 @@ -{ util, ... }: { - config = util.trimTabs '' - root = true +{ lib, ... }: { + text = lib.generators.toINIWithGlobalSection {} { + globalSection.root = true; - [*] - end_of_line = lf - charset = utf-8 - indent_style = tab - indent_size = 2 - insert_final_newline = true - trim_trailing_whitespace = true + sections = { + "*" = { + end_of_line = "lf"; + charset = "utf-8"; + indent_style = "tab"; + indent_size = "2"; + insert_final_newline = "true"; + trim_trailing_whitespace = "true"; + }; - [Makefile] - indent_size = 2 + Makefile = { + indent_size = 2; + }; - [*.{nix,js}] - indent_size = 2 + "*.{nix,js}" = { + indent_size = 2; + }; - [*.{lua,kt,kts,rs,py}] - indent_size = 4 + "*.{lua,kt,kts,rs,py}" = { + indent_size = 4; + }; - [*.{sh,md}] - indent_size = 8 - ''; + "*.{sh,md}" = { + indent_size = 8; + }; + }; + }; } diff --git a/user/common/foot/default.nix b/user/common/foot/default.nix index 95ced213..6d7970a6 100644 --- a/user/common/foot/default.nix +++ b/user/common/foot/default.nix @@ -1,17 +1,22 @@ -{ style, setting, util, ... }: let +{ style, setting, lib, ... }: let dpiaware = if setting.foot.font.dpi then "yes" else "no"; in { - config = util.trimTabs '' - font=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} - # font-bold=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} - font-italic=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} - font-bold-italic=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} - dpi-aware=${dpiaware} - font-size-adjustment=${toString(setting.foot.font.step)} + text = lib.generators.toINIWithGlobalSection {} { + globalSection = { + font = "${style.font.monospace.name}:size=${toString(style.font.size.terminal)}"; + # font-bold = "${style.font.monospace.name}:size=${toString(style.font.size.terminal)}"; + font-italic = "${style.font.monospace.name}:size=${toString(style.font.size.terminal)}"; + font-bold-italic = "${style.font.monospace.name}:size=${toString(style.font.size.terminal)}"; + dpi-aware = dpiaware; + font-size-adjustment = setting.foot.font.step; + }; - [colors] - alpha=${toString(style.opacity.terminal)} - background=${style.color.bg.dark} - foreground=${style.color.fg.light} - ''; + sections = { + colors = { + alpha = style.opacity.terminal; + background = style.color.bg.dark; + foreground = style.color.fg.light; + }; + }; + }; } diff --git a/user/common/keyd/default.nix b/user/common/keyd/default.nix index 26294a14..d36a4a02 100644 --- a/user/common/keyd/default.nix +++ b/user/common/keyd/default.nix @@ -1,3 +1,3 @@ -{ util, setting, ... } @args: { - config = util.catText (util.ls ./module) args; +{ util, ... } @args: { + text = util.catText (util.ls ./module) args; } diff --git a/user/common/keyd/module/DRG.nix b/user/common/keyd/module/DRG.nix index f3abbd67..c1c34c30 100644 --- a/user/common/keyd/module/DRG.nix +++ b/user/common/keyd/module/DRG.nix @@ -1,31 +1,32 @@ -{ setting, ... }: { - text = '' - [steam-app-548430] - leftshift = timeout(leftcontrol, ${toString(setting.keyd.timeout.ms)}, leftshift) - alt.w = macro(enter 10ms r enter) - alt.a = macro(enter 10ms N o enter) - alt.s = macro(enter 10ms W a i t enter) - alt.d = macro(enter 10ms Y e s enter) - alt.q = macro(enter 10ms S o r r y ! enter) - alt.e = macro(enter 10ms T h a n k s ! enter) - alt.g = macro(enter 10ms g g enter) - alt.z = macro(enter 10ms < space L e f t enter) - alt.x = macro(enter 10ms > space H e r e space < enter) - alt.c = macro(enter 10ms > space R i g h t enter) - alt.r = macro(enter 10ms N e e d space m o r e space a m m o enter) - alt.t = macro(enter 10ms M a y space I space t a k e space e x t r a ? enter) - alt.v = macro(enter 10ms A F K enter) - alt.f = macro(enter 10ms I space n e e d space h e l p ! enter) - alt.b = macro(enter 10ms I ' m space b a c k enter) - alt.l = macro(enter 10ms L e a f space l o v e r enter) - alt.j = macro(enter 10ms G o o d space j o b enter) - alt.k = macro(enter 10ms O k a y enter) - alt.1 = macro(enter 10ms L e t ' s space d o space t h i s space T e x a s space s t y l e ! enter) - alt.2 = macro(enter 10ms H e c k space y e s ! enter) - alt.3 = macro(enter 10ms J u s t space a space s i d e - j o b space w h i l e 10ms space w a i t i n g space f o r space a space s e x space u p d a t e . enter) - alt.4 = macro(enter 10ms < 3 enter) - alt.[ = macro(enter 10ms W h a t space i s space c r u n c h y 10ms space o n space t h e space o u t s i d e , 10ms space g o o e y space o n space 10ms t h e space i n s i d e ? enter) - alt.] = macro(enter 10ms Q ' r o n a r space S h e l l b a c k ! enter) - alt.m = macro(enter 10ms I space r e p l y space u s i n g space m a c r o s . 10ms space U s e space s o f t w a r e space l i k e space k e y d , 10ms space o r space b u y space a space Q M K space k e y b o a r d . enter) - ''; +{ setting, lib, ... }: { + text = lib.generators.toINI {} { + steam-app-548430 = { + "alt.1" = "macro(enter 10ms L e t ' s space d o space t h i s space T e x a s space s t y l e ! enter)"; + "alt.2" = "macro(enter 10ms H e c k space y e s ! enter)"; + "alt.3" = "macro(enter 10ms J u s t space a space s i d e - j o b space w h i l e 10ms space w a i t i n g space f o r space a space s e x space u p d a t e . enter)"; + "alt.4" = "macro(enter 10ms < 3 enter)"; + "alt.[" = "macro(enter 10ms W h a t space i s space c r u n c h y 10ms space o n space t h e space o u t s i d e , 10ms space g o o e y space o n space 10ms t h e space i n s i d e ? enter)"; + "alt.]" = "macro(enter 10ms Q ' r o n a r space S h e l l b a c k ! enter)"; + "alt.a" = "macro(enter 10ms N o enter)"; + "alt.b" = "macro(enter 10ms I ' m space b a c k enter)"; + "alt.c" = "macro(enter 10ms > space R i g h t enter)"; + "alt.d" = "macro(enter 10ms Y e s enter)"; + "alt.e" = "macro(enter 10ms T h a n k s ! enter)"; + "alt.f" = "macro(enter 10ms I space n e e d space h e l p ! enter)"; + "alt.g" = "macro(enter 10ms g g enter)"; + "alt.j" = "macro(enter 10ms G o o d space j o b enter)"; + "alt.k" = "macro(enter 10ms O k a y enter)"; + "alt.l" = "macro(enter 10ms L e a f space l o v e r enter)"; + "alt.m" = "macro(enter 10ms I space r e p l y space u s i n g space m a c r o s . 10ms space U s e space s o f t w a r e space l i k e space k e y d , 10ms space o r space b u y space a space Q M K space k e y b o a r d . enter)"; + "alt.q" = "macro(enter 10ms S o r r y ! enter)"; + "alt.r" = "macro(enter 10ms N e e d space m o r e space a m m o enter)"; + "alt.s" = "macro(enter 10ms W a i t enter)"; + "alt.t" = "macro(enter 10ms M a y space I space t a k e space e x t r a ? enter)"; + "alt.v" = "macro(enter 10ms A F K enter)"; + "alt.w" = "macro(enter 10ms r enter)"; + "alt.x" = "macro(enter 10ms > space H e r e space < enter)"; + "alt.z" = "macro(enter 10ms < space L e f t enter)"; + leftshift = "timeout(leftcontrol, ${toString(setting.keyd.timeout.ms)}, leftshift)"; + }; + }; } diff --git a/user/common/keyd/module/Firefox.nix b/user/common/keyd/module/Firefox.nix index d375dc7e..d5864b04 100644 --- a/user/common/keyd/module/Firefox.nix +++ b/user/common/keyd/module/Firefox.nix @@ -1,23 +1,24 @@ -{ ... }: { - text = '' - [firefox] - alt.E = C-S-pagedown - alt.N = S-f3 - alt.Q = C-S-pageup - alt.a = A-left - alt.d = A-right - alt.e = C-pagedown - alt.capslock = C-t - alt.f = C-f - alt.l = A-S-a - alt.n = f3 - alt.p = C-S-l - alt.q = C-pageup - alt.r = C-f5 - alt.s = down - alt.space = f6 - alt.u = C-S-t - alt.w = up - alt.x = C-w - ''; +{ lib, ... }: { + text = lib.generators.toINI {} { + "firefox" = { + "alt.E" = "C-S-pagedown"; + "alt.N" = "S-f3"; + "alt.Q" = "C-S-pageup"; + "alt.a" = "A-left"; + "alt.capslock" = "C-t"; + "alt.d" = "A-right"; + "alt.e" = "C-pagedown"; + "alt.f" = "C-f"; + "alt.l" = "A-S-a"; + "alt.n" = "f3"; + "alt.p" = "C-S-l"; + "alt.q" = "C-pageup"; + "alt.r" = "C-f5"; + "alt.s" = "down"; + "alt.space" = "f6"; + "alt.u" = "C-S-t"; + "alt.w" = "up"; + "alt.x" = "C-w"; + }; + }; } diff --git a/user/common/keyd/module/Jetbrains.nix b/user/common/keyd/module/Jetbrains.nix index 9811c3ad..e2872a25 100644 --- a/user/common/keyd/module/Jetbrains.nix +++ b/user/common/keyd/module/Jetbrains.nix @@ -1,25 +1,26 @@ -{ setting, ... }: { - text = '' - [jetbrains-*] - alt.a = C-A-5 - alt.c = S-escape - alt.d = S-f9 - alt.e = A-right - alt.f = C-S-f - alt.g = macro(gd) - alt.i = C-i - alt.o = C-o - alt.q = A-left - alt.n = C-A-n - alt.r = S-f10 - alt.s = C-A-s - alt.v = C-q - alt.w = C-S-A-t - alt.x = C-f4 - alt.z = C-f2 - alt./ = C-/ - alt.= = C-A-l - alt.tab = timeout(f8, ${toString(setting.keyd.timeout.ms)}, macro2(0, 0, f7)) - alt.capslock = C-A-S-insert - ''; +{ setting, lib, ... }: { + text = lib.generators.toINI {} { + "jetbrains-*" = { + "alt./" = "C-/"; + "alt.=" = "C-A-l"; + "alt.a" = "C-A-5"; + "alt.c" = "S-escape"; + "alt.capslock" = "C-A-S-insert"; + "alt.d" = "S-f9"; + "alt.e" = "A-right"; + "alt.f" = "C-S-f"; + "alt.g" = "macro(gd)"; + "alt.i" = "C-i"; + "alt.n" = "C-A-n"; + "alt.o" = "C-o"; + "alt.q" = "A-left"; + "alt.r" = "S-f10"; + "alt.s" = "C-A-s"; + "alt.tab" = "timeout(f8, ${toString(setting.keyd.timeout.ms)}, macro2(0, 0, f7))"; + "alt.v" = "C-q"; + "alt.w" = "C-S-A-t"; + "alt.x" = "C-f4"; + "alt.z" = "C-f2"; + }; + }; } diff --git a/user/common/mako/default.nix b/user/common/mako/default.nix index 3b347bd7..6b48d77c 100644 --- a/user/common/mako/default.nix +++ b/user/common/mako/default.nix @@ -1,16 +1,18 @@ -{ style, util, setting, ... }: let +{ style, lib, setting, ... }: let alpha = style.opacity.hex; in { - config = util.trimTabs '' - anchor=top-center - default-timeout=${toString(setting.popup.timeout.ms)} - font=${style.font.serif.name} ${toString(style.font.size.popup)} - background-color=#${style.color.bg.dark}${alpha} - border-color=#${style.color.bg.regular}${alpha} - text-color=#${style.color.fg.light} - height=120 - icons=0 - margin=32 - width=480 - ''; + text = lib.generators.toINIWithGlobalSection {} { + globalSection = { + anchor = "top-center"; + background-color = "#${style.color.bg.dark}${alpha}"; + border-color = "#${style.color.bg.regular}${alpha}"; + default-timeout = setting.popup.timeout.ms; + font = "${style.font.serif.name} ${toString(style.font.size.popup)}"; + height = 120; + icons = 0; + margin = 32; + text-color = "#${style.color.fg.light}"; + width = 480; + }; + }; } diff --git a/user/common/top/btop/default.nix b/user/common/top/btop/default.nix index 0ec6bf52..8445ebed 100644 --- a/user/common/top/btop/default.nix +++ b/user/common/top/btop/default.nix @@ -1,5 +1,5 @@ { setting, util, ... }: { - config = util.trimTabs '' + text = util.trimTabs '' #? Config file for btop v. 1.3.0 #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. diff --git a/user/common/top/htop/default.nix b/user/common/top/htop/default.nix index da987b9d..1e2bccbd 100644 --- a/user/common/top/htop/default.nix +++ b/user/common/top/htop/default.nix @@ -1,5 +1,5 @@ { util, ... }: { - config = util.trimTabs '' + text = util.trimTabs '' # Beware! This file is rewritten by htop when settings are changed in the interface. # The parser is also very primitive, and not human-friendly. htop_version=3.2.2