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