anchor.diff:  with pkgs.lib;
   
   let
  -
     cfg = config.services.logstash;
  -
  -  listToConfig = list: "[ " + (concatStringsSep ", " (map exprToConfig list)) + " ]";
  -
  -  hashToConfig = attrs:
  -    let
  -      attrNameToConfigList = name:
  -        [ (exprToConfig name)  (exprToConfig (getAttr name attrs)) ];
  -    in
  -      "[ " +
  -      (concatStringsSep ", " (map attrNameToConfigList (attrNames attrs))) +
  -      " ]";
  -
  -  valueToConfig = nvpair: let name = nvpair.name; value = nvpair.value; in
  -    if (isAttrs value) && ((!(value ? __type)) || value.__type == "repeated")
  -      then ''
  -        ${name} {
  -          ${exprToConfig value}
  -        }
  -      ''
  -      else "${name} => ${exprToConfig value}";
  -
  -  repeatedAttrsToConfig = values:
  -      concatStringsSep "\n" (map valueToConfig values);
  -
  -  attrsToConfig = attrs:
  -    let
  -      attrToConfig = name: valueToConfig {
  -        inherit name;
  -        value = (getAttr name attrs);
  -      };
  -    in
  -      concatStringsSep "\n" (map attrToConfig (attrNames attrs));
  -
  -  exprToConfig = expr:
  -    let
  -      isCustomType = expr: (isAttrs expr) && (expr ? __type);
  -
  -      isFloat = expr: (isCustomType expr) && (expr.__type == "float");
  -
  -      isHash = expr: (isCustomType expr) && (expr.__type == "hash");
  -
  -      isRepeatedAttrs = expr: (isCustomType expr) && (expr.__type == "repeated");
  -    in
  -      if builtins.isBool expr then (if expr then "true" else "false") else
  -      if builtins.isString expr then ''"${expr}"'' else
  -      if builtins.isInt expr then toString expr else
  -      if isFloat expr then expr.value else
  -      if isList expr then listToConfig expr else
  -      if isHash expr then hashToConfig expr.value else
  -      if isRepeatedAttrs expr then repeatedAttrsToConfig expr.values
  -      else attrsToConfig expr;
  -
  -  mergeConfigs = configs:
  -    let
  -      op = attrs: newAttrs:
  -        let
  -          isRepeated = newAttrs ? __type && newAttrs.__type == "repeated";
  -        in {
  -            values = attrs.values ++ (if isRepeated then newAttrs.values else
  -              map (name: { inherit name; value = getAttr name newAttrs; })
  -              (attrNames newAttrs));
  -          };
  -    in (foldl op { values = []; } configs) // { __type = "repeated"; };
   
   in
   
  
positive.code: 
    ###### implementation
  
    config = mkMerge [ {
      lib.logstash = {
        mkFloat = stringRep: { __type = "float"; value = stringRep; };
  
        mkHash = attrs: { __type = "hash"; value = attrs; };
  
        mkNameValuePairs = mergeConfigs;
      };
    } ( mkIf cfg.enable {
      systemd.services.logstash = with pkgs; {
        description = "Logstash daemon";
  
        wantedBy = [ "multi-user.target" ];
  
        path = [ jre ];
  
        script = "cd /tmp && exec java -jar ${logstash} agent -f ${writeText "logstash.conf" ''
          input {
            ${exprToConfig cfg.inputConfig}
          }
  
          filter {
            ${exprToConfig cfg.filterConfig}
          }
  
          output {
            ${exprToConfig cfg.outputConfig}
          }
        ''} &> /var/log/logstash.log";
      };
    })];
  }
  
negative.code:     services.logstash = {
        enable = mkOption {
          default = false;
          description = "Enable logstash";
        };
  
        inputConfig = mkOption {
          default = ''stdin { type => "example" }'';
          description = "Logstash input configuration";
        };
  
        filterConfig = mkOption {
          default = ''noop {}'';
          description = "logstash filter configuration";
        };
  
        outputConfig = mkOption {
          default = ''stdout { debug => true debug_format => "json"}'';
          description = "Logstash output configuration";
        };
      };
    };
  