Skip to content

Commit

Permalink
feat: allow optional arbitrary filtering of generated gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
arichtman committed Dec 29, 2024
1 parent 20c233e commit a0db108
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
downloadGitignore = arguments @ {
languages ? [],
hash ? lib.fakeSha256,
# Allow variadic arguments so we have one API
...
}:
builtins.fetchurl {
url = "https://www.toptal.com/developers/gitignore/api/${lib.concatStringsSep "," arguments.languages}";
Expand All @@ -10,8 +12,21 @@
sha256 = hash;
};
in {
# Pass-through the function
# Pass-through the function in case people want plain gitignores
inherit downloadGitignore;
sourceGitignoreList = arguments @ {
# Default this to a no-op processing where every list item is retained.
# TODO: Allow this to take a list of functions and recurse down to progressively apply them.
filterFunction ? (_: true),
...
}: let
gitignoreFile = downloadGitignore arguments;
rawText = builtins.readFile gitignoreFile;
splitList = builtins.split "\n" rawText;
pureList = builtins.filter (x: x != []) splitList;
filteredList = builtins.filter filterFunction pureList;
in
filteredList;
allAttrsSet = x: (builtins.all (v: lib.stringLength v > 0) (lib.attrValues x));
getPublicKeys = forge: username: fileHash:
# For some reason we get not one but two trailing empty lines
Expand All @@ -21,11 +36,4 @@ in {
url = "https://${forge}.com/${username}.keys";
sha256 = fileHash;
}));
sourceGitignoreList = arguments @ {...}: let
gitignoreFile = downloadGitignore arguments;
rawText = builtins.readFile gitignoreFile;
splitList = builtins.split "\n" rawText;
pureList = builtins.filter (x: x != []) splitList;
in
pureList;
}

0 comments on commit a0db108

Please sign in to comment.