diff --git a/lib/default.nix b/lib/default.nix index d551451..bba731a 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,35 +1,32 @@ { lib }: lib.makeExtensible (self: +with lib; +rec { + flattenListSet = imports: (flatten (concatLists (attrValues imports))); + flattenSetList = attrSet: (mapAttrs (name: value: flatten value) attrSet); - with lib; - rec { - flattenListSet = imports: (flatten (concatLists (attrValues imports))); - flattenSetList = attrSet: (mapAttrs (name: value: flatten value) attrSet); + # ["/home/user/" "/.screenrc"] -> ["home" "user" ".screenrc"] + splitPath = paths: + (filter + (s: builtins.typeOf s == "string" && s != "") + (concatMap (builtins.split "/") paths) + ); + # ["home" "user" ".screenrc"] -> "home/user/.screenrc" + dirListToPath = dirList: (concatStringsSep "/" dirList); - # ["/home/user/" "/.screenrc"] -> ["home" "user" ".screenrc"] - splitPath = paths: - (filter - (s: builtins.typeOf s == "string" && s != "") - (concatMap (builtins.split "/") paths) - ); + # ["/home/user/" "/.screenrc"] -> "/home/user/.screenrc" + concatPaths = paths: + let + prefix = optionalString (hasPrefix "/" (head paths)) "/"; + path = dirListToPath (splitPath paths); + in + prefix + path; - # ["home" "user" ".screenrc"] -> "home/user/.screenrc" - dirListToPath = dirList: (concatStringsSep "/" dirList); + sanitizeName = name: + replaceStrings + [ "." ] [ "" ] + (strings.sanitizeDerivationName (removePrefix "/" name)); - # ["/home/user/" "/.screenrc"] -> "/home/user/.screenrc" - concatPaths = paths: - let - prefix = optionalString (hasPrefix "/" (head paths)) "/"; - path = dirListToPath (splitPath paths); - in - prefix + path; - - sanitizeName = name: - replaceStrings - [ "." ] [ "" ] - (strings.sanitizeDerivationName (removePrefix "/" name)); - - getMainProgram = package: "${package}/bin/${attrByPath ["meta" "mainProgram"] package.pname package}"; - } -) + getMainProgram = package: "${package}/bin/${attrByPath ["meta" "mainProgram"] package.pname package}"; +})