mkShell: add builder (#30975)

zimbatm adc5c9b8 02d361ce

Changed files
+72
doc
pkgs
build-support
mkshell
top-level
+4
doc/default.nix
···
useChapters = true;
}
+ toDocbook {
+
inputFile = ./shell.md;
+
outputFile = "shell.xml";
+
}
+
+ toDocbook {
inputFile = ./languages-frameworks/python.md;
outputFile = "./languages-frameworks/python.xml";
}
+20
doc/shell.md
···
+
---
+
title: stdenv.mkShell
+
author: zimbatm
+
date: 2017-10-30
+
---
+
+
stdenv.mkShell is a special kind of derivation that is only useful when using
+
it combined with nix-shell. It will in fact fail to instantiate when invoked
+
with nix-build.
+
+
## Usage
+
+
```nix
+
{ pkgs ? import <nixpkgs> {} }:
+
pkgs.mkShell {
+
# this will make all the build inputs from hello and gnutar available to the shell environment
+
inputsFrom = with pkgs; [ hello gnutar ];
+
buildInputs = [ pkgs.gnumake ];
+
}
+
```
+46
pkgs/build-support/mkshell/default.nix
···
+
{ lib, stdenv }:
+
+
# A special kind of derivation that is only meant to be consumed by the
+
# nix-shell.
+
{
+
inputsFrom ? [], # a list of derivations whose inputs will be made available to the environment
+
buildInputs ? [],
+
nativeBuildInputs ? [],
+
propagatedBuildInputs ? [],
+
propagatedNativeBuildInputs ? [],
+
...
+
}@attrs:
+
let
+
mergeInputs = name:
+
let
+
op = item: sum: sum ++ item."${name}" or [];
+
nul = [];
+
list = [attrs] ++ inputsFrom;
+
in
+
lib.foldr op nul list;
+
+
rest = builtins.removeAttrs attrs [
+
"inputsFrom"
+
"buildInputs"
+
"nativeBuildInputs"
+
"propagatedBuildInputs"
+
"propagatedNativeBuildInputs"
+
];
+
in
+
+
stdenv.mkDerivation ({
+
name = "nix-shell";
+
phases = ["nobuildPhase"];
+
+
buildInputs = mergeInputs "buildInputs";
+
nativeBuildInputs = mergeInputs "nativeBuildInputs";
+
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
+
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
+
+
nobuildPhase = ''
+
echo
+
echo "This derivation is not meant to be built, aborting";
+
echo
+
exit 1
+
'';
+
} // rest)
+2
pkgs/top-level/all-packages.nix
···
inherit kernel rootModules allowMissing;
};
+
mkShell = callPackage ../build-supports/mkshell { };
+
nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacsPackagesNg) inherit-local; };
pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;