stdenv: Fix handling of some special cases in "substitute"