git.iko.soy/typeable/nixpkgs
on master help sign in
mkShell: introduce packages argument (#122180)

The distinction between the inputs doesn't really make sense in the mkShell context. Technically speaking, we should be using the nativeBuildInputs most of the time. So in order to make this function more beginner-friendly, add "packages" as an attribute, that maps to nativeBuildInputs. This commit also updates all the uses in nixpkgs.

commitc6b62f2381571cc83c6c32ef4984fabcbb4ca892 authorJonas Chevalier <zimbatm@zimbatm.com> dateThu 13 May 2021, 19:17 (6 years ago) parent7693c5d
13 files changed+40−31
doc/builders/special/mkshell.section.md+6−4 doc/languages-frameworks/dotnet.section.md+2−2 doc/languages-frameworks/python.section.md+1−1 doc/languages-frameworks/ruby.section.md+1−1 maintainers/scripts/update-luarocks-shell.nix+5−2 nixos/doc/manual/shell.nix+1−1 pkgs/applications/editors/emacs-modes/emacs2nix.nix+3−3 pkgs/applications/editors/emacs-modes/updater-emacs.nix+1−1 pkgs/applications/networking/cluster/nixops/shell.nix+2−2 pkgs/build-support/agda/default.nix+1−1 pkgs/build-support/mkshell/default.nix+14−10 pkgs/development/mobile/androidenv/examples/shell.nix+1−1 pkgs/tools/X11/opentabletdriver/shell.nix+2−2
doc/builders/special/mkshell.section.md+6−4
@@ -1,15 +1,17 @@
11# pkgs.mkShell {#sec-pkgs-mkShell}
22
3−`pkgs.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`.
3+`pkgs.mkShell` is a special kind of derivation that is only useful when using
4+it combined with `nix-shell`. It will in fact fail to instantiate when invoked
5+with `nix-build`.
46
57## Usage {#sec-pkgs-mkShell-usage}
68
79```nix
810{ pkgs ? import <nixpkgs> {} }:
911pkgs.mkShell {
10− # this will make all the build inputs from hello and gnutar
11− # available to the shell environment
12+ # specify which packages to add to the shell environment
13+ packages = [ pkgs.gnumake ];
14+ # add all the dependencies, of the given packages, to the shell environment
1215 inputsFrom = with pkgs; [ hello gnutar ];
13− buildInputs = [ pkgs.gnumake ];
1416}
1517```
doc/languages-frameworks/dotnet.section.md+2−2
@@ -10,7 +10,7 @@ with import <nixpkgs> {};
1010
1111mkShell {
1212 name = "dotnet-env";
13− buildInputs = [
13+ packages = [
1414 dotnet-sdk_3
1515 ];
1616}
@@ -25,7 +25,7 @@ with import <nixpkgs> {};
2525
2626mkShell {
2727 name = "dotnet-env";
28− buildInputs = [
28+ packages = [
2929 (with dotnetCorePackages; combinePackages [
3030 sdk_3_1
3131 sdk_3_0
doc/languages-frameworks/python.section.md+1−1
@@ -245,7 +245,7 @@ let
245245 ps.toolz
246246 ]);
247247in mkShell {
248− buildInputs = [
248+ packages = [
249249 pythonEnv
250250
251251 black
doc/languages-frameworks/ruby.section.md+1−1
@@ -106,7 +106,7 @@ let
106106 name = "gems-for-some-project";
107107 gemdir = ./.;
108108 };
109−in mkShell { buildInputs = [ gems gems.wrappedRuby ]; }
109+in mkShell { packages = [ gems gems.wrappedRuby ]; }
110110```
111111
112112With this file in your directory, you can run `nix-shell` to build and use the gems. The important parts here are `bundlerEnv` and `wrappedRuby`.
maintainers/scripts/update-luarocks-shell.nix+5−2
@@ -2,8 +2,11 @@
22}:
33with nixpkgs;
44mkShell {
5− buildInputs = [
6− bash luarocks-nix nix-prefetch-scripts parallel
5+ packages = [
6+ bash
7+ luarocks-nix
8+ nix-prefetch-scripts
9+ parallel
710 ];
811 LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path;
912}
nixos/doc/manual/shell.nix+1−1
@@ -4,5 +4,5 @@ in
44pkgs.mkShell {
55 name = "nixos-manual";
66
7− buildInputs = with pkgs; [ xmlformat jing xmloscopy ruby ];
7+ packages = with pkgs; [ xmlformat jing xmloscopy ruby ];
88}
pkgs/applications/editors/emacs-modes/emacs2nix.nix+3−3
@@ -7,10 +7,10 @@ let
77 rev = "860da04ca91cbb69c9b881a54248d16bdaaf9923";
88 sha256 = "1r3xmyk9rfgx7ln69dk8mgbnh3awcalm3r1c5ia2shlsrymvv1df";
99 };
10+in
11+pkgs.mkShell {
1012
11−in pkgs.mkShell {
12−
13− buildInputs = [
13+ packages = [
1414 pkgs.bash
1515 ];
1616
pkgs/applications/editors/emacs-modes/updater-emacs.nix+1−1
@@ -29,7 +29,7 @@ let
2929 in [ promise semaphore ]);
3030
3131in pkgs.mkShell {
32− buildInputs = [
32+ packages = [
3333 pkgs.git
3434 pkgs.nix
3535 pkgs.bash
pkgs/applications/networking/cluster/nixops/shell.nix+2−2
@@ -1,7 +1,7 @@
1−{ pkgs ? import <nixpkgs> {} }:
1+{ pkgs ? import <nixpkgs> { } }:
22
33pkgs.mkShell {
4− buildInputs = [
4+ packages = [
55 pkgs.poetry2nix.cli
66 pkgs.pkg-config
77 pkgs.libvirt
pkgs/build-support/agda/default.nix+1−1
@@ -1,6 +1,6 @@
11# Builder for Agda packages.
22
3−{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages, nixosTests }:
3+{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, ghcWithPackages, nixosTests }:
44
55with lib.strings;
66
pkgs/build-support/mkshell/default.nix+14−10
@@ -3,18 +3,22 @@
33# A special kind of derivation that is only meant to be consumed by the
44# nix-shell.
55{
6− inputsFrom ? [], # a list of derivations whose inputs will be made available to the environment
7− buildInputs ? [],
8− nativeBuildInputs ? [],
9− propagatedBuildInputs ? [],
10− propagatedNativeBuildInputs ? [],
11− ...
6+ # a list of packages to add to the shell environment
7+ packages ? [ ]
8+, # propagate all the inputs from the given derivations
9+ inputsFrom ? [ ]
10+, buildInputs ? [ ]
11+, nativeBuildInputs ? [ ]
12+, propagatedBuildInputs ? [ ]
13+, propagatedNativeBuildInputs ? [ ]
14+, ...
1215}@attrs:
1316let
1417 mergeInputs = name: lib.concatLists (lib.catAttrs name
15− ([attrs] ++ inputsFrom));
18+ ([ attrs ] ++ inputsFrom));
1619
1720 rest = builtins.removeAttrs attrs [
21+ "packages"
1822 "inputsFrom"
1923 "buildInputs"
2024 "nativeBuildInputs"
@@ -26,15 +30,15 @@ in
2630
2731stdenv.mkDerivation ({
2832 name = "nix-shell";
29− phases = ["nobuildPhase"];
33+ phases = [ "nobuildPhase" ];
3034
3135 buildInputs = mergeInputs "buildInputs";
32− nativeBuildInputs = mergeInputs "nativeBuildInputs";
36+ nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
3337 propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
3438 propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
3539
3640 shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
37− (lib.reverseList inputsFrom ++ [attrs]));
41+ (lib.reverseList inputsFrom ++ [ attrs ]));
3842
3943 nobuildPhase = ''
4044 echo
pkgs/development/mobile/androidenv/examples/shell.nix+1−1
@@ -115,7 +115,7 @@ let
115115in
116116pkgs.mkShell rec {
117117 name = "androidenv-demo";
118− buildInputs = [ androidSdk platformTools jdk pkgs.android-studio ];
118+ packages = [ androidSdk platformTools jdk pkgs.android-studio ];
119119
120120 LANG = "C.UTF-8";
121121 LC_ALL = "C.UTF-8";
pkgs/tools/X11/opentabletdriver/shell.nix+2−2
@@ -1,9 +1,9 @@
1−{ pkgs ? import ../../../../. {} }:
1+{ pkgs ? import ../../../../. { } }:
22
33with pkgs;
44
55mkShell {
6− buildInputs = [
6+ packages = [
77 common-updater-scripts
88 curl
99 dotnetCorePackages.sdk_5_0