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