Skip to content

Commit a5eabe9

Browse files
committedDec 20, 2017
mkShell: add builder
1 parent 02d361c commit a5eabe9

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
 

‎doc/default.nix

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ pkgs.stdenv.mkDerivation {
4949
outputFile = "introduction.xml";
5050
useChapters = true;
5151
}
52+
+ toDocbook {
53+
inputFile = ./shell.md;
54+
outputFile = "shell.xml";
55+
}
5256
+ toDocbook {
5357
inputFile = ./languages-frameworks/python.md;
5458
outputFile = "./languages-frameworks/python.xml";

‎doc/shell.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: stdenv.mkShell
3+
author: zimbatm
4+
date: 2017-10-30
5+
---
6+
7+
stdenv.mkShell is a special kind of derivation that is only useful when using
8+
it combined with nix-shell. It will in fact fail to instantiate when invoked
9+
with nix-build.
10+
11+
## Usage
12+
13+
```nix
14+
{ pkgs ? import <nixpkgs> {} }:
15+
pkgs.mkShell {
16+
# this will make all the build inputs from hello and gnutar available to the shell environment
17+
inputsFrom = with pkgs; [ hello gnutar ];
18+
buildInputs = [ pkgs.gnumake ];
19+
}
20+
```
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{ lib, stdenv }:
2+
3+
# A special kind of derivation that is only meant to be consumed by the
4+
# nix-shell.
5+
{
6+
inputsFrom ? [], # a list of derivations whose inputs will be made available to the environment
7+
buildInputs ? [],
8+
nativeBuildInputs ? [],
9+
propagatedBuildInputs ? [],
10+
propagatedNativeBuildInputs ? [],
11+
...
12+
}@attrs:
13+
let
14+
mergeInputs = name:
15+
let
16+
op = item: sum: sum ++ item."${name}" or [];
17+
nul = [];
18+
list = [attrs] ++ inputsFrom;
19+
in
20+
lib.foldr op nul list;
21+
22+
rest = builtins.removeAttrs attrs [
23+
"inputsFrom"
24+
"buildInputs"
25+
"nativeBuildInputs"
26+
"propagatedBuildInputs"
27+
"propagatedNativeBuildInputs"
28+
];
29+
in
30+
31+
stdenv.mkDerivation ({
32+
name = "nix-shell";
33+
phases = ["nobuildPhase"];
34+
35+
buildInputs = mergeInputs "buildInputs";
36+
nativeBuildInputs = mergeInputs "nativeBuildInputs";
37+
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
38+
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
39+
40+
nobuildPhase = ''
41+
echo
42+
echo "This derivation is not meant to be built, aborting";
43+
echo
44+
exit 1
45+
'';
46+
} // rest)

‎pkgs/top-level/all-packages.nix

+2
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ with pkgs;
311311
inherit kernel rootModules allowMissing;
312312
};
313313

314+
mkShell = callPackage ../build-supports/mkshell { };
315+
314316
nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacsPackagesNg) inherit-local; };
315317

316318
pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;

0 commit comments

Comments
 (0)
Please sign in to comment.