ldap-client/npm/nodeLib/parseNpmAuthTokens.nix
Matvey Aksenov 7a1214f773 Be honest about the ldapjs dependency.
`nix-build` can run tests without any problems now. Close #1.
2016-08-27 13:56:33 +00:00

17 lines
592 B
Nix

# Parses the `NPM_AUTH_TOKENS` environment variable to discover
# namespace-token associations and turn them into an attribute set
# which we can use as an input to the fetchPrivateNpm function.
{pkgs, joinSets}:
let
inherit (pkgs.lib) flip length elemAt;
npmAuthTokens = builtins.getEnv "NPM_AUTH_TOKENS";
in
# Split the variable on ':', then turn each k=v element in
# the list into an attribute set and join all of those sets.
joinSets (
flip map (split ":" npmAuthTokens) (kvPair:
if length (split "=" kvPair) != 2 then {}
else {"${elemAt kvPair 0}" = elemAt kvPair 1;}))