Repository: nix-community/nixpkgs-fmt (rust)

Issue:
sample: unindented `++`s after a new line
## Input
```nix
pkgs.example rec {
  buildInputs = [ pkgs.foo  ] ++
    pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [
      pkgs.bar
    ];
}
```

## Output
```nix
pkgs.example rec {
  buildInputs = [ pkgs.foo ]
  ++ pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [ # <- I'm surprised this isn't indentend two spaces
    pkgs.bar
  ]
  ;
}
```

Not so sure about this one, though.

Pull request description:
indent binops relative to right hand side
closes #33 

bors r+

Patch:
diff --git a/src/rules.rs b/src/rules.rs
index 189d879..f4ce5f9 100644
--- a/src/rules.rs
+++ b/src/rules.rs
@@ -1,12 +1,13 @@
 //! This module contains specific `super::dsl` rules for formatting nix language.
 use rnix::{
     parser::nodes::*,
-    types::{Apply, Lambda, SetEntry, TypedNode, With, Operation},
+    types::{Apply, Lambda, Operation, SetEntry, TypedNode, With},
     SyntaxElement, SyntaxKind, T,
 };
 
 use crate::{
     dsl::{self, IndentDsl, SpacingDsl},
+    pattern::Pattern,
     tree_utils::{has_newline, prev_sibling},
 };
 
@@ -106,6 +107,7 @@ pub(crate) fn indentation() -> IndentDsl {
     let mut dsl = IndentDsl::default();
     dsl
         .anchor(NODE_PAT_ENTRY)
+        .anchor(Pattern::from(rhs_of_binop))
 
         .inside(NODE_LIST).indent(VALUES)
         .inside(ENTRY_OWNERS).indent([NODE_SET_ENTRY, NODE_INHERIT])
@@ -166,6 +168,14 @@ fn set_entry_with_single_line_value(entry: SyntaxElement<'_>) -> bool {
     find(entry) == Some(true)
 }
 
+fn rhs_of_binop(rhs: SyntaxElement<'_>) -> bool {
+    fn find(rhs: SyntaxElement<'_>) -> Option<bool> {
+        let op = rhs.parent().and_then(Operation::cast)?;
+        Some(op.value2() == rhs.as_node()?)
+    }
+    find(rhs) == Some(true)
+}
+
 static ENTRY_OWNERS: &[SyntaxKind] = &[NODE_SET, NODE_LET_IN];
 
 static VALUES: &[SyntaxKind] = &[
@@ -179,24 +189,22 @@ static VALUES: &[SyntaxKind] = &[
     NODE_SET,
     NODE_STRING,
     NODE_VALUE,
+    NODE_APPLY,
 ];
 
 static BIN_OPS: &[SyntaxKind] = &[
     T!["//"],
     T![++],
-
     T![+],
     T![-],
     T![*],
     T![/],
-
     T![==],
     T![=>],
     T![<],
     T![>],
     T![<=],
     T![!=],
-
     T![||],
     T![&&],
 ];


Test patch:
diff --git a/test_data/nested_indent_after_binop.bad.nix b/test_data/nested_indent_after_binop.bad.nix
new file mode 100644
index 0000000..2065a25
--- /dev/null
+++ b/test_data/nested_indent_after_binop.bad.nix
@@ -0,0 +1,6 @@
+pkgs.example rec {
+  buildInputs = [ pkgs.foo  ] ++
+    pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [
+      pkgs.bar
+    ];
+}
\ No newline at end of file
diff --git a/test_data/nested_indent_after_binop.good.nix b/test_data/nested_indent_after_binop.good.nix
new file mode 100644
index 0000000..5245fbb
--- /dev/null
+++ b/test_data/nested_indent_after_binop.good.nix
@@ -0,0 +1,7 @@
+pkgs.example rec {
+  buildInputs = [ pkgs.foo ]
+    ++ pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [
+         pkgs.bar
+       ]
+  ;
+}