Adding a crosscompiler into nix-shell environment

I need to have Aarch64 cross gcc into shell environment. It’s required for tests, the main code should be compiled with the regular native compiler so the method described here is not what I want.

I found a topic where this code was suggested for user environment:

nix-env -iA --arg crossSystem '{ config = "aarch64-unknown-linux-gnu"; }'

It actually works and adds cross compiler into user environment – but I need to add it to the environment generated by a nix script. I tried to reproduce it in a script:

    nixpkgs = import <nixpkgs> {};
    aarch64cc = { crossSystem = { config = "aarch64-unknown-linux-gnu"; }; };
    nixpkgs.mkShell { buildInputs = [ aarch64cc ]; }

but it fails with an error:

error: attempt to call something which is not a function but a set

How can I have a crosscompiler in shell environments? In general, how to debug such issues?

You may want something like:

  nixpkgs = import <nixpkgs> {};
  cross = import <nixpkgs> {
    crossSystem = { config = "aarch64-unknown-linux-gnu"; };
nixpkgs.mkShell {
  buildInputs = [

You’re evaluating twice <nixpkgs>, once for your current architecture, once for your target architecture.
Then, in buildInputs, you’re adding the compiler which can build (“buildPackages”) for your target architecture.