Added flake.nix and nethack.nix

This commit is contained in:
xezo360hye 2024-07-06 18:35:07 +03:00
parent d6f049f924
commit 81d6587c8b
2 changed files with 113 additions and 0 deletions

10
flake.nix Normal file
View File

@ -0,0 +1,10 @@
{
description = "Nethack configuration module for home-manager";
inputs = {};
outputs = inputs: {
homeManagerModules.nethack = ./nethack.nix;
};
}
# vim: et ts=2 sw=2

103
nethack.nix Normal file
View File

@ -0,0 +1,103 @@
{
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