mkShell: add builder (#30975)

This commit is contained in:
zimbatm 2017-12-20 23:42:07 +00:00 committed by GitHub
parent 02d361cea9
commit adc5c9b83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 0 deletions

View File

@ -49,6 +49,10 @@ pkgs.stdenv.mkDerivation {
outputFile = "introduction.xml";
useChapters = true;
}
+ toDocbook {
inputFile = ./shell.md;
outputFile = "shell.xml";
}
+ toDocbook {
inputFile = ./languages-frameworks/python.md;
outputFile = "./languages-frameworks/python.xml";

20
doc/shell.md Normal file
View File

@ -0,0 +1,20 @@
---
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 ];
}
```

View File

@ -0,0 +1,46 @@
{ 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)

View File

@ -311,6 +311,8 @@ with pkgs;
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;