Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. { config, lib, pkgs, ... }:
  2. with lib;
  3.  
  4. let
  5.  
  6. colors = config.colors;
  7.  
  8. BtoString = cond: if cond then "true" else "false";
  9.  
  10. oSN = k: v: optionalString (v != null) "${k}: ${v}";
  11.  
  12. mkColorOption = n: {
  13. name = "${n}";
  14. value = mkOption {
  15. type = types.nullOr types.str;
  16. example = "#E84F4F";
  17. };
  18. };
  19.  
  20. takeDigits = s: toString (builtins.head
  21. (builtins.match "[[:alpha:]]+([[:digit:]]+)" s));
  22.  
  23. mkColorAlias = n: {
  24. name = "color${takeDigits n}";
  25. value = mkAliasDefinitions n;
  26. };
  27.  
  28. colorOptions = [
  29. "black0" # color0 is an alias
  30. "black8" # color8
  31. "red1" # color1
  32. "red9" # color9
  33. "green2" # color2
  34. "green10" # color10
  35. "yellow3" # color3
  36. "yellow11" # color11
  37. "blue4" # color4
  38. "blue12" # color12
  39. "magenta5" # color5
  40. "magenta13" # color13
  41. "cyan6" # color6
  42. "cyan14" # color14
  43. "white7" # color7
  44. "white15" # color15
  45. ];
  46. extraOptions = [
  47. "foreground" "foregroundHi"
  48. "background" "backgroundHi"
  49. "border" "borderHi"
  50. "focus" "focusHi"
  51. "cursor" "cursorHi"
  52. ];
  53.  
  54. in {
  55.  
  56. options.colors = {
  57. xresources.enable = mkEnableOption "Use Color Config in Xresources.";
  58. sessionVariables.enable = mkEnableOption
  59. "Add \"$COLOR1\", \"$RED\", \"COLOR9\", \"$REDHI\", etc... to env vars";
  60. } // (builtins.listToAttrs ((map mkColorAlias colorOptions) ++
  61. (map mkColorOption (colorOptions ++ extraOptions))));
  62.  
  63. config = {
  64.  
  65. home.file.".Xresources" = mkIf colors.xresources.enable {
  66. text = ''
  67. ! /etc/Xresources: DO NOT EDIT -- this file has been generated automatically.
  68.  
  69. ! Colors
  70. *foreground: ${colors.foreground}
  71. *background: ${colors.background}
  72. ! Black
  73. *color0: ${colors.black0}
  74. *color8: ${colors.black8}
  75. ! Red
  76. *color1: ${colors.red1}
  77. *color9: ${colors.red9}
  78. ! Green
  79. *color2: ${colors.green2}
  80. *color10: ${colors.green10}
  81. ! Yellow
  82. *color3: ${colors.yellow3}
  83. *color11: ${colors.yellow11}
  84. ! Blue
  85. *color4: ${colors.blue4}
  86. *color12: ${colors.blue12}
  87. ! Magenta
  88. *color5: ${colors.magenta5}
  89. *color13: ${colors.magenta13}
  90. ! Cyan
  91. *color6: ${colors.cyan6}
  92. *color14: ${colors.cyan14}
  93. ! White
  94. *color7: ${colors.white7}
  95. *color15: ${colors.white15}
  96. '';
  97. onChange = ''
  98. if [[ -v DISPLAY ]] ; then
  99. $DRY_RUN_CMD ${pkgs.xorg.xrdb}/bin/xrdb -merge $HOME/.Xresources
  100. fi
  101. '';
  102. }; # End Xresources
  103.  
  104. home.sessionVariables = mkIf colors.sessionVariables.enable {
  105. BLACK = "${colors.black0}";
  106. COLOR0 = "${colors.black0}";
  107. BLACKHI = "${colors.black8}";
  108. COLOR8 = "${colors.black8}";
  109. RED = "${colors.red1}";
  110. COLOR1 = "${colors.red1}";
  111. REDHI = "${colors.red9}";
  112. COLOR9 = "${colors.red9}";
  113. GREEN = "${colors.green2}";
  114. COLOR2 = "${colors.green2}";
  115. GREENHI = "${colors.green10}";
  116. COLOR10 = "${colors.green10}";
  117. YELLOW = "${colors.yellow3}";
  118. COLOR3 = "${colors.yellow3}";
  119. YELLOWHI = "${colors.yellow11}";
  120. COLOR11 = "${colors.yellow11}";
  121. BLUE = "${colors.blue4}";
  122. COLOR4 = "${colors.blue4}";
  123. BLUEHI = "${colors.blue12}";
  124. COLOR12 = "${colors.blue12}";
  125. MAGENTA = "${colors.magenta5}";
  126. COLOR5 = "${colors.magenta5}";
  127. MAGENTAHI = "${colors.magenta13}";
  128. COLOR13 = "${colors.magenta13}";
  129. CYAN = "${colors.cyan6}";
  130. COLOR6 = "${colors.cyan6}";
  131. CYANHI = "${colors.cyan14}";
  132. COLOR14 = "${colors.cyan14}";
  133. WHITE = "${colors.white7}";
  134. COLOR7 = "${colors.white7}";
  135. WHITEHI = "${colors.white15}";
  136. COLOR15 = "${colors.white15}";
  137. FOREGROUND = "${colors.foreground}";
  138. FOREGROUNDHI = "${colors.foregroundHi}";
  139. BACKGROUND = "${colors.background}";
  140. BACKGROUNDHI = "${colors.backgroundHi}";
  141. BORDER = "${colors.border}";
  142. BORDERHI = "${colors.borderHi}";
  143. FOCUS = "${colors.focus}";
  144. FOCUSHI = "${colors.focusHi}";
  145. CURSOR = "${colors.cursor}";
  146. CURSORHI = "${colors.cursorHi}";
  147. }; # End Session Variables
  148.  
  149. }; # End Config
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement