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.

Changed files
+40 -31
doc
maintainers
nixos
doc
manual
pkgs
applications
editors
networking
cluster
nixops
build-support
agda
mkshell
development
mobile
androidenv
examples
tools
X11
opentabletdriver
+6 -4
doc/builders/special/mkshell.section.md
···
# pkgs.mkShell {#sec-pkgs-mkShell}
-
`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`.
## Usage {#sec-pkgs-mkShell-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 ];
}
```
···
# pkgs.mkShell {#sec-pkgs-mkShell}
+
`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`.
## Usage {#sec-pkgs-mkShell-usage}
```nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
+
# specify which packages to add to the shell environment
+
packages = [ pkgs.gnumake ];
+
# add all the dependencies, of the given packages, to the shell environment
inputsFrom = with pkgs; [ hello gnutar ];
}
```
+2 -2
doc/languages-frameworks/dotnet.section.md
···
mkShell {
name = "dotnet-env";
-
buildInputs = [
dotnet-sdk_3
];
}
···
mkShell {
name = "dotnet-env";
-
buildInputs = [
(with dotnetCorePackages; combinePackages [
sdk_3_1
sdk_3_0
···
mkShell {
name = "dotnet-env";
+
packages = [
dotnet-sdk_3
];
}
···
mkShell {
name = "dotnet-env";
+
packages = [
(with dotnetCorePackages; combinePackages [
sdk_3_1
sdk_3_0
+1 -1
doc/languages-frameworks/python.section.md
···
ps.toolz
]);
in mkShell {
-
buildInputs = [
pythonEnv
black
···
ps.toolz
]);
in mkShell {
+
packages = [
pythonEnv
black
+1 -1
doc/languages-frameworks/ruby.section.md
···
name = "gems-for-some-project";
gemdir = ./.;
};
-
in mkShell { buildInputs = [ gems gems.wrappedRuby ]; }
```
With this file in your directory, you can run `nix-shell` to build and use the gems. The important parts here are `bundlerEnv` and `wrappedRuby`.
···
name = "gems-for-some-project";
gemdir = ./.;
};
+
in mkShell { packages = [ gems gems.wrappedRuby ]; }
```
With this file in your directory, you can run `nix-shell` to build and use the gems. The important parts here are `bundlerEnv` and `wrappedRuby`.
+5 -2
maintainers/scripts/update-luarocks-shell.nix
···
}:
with nixpkgs;
mkShell {
-
buildInputs = [
-
bash luarocks-nix nix-prefetch-scripts parallel
];
LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path;
}
···
}:
with nixpkgs;
mkShell {
+
packages = [
+
bash
+
luarocks-nix
+
nix-prefetch-scripts
+
parallel
];
LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path;
}
+1 -1
nixos/doc/manual/shell.nix
···
pkgs.mkShell {
name = "nixos-manual";
-
buildInputs = with pkgs; [ xmlformat jing xmloscopy ruby ];
}
···
pkgs.mkShell {
name = "nixos-manual";
+
packages = with pkgs; [ xmlformat jing xmloscopy ruby ];
}
+3 -3
pkgs/applications/editors/emacs-modes/emacs2nix.nix
···
rev = "860da04ca91cbb69c9b881a54248d16bdaaf9923";
sha256 = "1r3xmyk9rfgx7ln69dk8mgbnh3awcalm3r1c5ia2shlsrymvv1df";
};
-
-
in pkgs.mkShell {
-
buildInputs = [
pkgs.bash
];
···
rev = "860da04ca91cbb69c9b881a54248d16bdaaf9923";
sha256 = "1r3xmyk9rfgx7ln69dk8mgbnh3awcalm3r1c5ia2shlsrymvv1df";
};
+
in
+
pkgs.mkShell {
+
packages = [
pkgs.bash
];
+1 -1
pkgs/applications/editors/emacs-modes/updater-emacs.nix
···
in [ promise semaphore ]);
in pkgs.mkShell {
-
buildInputs = [
pkgs.git
pkgs.nix
pkgs.bash
···
in [ promise semaphore ]);
in pkgs.mkShell {
+
packages = [
pkgs.git
pkgs.nix
pkgs.bash
+2 -2
pkgs/applications/networking/cluster/nixops/shell.nix
···
-
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
-
buildInputs = [
pkgs.poetry2nix.cli
pkgs.pkg-config
pkgs.libvirt
···
+
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
+
packages = [
pkgs.poetry2nix.cli
pkgs.pkg-config
pkgs.libvirt
+1 -1
pkgs/build-support/agda/default.nix
···
# Builder for Agda packages.
-
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages, nixosTests }:
with lib.strings;
···
# Builder for Agda packages.
+
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, ghcWithPackages, nixosTests }:
with lib.strings;
+14 -10
pkgs/build-support/mkshell/default.nix
···
# 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: lib.concatLists (lib.catAttrs name
-
([attrs] ++ inputsFrom));
rest = builtins.removeAttrs attrs [
"inputsFrom"
"buildInputs"
"nativeBuildInputs"
···
stdenv.mkDerivation ({
name = "nix-shell";
-
phases = ["nobuildPhase"];
buildInputs = mergeInputs "buildInputs";
-
nativeBuildInputs = mergeInputs "nativeBuildInputs";
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
-
(lib.reverseList inputsFrom ++ [attrs]));
nobuildPhase = ''
echo
···
# A special kind of derivation that is only meant to be consumed by the
# nix-shell.
{
+
# a list of packages to add to the shell environment
+
packages ? [ ]
+
, # propagate all the inputs from the given derivations
+
inputsFrom ? [ ]
+
, buildInputs ? [ ]
+
, nativeBuildInputs ? [ ]
+
, propagatedBuildInputs ? [ ]
+
, propagatedNativeBuildInputs ? [ ]
+
, ...
}@attrs:
let
mergeInputs = name: lib.concatLists (lib.catAttrs name
+
([ attrs ] ++ inputsFrom));
rest = builtins.removeAttrs attrs [
+
"packages"
"inputsFrom"
"buildInputs"
"nativeBuildInputs"
···
stdenv.mkDerivation ({
name = "nix-shell";
+
phases = [ "nobuildPhase" ];
buildInputs = mergeInputs "buildInputs";
+
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
+
(lib.reverseList inputsFrom ++ [ attrs ]));
nobuildPhase = ''
echo
+1 -1
pkgs/development/mobile/androidenv/examples/shell.nix
···
in
pkgs.mkShell rec {
name = "androidenv-demo";
-
buildInputs = [ androidSdk platformTools jdk pkgs.android-studio ];
LANG = "C.UTF-8";
LC_ALL = "C.UTF-8";
···
in
pkgs.mkShell rec {
name = "androidenv-demo";
+
packages = [ androidSdk platformTools jdk pkgs.android-studio ];
LANG = "C.UTF-8";
LC_ALL = "C.UTF-8";
+2 -2
pkgs/tools/X11/opentabletdriver/shell.nix
···
-
{ pkgs ? import ../../../../. {} }:
with pkgs;
mkShell {
-
buildInputs = [
common-updater-scripts
curl
dotnetCorePackages.sdk_5_0
···
+
{ pkgs ? import ../../../../. { } }:
with pkgs;
mkShell {
+
packages = [
common-updater-scripts
curl
dotnetCorePackages.sdk_5_0