1
0
Fork 0
nixos-config/nixos/roles/home-assistant/jinja.nix
2022-03-11 01:10:01 +01:00

15 lines
557 B
Nix

lib: let
inherit (builtins) foldl';
in rec {
case = default: attrs: ''
{% if ${lib.concatStringsSep "\n{% elseif " (lib.mapAttrsToList (condition: result: "${condition} %}\n ${result}") attrs)}
{% else %}
${default}
{% endif %}
'';
if' = condition: ifTrue: ifFalse: case ifFalse {"${condition}" = ifTrue;};
or = lhs: rhs: "(${lhs} or ${rhs})";
and = lhs: rhs: "(${lhs} and ${rhs})";
isState = entity: state: "is_state('${entity}','${state}')";
isStates = entity: states: foldl' or "false" (map (isState entity) states);
}