status-react/nix/lib/mkFilter.nix
Jakub Sokołowski 42fb40476c
nix: reafactoring of status-go builds
Changes:
- Fixed `nix/status-go/desktop` builds
- Dropped nimbus wrapper for `status-go` for now
- Split `status-go` builds into subfolders: `mobile`, `desktop`
- Fixed shells for desktop builds: `linux`,`macos`,`windows`
- Added `make status-go-*` targets for building them
- Moved source management to `nix/status-go/source.nix`
- Moved `nix/status-go/build.nix` into `nix/status-go/mobile`
- Moved `nix/desktop/cmake/qtkeychain` to `nix/pkgs/qtkeychain-src`
- Moved `nix/desktop/linux/linuxdeployqt` to `nix/pkgs`
- Moved `nix/desktop/linux/appimagekit` to `nix/pkgs`
- Dropped `nix/tools/mkShell.nix` since it did almost nothing
- Dropped `nix/desktop/cmake/snorenotify` since it's broken
- Moved setup from `nix/tools/mkShell.nix` to `nix/shells.nix`
- Simplified `nix/mobile/ios/status-go-shell.nix`
- Simplified `nix/status-go/default.nix`
- Updated the `nix/DETAILS.md` and `nix/README.md`
- Moved known issues to `nix/KNOWN_ISSUES.md`
- Improved output of `nix/scripts/build.sh`

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-05-04 20:55:07 +02:00

63 lines
2.1 KiB
Nix

# This Nix expression allows filtering a local directory by
# specifying dirRootsToInclude, dirsToExclude and filesToInclude.
# It also filters out symlinks to result folders created by nix-build,
# as well as backup/swap/generated files.
{ lib }:
let
inherit (lib)
any range flatten length sublist cleanSourceFilter
splitString hasPrefix removePrefix concatStringsSep;
inherit (builtins) map match;
mkFilter = {
# primary path under which all files are included, unless excluded
root,
# list of regex expressions to match files to include/exclude
include ? [ ],
exclude ? [ ], # has precedence over include
# by default we ignore Version Control System files
ignoreVCS ? true,
}:
let
# removes superfluous slashes from the path
cleanRoot = "${toString (/. + root)}/";
in path: type:
let
# unpack path: "x/y/.*" => ["x" "x/y" "x/y/.*"]
unpackPath = path:
let
tokens = splitString "/" path;
perms = range 1 (length tokens);
subPaths = builtins.map (x: sublist 0 x tokens) perms;
in builtins.map (x: concatStringsSep "/" x) subPaths;
# accept subdirs from regexes
includeSubdirs = regexes: flatten (map unpackPath regexes);
# checks all regexes in a list against str
matchesRegexes = str: regexes: (map (r: (match r str)) regexes);
# match returns empty list on match
isMatch = x: x == [ ];
# path relative to search root
relPath = removePrefix cleanRoot path;
# check if any of the regexes match the relative path
checkRegexes = regexes: any isMatch (matchesRegexes relPath regexes);
# main check methods
isRootSubdir = hasPrefix cleanRoot path;
isIncluded = checkRegexes (includeSubdirs include);
isExcluded = checkRegexes exclude;
isVCS = ignoreVCS && !cleanSourceFilter path type;
in
if !isRootSubdir then
# everything outside of root is excluded
false
else if isExcluded || isVCS then
# isExcluded has precedence over isIncluded
false
else
isIncluded;
in mkFilter