git.iko.soy/typeable/nixpkgs
on master help sign in
mkDerivation: Introduce .inputDerivation for shell.nix build convenience

This introduces the .inputDerivation attribute on all derivations created with mkDerivation. This is another derivation that can always build successfully and whose runtime dependencies are the build time dependencies of the original derivation. This allows easy building and distributing of all derivations needed to enter a nix-shell with nix-build shell.nix -A inputDerivation

commit3e1a40df7598cd24d091ef7fb0933b104aa05157 authorSilvan Mosberger <contact@infinisil.com> dateSat 15 Aug 2020, 23:11 (6 years ago) parentb7be00a
1 file changed+26
pkgs/stdenv/generic/make-derivation.nix+26
pkgs/stdenv/generic/make-derivation.nix+26
@@ -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