Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E003: Invalid Binary Operator

Severity: Error

cannot apply `+` to `string` and `int`

A binary operator was applied to operands whose types don’t support that operation. Nix’s + is overloaded (works on ints, floats, strings, and paths), but the two operands must be compatible.

Common causes

  • Mixing strings and numbers with + without converting:
    "count: " + 42   # string + int is not allowed
    
  • Using arithmetic operators (-, *, /) on non-numeric types.
  • Using // (attribute set merge) where + (addition or concatenation) was intended, or vice versa.

How to fix

  • For string concatenation with non-strings, use string interpolation:
    "count: ${toString 42}"
    
  • Make sure both operands of arithmetic operators are numeric (int or float).
  • Use ++ for list concatenation, // for attribute set merging.