Implemented [CHOOSE] options and fixed typo "generateNe/t/hackrc"
This commit is contained in:
parent
10fc937bbb
commit
56ff4000d9
122
nethack.nix
122
nethack.nix
@ -5,7 +5,9 @@
|
|||||||
}:
|
}:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
with types;
|
||||||
let
|
let
|
||||||
|
# Functions for internal use {{{
|
||||||
generateOption = name: value:
|
generateOption = name: value:
|
||||||
if isBool value
|
if isBool value
|
||||||
then "OPTIONS=${if value then "" else "!"}${name}"
|
then "OPTIONS=${if value then "" else "!"}${name}"
|
||||||
@ -22,19 +24,39 @@ let
|
|||||||
in concatStringsSep "\n" msg_type_strings;
|
in concatStringsSep "\n" msg_type_strings;
|
||||||
|
|
||||||
generateMenuColor = regex: color: ''MENUCOLOR="${regex}"=${color}'';
|
generateMenuColor = regex: color: ''MENUCOLOR="${regex}"=${color}'';
|
||||||
|
# }}}
|
||||||
|
|
||||||
generateNehackrc = nethack_config:
|
# Generate base configuration {{{
|
||||||
let all_configs = (mapAttrsToList generateOption nethack_config.options)
|
generateConfig = { nethack_options, hilite_status, msg_types, menu_colors, ... } @ config:
|
||||||
++ (mapAttrsToList generateHilite nethack_config.hilite_status)
|
let all_configs = (mapAttrsToList generateOption nethack_options)
|
||||||
++ (mapAttrsToList generateMsgType nethack_config.msg_types)
|
++ (mapAttrsToList generateHilite hilite_status)
|
||||||
++ (mapAttrsToList generateMenuColor nethack_config.menu_colors);
|
++ (mapAttrsToList generateMsgType msg_types)
|
||||||
|
++ (mapAttrsToList generateMenuColor menu_colors);
|
||||||
in concatStringsSep "\n" all_configs;
|
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
|
in
|
||||||
{
|
{
|
||||||
options.programs.nethack = with types; {
|
# Options definitions {{{
|
||||||
|
options.programs.nethack = {
|
||||||
enable = mkEnableOption "nethack configuration";
|
enable = mkEnableOption "nethack configuration";
|
||||||
|
|
||||||
options = mkOption {
|
nethack_options = mkOption {
|
||||||
type = attrsOf (oneOf [bool int str]);
|
type = attrsOf (oneOf [bool int str]);
|
||||||
default = {};
|
default = {};
|
||||||
description = "Nethack options";
|
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 = {
|
config = {
|
||||||
home.file.".nethackrc" = with config.programs.nethack; {
|
home.file.".nethackrc" = with config.programs.nethack; {
|
||||||
inherit enable;
|
inherit enable;
|
||||||
text = generateNehackrc config.programs.nethack;
|
text = generateNethackrc config.programs.nethack;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user