default.nix: use nixpkgs lib

This commit is contained in:
Wroclaw 2025-01-13 00:46:20 +01:00
parent 33708ea922
commit 3e37f1fbd4

View file

@ -3,16 +3,8 @@
# if evaluating inside the store, import the outputs.nix file
let
contains = str: substr: let
str_length = builtins.stringLength str;
substr_length = builtins.stringLength substr;
listOfPossibleSubstrings = builtins.genList (i: builtins.substring i substr_length str) (str_length - substr_length + 1);
in if substr_length > str_length then false else builtins.any (x: x == substr) listOfPossibleSubstrings;
endsWith = str: substr: let
str_length = builtins.stringLength str;
substr_length = builtins.stringLength substr;
in if substr_length > str_length then false else builtins.substring (str_length - substr_length) str_length str == substr;
# Ideally this file should not depend on nixpkgs lib itself, but I like the utilities here
lib = (import "${(import ./inputs.nix {}).nixpkgs}/lib");
gitignore = builtins.filter (v:
# ignore comments and empty lines
@ -32,11 +24,11 @@ let
if pattern == "*" then true
else if pattern == ".*" then true
else if pattern == "*.*" then true
else if builtins.substring 0 2 pattern == "*." then endsWith path (builtins.substring 0 2 pattern)
else if contains pattern "*" then abort unsupportedPatternMessage
else if builtins.substring 0 2 pattern == "*." then lib.hasSuffix (builtins.substring 0 2 pattern) path
else if lib.hasInfix "*" pattern then abort unsupportedPatternMessage
else if patternLength > 2 && builtins.substring 0 2 pattern == "./" then abort unsupportedPatternMessage
else if patternLength > 1 && builtins.substring 0 1 pattern == "/" then abort unsupportedPatternMessage
else contains path pattern
else lib.hasInfix pattern path
) gitignore;
currentFilePath = (builtins.unsafeGetAttrPos "any" { any = "any"; }).file;