4 changed files with 72 additions and 0 deletions
@ -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 ]; |
||||
} |
||||
``` |
@ -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) |
Loading…
Reference in new issue