Use stdenv.mkDerivation instead; it will set up a working build environment for you (see the doc for what it contains, pretty sure a C compiler is already in there).
Nearly all packages in nixpkgs use this and its derived functions to build derivations, if you need examples, look there.
I’ve not used the derivation function much myself, but I think the problem here is most likely that /bin/sh isn’t set up correctly in the sandbox, or some library required for it isn’t accessed correctly. The sandbox is hard to configure manually, which is why you should use the nixpkgs lib, unless you’re writing a distro from scratch - in which case you should probably define your own stdenv before packaging anything.
This is also why I wouldn’t recommend the nix pills for a beginner, they show off a lot of things a beginner shouldn’t worry about, while covering few of the practical packaging things