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.
This commit is contained in:
Jonas Chevalier 2021-05-13 19:17:29 +02:00 committed by GitHub
parent 7693c5d59b
commit c6b62f2381
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 40 additions and 31 deletions

View file

@ -1,15 +1,17 @@
# pkgs.mkShell {#sec-pkgs-mkShell} # 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`. `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} ## Usage {#sec-pkgs-mkShell-usage}
```nix ```nix
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
pkgs.mkShell { pkgs.mkShell {
# this will make all the build inputs from hello and gnutar # specify which packages to add to the shell environment
# available to the shell environment packages = [ pkgs.gnumake ];
# add all the dependencies, of the given packages, to the shell environment
inputsFrom = with pkgs; [ hello gnutar ]; inputsFrom = with pkgs; [ hello gnutar ];
buildInputs = [ pkgs.gnumake ];
} }
``` ```

View file

@ -10,7 +10,7 @@ with import <nixpkgs> {};
mkShell { mkShell {
name = "dotnet-env"; name = "dotnet-env";
buildInputs = [ packages = [
dotnet-sdk_3 dotnet-sdk_3
]; ];
} }
@ -25,7 +25,7 @@ with import <nixpkgs> {};
mkShell { mkShell {
name = "dotnet-env"; name = "dotnet-env";
buildInputs = [ packages = [
(with dotnetCorePackages; combinePackages [ (with dotnetCorePackages; combinePackages [
sdk_3_1 sdk_3_1
sdk_3_0 sdk_3_0

View file

@ -245,7 +245,7 @@ let
ps.toolz ps.toolz
]); ]);
in mkShell { in mkShell {
buildInputs = [ packages = [
pythonEnv pythonEnv
black black

View file

@ -106,7 +106,7 @@ let
name = "gems-for-some-project"; name = "gems-for-some-project";
gemdir = ./.; gemdir = ./.;
}; };
in mkShell { buildInputs = [ gems gems.wrappedRuby ]; } 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`. 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`.

View file

@ -2,8 +2,11 @@
}: }:
with nixpkgs; with nixpkgs;
mkShell { mkShell {
buildInputs = [ packages = [
bash luarocks-nix nix-prefetch-scripts parallel bash
luarocks-nix
nix-prefetch-scripts
parallel
]; ];
LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path; LUAROCKS_NIXPKGS_PATH = toString nixpkgs.path;
} }

View file

@ -4,5 +4,5 @@ in
pkgs.mkShell { pkgs.mkShell {
name = "nixos-manual"; name = "nixos-manual";
buildInputs = with pkgs; [ xmlformat jing xmloscopy ruby ]; packages = with pkgs; [ xmlformat jing xmloscopy ruby ];
} }

View file

@ -7,10 +7,10 @@ let
rev = "860da04ca91cbb69c9b881a54248d16bdaaf9923"; rev = "860da04ca91cbb69c9b881a54248d16bdaaf9923";
sha256 = "1r3xmyk9rfgx7ln69dk8mgbnh3awcalm3r1c5ia2shlsrymvv1df"; sha256 = "1r3xmyk9rfgx7ln69dk8mgbnh3awcalm3r1c5ia2shlsrymvv1df";
}; };
in
pkgs.mkShell {
in pkgs.mkShell { packages = [
buildInputs = [
pkgs.bash pkgs.bash
]; ];

View file

@ -29,7 +29,7 @@ let
in [ promise semaphore ]); in [ promise semaphore ]);
in pkgs.mkShell { in pkgs.mkShell {
buildInputs = [ packages = [
pkgs.git pkgs.git
pkgs.nix pkgs.nix
pkgs.bash pkgs.bash

View file

@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { pkgs.mkShell {
buildInputs = [ packages = [
pkgs.poetry2nix.cli pkgs.poetry2nix.cli
pkgs.pkg-config pkgs.pkg-config
pkgs.libvirt pkgs.libvirt

View file

@ -1,6 +1,6 @@
# Builder for Agda packages. # Builder for Agda packages.
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages, nixosTests }: { stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, ghcWithPackages, nixosTests }:
with lib.strings; with lib.strings;

View file

@ -3,18 +3,22 @@
# A special kind of derivation that is only meant to be consumed by the # A special kind of derivation that is only meant to be consumed by the
# nix-shell. # nix-shell.
{ {
inputsFrom ? [], # a list of derivations whose inputs will be made available to the environment # a list of packages to add to the shell environment
buildInputs ? [], packages ? [ ]
nativeBuildInputs ? [], , # propagate all the inputs from the given derivations
propagatedBuildInputs ? [], inputsFrom ? [ ]
propagatedNativeBuildInputs ? [], , buildInputs ? [ ]
... , nativeBuildInputs ? [ ]
, propagatedBuildInputs ? [ ]
, propagatedNativeBuildInputs ? [ ]
, ...
}@attrs: }@attrs:
let let
mergeInputs = name: lib.concatLists (lib.catAttrs name mergeInputs = name: lib.concatLists (lib.catAttrs name
([attrs] ++ inputsFrom)); ([ attrs ] ++ inputsFrom));
rest = builtins.removeAttrs attrs [ rest = builtins.removeAttrs attrs [
"packages"
"inputsFrom" "inputsFrom"
"buildInputs" "buildInputs"
"nativeBuildInputs" "nativeBuildInputs"
@ -26,15 +30,15 @@ in
stdenv.mkDerivation ({ stdenv.mkDerivation ({
name = "nix-shell"; name = "nix-shell";
phases = ["nobuildPhase"]; phases = [ "nobuildPhase" ];
buildInputs = mergeInputs "buildInputs"; buildInputs = mergeInputs "buildInputs";
nativeBuildInputs = mergeInputs "nativeBuildInputs"; nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
propagatedBuildInputs = mergeInputs "propagatedBuildInputs"; propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs"; propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook" shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
(lib.reverseList inputsFrom ++ [attrs])); (lib.reverseList inputsFrom ++ [ attrs ]));
nobuildPhase = '' nobuildPhase = ''
echo echo

View file

@ -115,7 +115,7 @@ let
in in
pkgs.mkShell rec { pkgs.mkShell rec {
name = "androidenv-demo"; name = "androidenv-demo";
buildInputs = [ androidSdk platformTools jdk pkgs.android-studio ]; packages = [ androidSdk platformTools jdk pkgs.android-studio ];
LANG = "C.UTF-8"; LANG = "C.UTF-8";
LC_ALL = "C.UTF-8"; LC_ALL = "C.UTF-8";

View file

@ -1,9 +1,9 @@
{ pkgs ? import ../../../../. {} }: { pkgs ? import ../../../../. { } }:
with pkgs; with pkgs;
mkShell { mkShell {
buildInputs = [ packages = [
common-updater-scripts common-updater-scripts
curl curl
dotnetCorePackages.sdk_5_0 dotnetCorePackages.sdk_5_0