Implemented [CHOOSE] options and fixed typo "generateNe/t/hackrc"

This commit is contained in:
xezo360hye 2024-08-05 00:07:56 +03:00
parent 10fc937bbb
commit 56ff4000d9

View File

@ -5,7 +5,9 @@
}:
with lib;
with types;
let
# Functions for internal use {{{
generateOption = name: value:
if isBool value
then "OPTIONS=${if value then "" else "!"}${name}"
@ -22,19 +24,39 @@ let
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);
# Generate base configuration {{{
generateConfig = { nethack_options, hilite_status, msg_types, menu_colors, ... } @ config:
let all_configs = (mapAttrsToList generateOption nethack_options)
++ (mapAttrsToList generateHilite hilite_status)
++ (mapAttrsToList generateMsgType msg_types)
++ (mapAttrsToList generateMenuColor menu_colors);
in concatStringsSep "\n" all_configs;
# }}}
# Generate choose options {{{
generateChoose = choose_config:
if choose_config == {} then "" else
let generateChooseOption = name: config: "[${name}]\n" + generateConfig config;
choose_options = mapAttrsToList (n: v: generateChooseOption n v) choose_config;
choose_names = concatStringsSep "," (attrNames choose_config);
in "CHOOSE=${choose_names}\n${concatStringsSep "\n" choose_options}";
# }}}
# Generate whole .nethackrc {{{
generateNethackrc = nethack_config:
let base_config = generateConfig nethack_config;
choose_config = generateChoose nethack_config.choose_options;
in base_config + "\n" + choose_config;
# }}}
in
{
options.programs.nethack = with types; {
# Options definitions {{{
options.programs.nethack = {
enable = mkEnableOption "nethack configuration";
options = mkOption {
nethack_options = mkOption {
type = attrsOf (oneOf [bool int str]);
default = {};
description = "Nethack options";
@ -91,12 +113,96 @@ in
}
'';
};
# Choose options {{{
choose_options = mkOption {
type = attrsOf (submodule {
options = {
nethack_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.*"
];
}
'';
};
};
});
default = {};
description = "Set of CHOOSE= configurations";
example = literalExpression ''
{
elf-wiz = {
options = {
race = "elf";
role = "wizard";
};
};
tourist.options = {
role = "tourist";
gender = "male";
};
}
'';
};
# }}}
};
# }}}
config = {
home.file.".nethackrc" = with config.programs.nethack; {
inherit enable;
text = generateNehackrc config.programs.nethack;
text = generateNethackrc config.programs.nethack;
};
};
}