Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { config, lib, pkgs, ... }:
- with lib;
- let
- colors = config.colors;
- BtoString = cond: if cond then "true" else "false";
- oSN = k: v: optionalString (v != null) "${k}: ${v}";
- mkColorOption = n: {
- name = "${n}";
- value = mkOption {
- type = types.nullOr types.str;
- example = "#E84F4F";
- };
- };
- takeDigits = s: toString (builtins.head
- (builtins.match "[[:alpha:]]+([[:digit:]]+)" s));
- mkColorAlias = n: {
- name = "color${takeDigits n}";
- value = mkAliasDefinitions n;
- };
- colorOptions = [
- "black0" # color0 is an alias
- "black8" # color8
- "red1" # color1
- "red9" # color9
- "green2" # color2
- "green10" # color10
- "yellow3" # color3
- "yellow11" # color11
- "blue4" # color4
- "blue12" # color12
- "magenta5" # color5
- "magenta13" # color13
- "cyan6" # color6
- "cyan14" # color14
- "white7" # color7
- "white15" # color15
- ];
- extraOptions = [
- "foreground" "foregroundHi"
- "background" "backgroundHi"
- "border" "borderHi"
- "focus" "focusHi"
- "cursor" "cursorHi"
- ];
- in {
- options.colors = {
- xresources.enable = mkEnableOption "Use Color Config in Xresources.";
- sessionVariables.enable = mkEnableOption
- "Add \"$COLOR1\", \"$RED\", \"COLOR9\", \"$REDHI\", etc... to env vars";
- } // (builtins.listToAttrs ((map mkColorAlias colorOptions) ++
- (map mkColorOption (colorOptions ++ extraOptions))));
- config = {
- home.file.".Xresources" = mkIf colors.xresources.enable {
- text = ''
- ! /etc/Xresources: DO NOT EDIT -- this file has been generated automatically.
- ! Colors
- *foreground: ${colors.foreground}
- *background: ${colors.background}
- ! Black
- *color0: ${colors.black0}
- *color8: ${colors.black8}
- ! Red
- *color1: ${colors.red1}
- *color9: ${colors.red9}
- ! Green
- *color2: ${colors.green2}
- *color10: ${colors.green10}
- ! Yellow
- *color3: ${colors.yellow3}
- *color11: ${colors.yellow11}
- ! Blue
- *color4: ${colors.blue4}
- *color12: ${colors.blue12}
- ! Magenta
- *color5: ${colors.magenta5}
- *color13: ${colors.magenta13}
- ! Cyan
- *color6: ${colors.cyan6}
- *color14: ${colors.cyan14}
- ! White
- *color7: ${colors.white7}
- *color15: ${colors.white15}
- '';
- onChange = ''
- if [[ -v DISPLAY ]] ; then
- $DRY_RUN_CMD ${pkgs.xorg.xrdb}/bin/xrdb -merge $HOME/.Xresources
- fi
- '';
- }; # End Xresources
- home.sessionVariables = mkIf colors.sessionVariables.enable {
- BLACK = "${colors.black0}";
- COLOR0 = "${colors.black0}";
- BLACKHI = "${colors.black8}";
- COLOR8 = "${colors.black8}";
- RED = "${colors.red1}";
- COLOR1 = "${colors.red1}";
- REDHI = "${colors.red9}";
- COLOR9 = "${colors.red9}";
- GREEN = "${colors.green2}";
- COLOR2 = "${colors.green2}";
- GREENHI = "${colors.green10}";
- COLOR10 = "${colors.green10}";
- YELLOW = "${colors.yellow3}";
- COLOR3 = "${colors.yellow3}";
- YELLOWHI = "${colors.yellow11}";
- COLOR11 = "${colors.yellow11}";
- BLUE = "${colors.blue4}";
- COLOR4 = "${colors.blue4}";
- BLUEHI = "${colors.blue12}";
- COLOR12 = "${colors.blue12}";
- MAGENTA = "${colors.magenta5}";
- COLOR5 = "${colors.magenta5}";
- MAGENTAHI = "${colors.magenta13}";
- COLOR13 = "${colors.magenta13}";
- CYAN = "${colors.cyan6}";
- COLOR6 = "${colors.cyan6}";
- CYANHI = "${colors.cyan14}";
- COLOR14 = "${colors.cyan14}";
- WHITE = "${colors.white7}";
- COLOR7 = "${colors.white7}";
- WHITEHI = "${colors.white15}";
- COLOR15 = "${colors.white15}";
- FOREGROUND = "${colors.foreground}";
- FOREGROUNDHI = "${colors.foregroundHi}";
- BACKGROUND = "${colors.background}";
- BACKGROUNDHI = "${colors.backgroundHi}";
- BORDER = "${colors.border}";
- BORDERHI = "${colors.borderHi}";
- FOCUS = "${colors.focus}";
- FOCUSHI = "${colors.focusHi}";
- CURSOR = "${colors.cursor}";
- CURSORHI = "${colors.cursorHi}";
- }; # End Session Variables
- }; # End Config
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement