@@ -337,6 +337,32 @@ in rec {
337337 validity.handled
338338 ({
339339 overrideAttrs = f: mkDerivation (attrs // (f attrs));
340+
341+ # A derivation that always builds successfully and whose runtime
342+ # dependencies are the original derivations build time dependencies
343+ # This allows easy building and distributing of all derivations
344+ # needed to enter a nix-shell with
345+ # nix-build shell.nix -A inputDerivation
346+ inputDerivation = derivation (derivationArg // {
347+ # Add a name in case the original drv didn't have one
348+ name = derivationArg.name or "inputDerivation";
349+ # This always only has one output
350+ outputs = [ "out" ];
351+
352+ # Propagate the original builder and arguments, since we override
353+ # them and they might contain references to build inputs
354+ _derivation_original_builder = derivationArg.builder;
355+ _derivation_original_args = derivationArg.args;
356+
357+ builder = stdenv.shell;
358+ # The bash builtin `export` dumps all current environment variables,
359+ # which is where all build input references end up (e.g. $PATH for
360+ # binaries). By writing this to $out, Nix can find and register
361+ # them as runtime dependencies (since Nix greps for store paths
362+ # through $out to find them)
363+ args = [ "-c" "export > $out" ];
364+ });
365+
340366 inherit meta passthru;
341367 } //
342368 # Pass through extra attributes that are not inputs, but