{ config, lib, ... }: with lib; let generateOption = name: value: if isBool value then "OPTIONS=${if value then "" else "!"}${name}" else "OPTIONS=${name}:${toString value}"; generateHilite = field: settings: let createHiliteString = trigger: color: "/${trigger}/${color}"; hilite_strings = mapAttrsToList combine settings; in "OPTIONS=hilite_status:${field}${concatStrings hilite_strings}"; generateMsgType = action: messages: let createMsgTypeString = message: ''MSGTYPE=${action} "${message}"''; msg_type_strings = map createMsgTypeString messages; in concatStringsSep "\n" msg_type_strings; generateMenuColor = regex: color: ''MENUCOLOR="${regex}"=${color}''; generateNehackrc = nethack_config: let all_configs = (mapAttrsToList generateOption nethack_config.options) ++ (mapAttrsToList generateHilite nethack_config.hilite_status) ++ (mapAttrsToList generateMsgType nethack_config.msg_types) ++ (mapAttrsToList generateMenuColor nethack_config.menu_colors); in concatStringsSep "\n" all_configs; in { options.programs.nethack = with types; { enable = mkEnableOption "nethack configuration"; options = mkOption { type = attrsOf (oneOf [bool int str]); default = {}; description = "Nethack options"; example = literalExpression '' { boulder = "0"; windowtype = "curses"; statuslines = 3; autopickup = true; } ''; }; hilite_status = mkOption { type = attrsOf (attrsOf str); default = {}; description = "Status hilites options set"; example = literalExpression '' { hitpoints = { "100%" = "grey&normal"; "<100%" = "green&normal"; "<66%" = "yellow&normal"; "<50%" = "orange&normal"; "<33%" = "red&bold"; }; gold.up = "yellow"; gold.down = "brown"; } ''; }; menu_colors = mkOption { type = attrsOf str; default = {}; description = "Set of MENUCOLOR= options"; }; msg_types = mkOption { type = attrsOf (listOf str); default = {}; description = "Set of MSGTYPE= options"; example = literalExpression '' { hide = [ "You swap places with .*" "Your tentacles suck the .*" ]; norep = [ "You see here a.*" ]; } ''; }; }; config = { home.file.".nethackrc" = with config.programs.nethack; { inherit enable; text = generateNehackrc config.programs.nethack; }; }; } # vim: et ts=2 sw=2