lib.crossLists is deprecated, use lib.cartesianProductOfSets instead

I’m getting this error when using the crossLists function, but it’s not clear how cartesianProductOfSets is a replacement. Is this deprecation message correct?

Here’s what I’m doing:

nix-repl> region = [ "us-east-1" "us-east-2" "us-west-2" ]
nix-repl> env = [ "dev" "test" "prod" ]
nix-repl> :p lib.lists.crossLists (x: y: "${y}-${x}") [ region env ]
[ "dev-us-east-1" "test-us-east-1" "prod-us-east-1" "dev-us-east-2" "test-us-east-2" "prod-us-east-2" "dev-us-west-2" "test-us-west-2" "prod-us-west-2" ]

Now I can get to the same result with the suggested alternative, but not straight away.

nix-repl> xs = lib.attrsets.cartesianProductOfSets { inherit region env; }

nix-repl> lib.lists.map (x: "${x.env}-${x.region}") xs
[ "dev-us-east-1" "dev-us-east-2" "dev-us-west-2" "test-us-east-1" "test-us-east-2" "test-us-west-2" "prod-us-east-1" "prod-us-east-2" "prod-us-west-2" ]

Is this how it’s supposed to be done? or am I missing something?

$ nix --version
nix (Nix) 2.20.5

I’ve found the PR where this function was deprecated: lib/attrsets: add cartesianProductOfSets function by tfc · Pull Request #110787 · NixOS/nixpkgs · GitHub

@Infinisil sorry to bother 3 years later :smile: , but given your suggestion there, do you recall if this use case was considered? It seems the original scenario was quite different than mine.

There’s a change in that PR that represents my use case actually, and the answer seems to be use map + cartesianProductOfSets as opposed to just the latter.

I can submit a PR to fix the deprecated message if this is the intention, but wondering can we still have a non-deprecated lib.lists.crossLists function implemented on top of those two functions?

Indeed looks like it’s not quite the same. I think your PR is justified, I’ll take a look :slight_smile:

1 Like