From 81d6587c8b09b330d6aec6050554113e889d8faa Mon Sep 17 00:00:00 2001 From: xezo360hye Date: Sat, 6 Jul 2024 18:35:07 +0300 Subject: [PATCH] Added flake.nix and nethack.nix --- flake.nix | 10 +++++ nethack.nix | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 flake.nix create mode 100644 nethack.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ef0228f --- /dev/null +++ b/flake.nix @@ -0,0 +1,10 @@ +{ + description = "Nethack configuration module for home-manager"; + + inputs = {}; + + outputs = inputs: { + homeManagerModules.nethack = ./nethack.nix; + }; +} +# vim: et ts=2 sw=2 diff --git a/nethack.nix b/nethack.nix new file mode 100644 index 0000000..85c242b --- /dev/null +++ b/nethack.nix @@ -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