aboutsummaryrefslogtreecommitdiff
path: root/pkgs/stdenv
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-08-31 15:46:41 +0200
committerGitHub <noreply@github.com>2020-08-31 15:46:41 +0200
commit911497988fc0de87fb00c7a0ad42ce047a9e2d0d (patch)
tree6b7a6f3fde77918c849edbb2fde1b4660ed2f00c /pkgs/stdenv
parentdb79e3ee10498216cd93ffcd6aa71656b4ec0852 (diff)
parent3e1a40df7598cd24d091ef7fb0933b104aa05157 (diff)
Merge pull request #95536 from Infinisil/inputDerivation
mkDerivation: Introduce .inputDerivation for shell.nix build convenience
Diffstat (limited to 'pkgs/stdenv')
-rw-r--r--pkgs/stdenv/generic/make-derivation.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix
index 5b1c380548f4..e0266aacf34c 100644
--- a/pkgs/stdenv/generic/make-derivation.nix
+++ b/pkgs/stdenv/generic/make-derivation.nix
@@ -338,6 +338,32 @@ in rec {
validity.handled
({
overrideAttrs = f: mkDerivation (attrs // (f attrs));
+
+ # A derivation that always builds successfully and whose runtime
+ # dependencies are the original derivations build time dependencies
+ # This allows easy building and distributing of all derivations
+ # needed to enter a nix-shell with
+ # nix-build shell.nix -A inputDerivation
+ inputDerivation = derivation (derivationArg // {
+ # Add a name in case the original drv didn't have one
+ name = derivationArg.name or "inputDerivation";
+ # This always only has one output
+ outputs = [ "out" ];
+
+ # Propagate the original builder and arguments, since we override
+ # them and they might contain references to build inputs
+ _derivation_original_builder = derivationArg.builder;
+ _derivation_original_args = derivationArg.args;
+
+ builder = stdenv.shell;
+ # The bash builtin `export` dumps all current environment variables,
+ # which is where all build input references end up (e.g. $PATH for
+ # binaries). By writing this to $out, Nix can find and register
+ # them as runtime dependencies (since Nix greps for store paths
+ # through $out to find them)
+ args = [ "-c" "export > $out" ];
+ });
+
inherit meta passthru;
} //
# Pass through extra attributes that are not inputs, but