Browse Source

mkShell: add builder (#30975)

nixos-19.03
zimbatm 4 years ago committed by GitHub
parent
commit
adc5c9b83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      doc/default.nix
  2. 20
      doc/shell.md
  3. 46
      pkgs/build-support/mkshell/default.nix
  4. 2
      pkgs/top-level/all-packages.nix

4
doc/default.nix

@ -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

@ -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 ];
}
```

46
pkgs/build-support/mkshell/default.nix

@ -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)

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

@ -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;

Loading…
Cancel
Save