Avoid top-level `with ...;` in pkgs/build-support/nix-gitignore/default.nix

We also renamed `filter` (as a name of a parameter) to `predicate` following the naming suggestion in code review. It's better!

Since it's not part of an attrset, the name can change with no impact to semantics, since it can't be observed with `builtins.functionArgs`.

```
$ nix-repl
Nix 2.21.0
Type :? for help.
nix-repl> f = x: y: z: (x + y + z)

nix-repl> builtins.functionArgs f
{ }

nix-repl> :doc builtins.functionArgs
Synopsis: builtins.functionArgs f

Return a set containing the names of the formal arguments expected by the function f. The value of each attribute is a Boolean denoting whether the corresponding argument has a default value. For instance, functionArgs ({ x, y ?
123}: ...) = { x = false; y = true; }.

"Formal argument" here refers to the attributes pattern-matched by the function. Plain lambdas are not included, e.g. functionArgs (x: ...) = { }.
```

authored by philiptaron.tngl.sh and committed by Valentin Gagarin 997e54a4 869e5566

+40 -17
+40 -17
pkgs/build-support/nix-gitignore/default.nix
··· 7 7 # - zero or more directories. For example, "a/**/b" matches "a/b", 8 8 # - "a/x/b", "a/x/y/b" and so on. 9 9 10 - with builtins; 10 + let 11 + inherit (builtins) filterSource; 12 + 13 + inherit (lib) 14 + concatStringsSep 15 + elemAt 16 + filter 17 + head 18 + isList 19 + length 20 + optionals 21 + optionalString 22 + pathExists 23 + readFile 24 + removePrefix 25 + replaceStrings 26 + stringLength 27 + sub 28 + substring 29 + toList 30 + trace 31 + ; 11 32 12 - let 33 + 34 + inherit (lib.strings) match split typeOf; 35 + 13 36 debug = a: trace a a; 14 37 last = l: elemAt l ((length l) - 1); 15 38 in rec { ··· 17 40 filterPattern = patterns: root: 18 41 (name: _type: 19 42 let 20 - relPath = lib.removePrefix ((toString root) + "/") name; 43 + relPath = removePrefix ((toString root) + "/") name; 21 44 matches = pair: (match (head pair) relPath) != null; 22 45 matched = map (pair: [(matches pair) (last pair)]) patterns; 23 46 in ··· 45 68 escs = "\\*?"; 46 69 splitString = 47 70 let recurse = str : [(substring 0 1 str)] ++ 48 - (lib.optionals (str != "") (recurse (substring 1 (stringLength(str)) str) )); 71 + (optionals (str != "") (recurse (substring 1 (stringLength(str)) str) )); 49 72 in str : recurse str; 50 73 chars = s: filter (c: c != "" && !isList c) (splitString s); 51 74 escape = s: map (c: "\\" + c) (chars s); ··· 66 89 handleSlashPrefix = l: 67 90 let 68 91 split = (match "^(/?)(.*)" l); 69 - findSlash = l: lib.optionalString ((match ".+/.+" l) == null) l; 92 + findSlash = l: optionalString ((match ".+/.+" l) == null) l; 70 93 hasSlash = mapAroundCharclass findSlash l != l; 71 94 in 72 95 (if (elemAt split 0) == "/" || hasSlash ··· 94 117 gitignoreCompileIgnore = file_str_patterns: root: 95 118 let 96 119 onPath = f: a: if typeOf a == "path" then f a else a; 97 - str_patterns = map (onPath readFile) (lib.toList file_str_patterns); 120 + str_patterns = map (onPath readFile) (toList file_str_patterns); 98 121 in concatStringsSep "\n" str_patterns; 99 122 100 - gitignoreFilterPure = filter: patterns: root: name: type: 123 + gitignoreFilterPure = predicate: patterns: root: name: type: 101 124 gitignoreFilter (gitignoreCompileIgnore patterns root) root name type 102 - && filter name type; 125 + && predicate name type; 103 126 104 127 # This is a very hacky way of programming this! 105 128 # A better way would be to reuse existing filtering by making multiple gitignore functions per each root. ··· 145 168 ''); 146 169 147 170 withGitignoreFile = patterns: root: 148 - lib.toList patterns ++ [ ".git" ] ++ [(root + "/.gitignore")]; 171 + toList patterns ++ [ ".git" ] ++ [(root + "/.gitignore")]; 149 172 150 173 withRecursiveGitignoreFile = patterns: root: 151 - lib.toList patterns ++ [ ".git" ] ++ [(compileRecursiveGitignore root)]; 174 + toList patterns ++ [ ".git" ] ++ [(compileRecursiveGitignore root)]; 152 175 153 176 # filterSource derivatives 154 177 155 - gitignoreFilterSourcePure = filter: patterns: root: 156 - filterSource (gitignoreFilterPure filter patterns root) root; 178 + gitignoreFilterSourcePure = predicate: patterns: root: 179 + filterSource (gitignoreFilterPure predicate patterns root) root; 157 180 158 - gitignoreFilterSource = filter: patterns: root: 159 - gitignoreFilterSourcePure filter (withGitignoreFile patterns root) root; 181 + gitignoreFilterSource = predicate: patterns: root: 182 + gitignoreFilterSourcePure predicate (withGitignoreFile patterns root) root; 160 183 161 - gitignoreFilterRecursiveSource = filter: patterns: root: 162 - gitignoreFilterSourcePure filter (withRecursiveGitignoreFile patterns root) root; 184 + gitignoreFilterRecursiveSource = predicate: patterns: root: 185 + gitignoreFilterSourcePure predicate (withRecursiveGitignoreFile patterns root) root; 163 186 164 - # "Filter"-less alternatives 187 + # "Predicate"-less alternatives 165 188 166 189 gitignoreSourcePure = gitignoreFilterSourcePure (_: _: true); 167 190 gitignoreSource = patterns: let type = typeOf patterns; in