···11# pkgs.mkShell {#sec-pkgs-mkShell}
2233-`pkgs.mkShell` is a special kind of derivation that is only useful when using
44-it combined with `nix-shell`. It will in fact fail to instantiate when invoked
55-with `nix-build`.
33+`pkgs.mkShell` is a specialized `stdenv.mkDerivation` that removes some
44+repetition when using it with `nix-shell` (or `nix develop`).
6576## Usage {#sec-pkgs-mkShell-usage}
8788+Here is a common usage example:
99+910```nix
1011{ pkgs ? import <nixpkgs> {} }:
1112pkgs.mkShell {
1212- # specify which packages to add to the shell environment
1313 packages = [ pkgs.gnumake ];
1414- # add all the dependencies, of the given packages, to the shell environment
1515- inputsFrom = with pkgs; [ hello gnutar ];
1414+1515+ inputsFrom = [ pkgs.hello pkgs.gnutar ];
1616+1717+ shellHook = ''
1818+ export DEBUG=1
1919+ '';
1620}
1721```
2222+2323+## Attributes
2424+2525+* `name` (default: `nix-shell`). Set the name of the derivation.
2626+* `packages` (default: `[]`). Add executable packages to the `nix-shell` environment.
2727+* `inputsFrom` (default: `[]`). Add build dependencies of the listed derivations to the `nix-shell` environment.
2828+* `shellHook` (default: `""`). Bash statements that are executed by `nix-shell`.
2929+3030+... all the attributes of `stdenv.mkDerivation`.
3131+3232+## Building the shell
3333+3434+This derivation output will contain a text file that contains a reference to
3535+all the build inputs. This is useful in CI where we want to make sure that
3636+every derivation, and its dependencies, build properly. Or when creating a GC
3737+root so that the build dependencies don't get garbage-collected.
···117117 description = "Employee time tracking software";
118118 homepage = "https://www.timedoctor.com";
119119 license = licenses.unfree;
120120- maintainers = with maintainers; [ kamadorueda ];
120120+ maintainers = with maintainers; [ dsalaza4 ];
121121 platforms = [ "x86_64-linux" ];
122122 # gpgme for i686-linux failed to build.
123123 broken = true;
+3-3
pkgs/applications/science/logic/lean/default.nix
···2233stdenv.mkDerivation rec {
44 pname = "lean";
55- version = "3.36.0";
55+ version = "3.37.0";
6677 src = fetchFromGitHub {
88 owner = "leanprover-community";
···1111 # from. this is then used to check whether an olean file should be
1212 # rebuilt. don't use a tag as rev because this will get replaced into
1313 # src/githash.h.in in preConfigure.
1414- rev = "e948149d3d1bbdb8eac9cd103d58626a59fae3b9";
1515- sha256 = "1lcjif29lfj3myc6j63ifk8fdvylyv8g82g2dv0d85nz7mpbq47b";
1414+ rev = "e69ab934262eb6f141344fdaec98ede68a9102b6";
1515+ sha256 = "19sigzbrdl90jqk7lvl3q8j6n4nnidzwp9zzmzgq3zxxgywa2ghp";
1616 };
17171818 nativeBuildInputs = [ cmake ];
···11-{ lib, stdenv }:
11+{ lib, stdenv, buildEnv }:
2233# A special kind of derivation that is only meant to be consumed by the
44# nix-shell.
55-{
66- # a list of packages to add to the shell environment
55+{ name ? "nix-shell"
66+, # a list of packages to add to the shell environment
77 packages ? [ ]
88, # propagate all the inputs from the given derivations
99 inputsFrom ? [ ]
···1515}@attrs:
1616let
1717 mergeInputs = name:
1818- (attrs.${name} or []) ++
1818+ (attrs.${name} or [ ]) ++
1919 (lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
20202121 rest = builtins.removeAttrs attrs [
2222+ "name"
2223 "packages"
2324 "inputsFrom"
2425 "buildInputs"
···3031in
31323233stdenv.mkDerivation ({
3333- name = "nix-shell";
3434- phases = [ "nobuildPhase" ];
3434+ inherit name;
35353636 buildInputs = mergeInputs "buildInputs";
3737 nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
···4141 shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
4242 (lib.reverseList inputsFrom ++ [ attrs ]));
43434444- nobuildPhase = ''
4545- echo
4646- echo "This derivation is not meant to be built, aborting";
4747- echo
4848- exit 1
4444+ phases = [ "buildPhase" ];
4545+4646+ buildPhase = ''
4747+ echo "------------------------------------------------------------" >>$out
4848+ echo " WARNING: the existence of this path is not guaranteed." >>$out
4949+ echo " It is an internal implementation detail for pkgs.mkShell." >>$out
5050+ echo "------------------------------------------------------------" >>$out
5151+ echo >> $out
5252+ # Record all build inputs as runtime dependencies
5353+ export >> $out
4954 '';
5055} // rest)
···11-{ lib, stdenv, fetchurl, pkg-config
22-11+{ lib
22+, stdenv
33+, fetchurl
44+, buildPackages
55+, pkg-config
36, abiVersion ? "6"
44-, mouseSupport ? false
55-, unicode ? true
67, enableStatic ? stdenv.hostPlatform.isStatic
77-, enableShared ? !enableStatic
88, withCxx ? !stdenv.hostPlatform.useAndroidPrebuilt
99-1010-, gpm
1111-1212-, buildPackages
99+, mouseSupport ? false, gpm
1010+, unicodeSupport ? true
1311}:
14121513stdenv.mkDerivation rec {
···3129 setOutputFlags = false; # some aren't supported
32303331 configureFlags = [
3434- (lib.withFeature enableShared "shared")
3232+ (lib.withFeature (!enableStatic) "shared")
3533 "--without-debug"
3634 "--enable-pc-files"
3735 "--enable-symlinks"
3836 "--with-manpage-format=normal"
3937 "--disable-stripping"
4040- ] ++ lib.optional unicode "--enable-widec"
3838+ ] ++ lib.optional unicodeSupport "--enable-widec"
4139 ++ lib.optional (!withCxx) "--without-cxx"
4240 ++ lib.optional (abiVersion == "5") "--with-abi-version=5"
4341 ++ lib.optional stdenv.hostPlatform.isNetBSD "--enable-rpath"
···4947 # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris:
5048 CFLAGS = lib.optionalString stdenv.isSunOS "-D_XOPEN_SOURCE_EXTENDED";
51495252- depsBuildBuild = [ buildPackages.stdenv.cc ];
5050+ depsBuildBuild = [
5151+ buildPackages.stdenv.cc
5252+ ];
5353+5354 nativeBuildInputs = [
5455 pkg-config
5556 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
5657 buildPackages.ncurses
5758 ];
5959+5860 buildInputs = lib.optional (mouseSupport && stdenv.isLinux) gpm;
59616062 preConfigure = ''
···147149 rm "$out"/lib/*.a
148150 '';
149151150150- meta = {
152152+ meta = with lib; {
153153+ homepage = "https://www.gnu.org/software/ncurses/";
151154 description = "Free software emulation of curses in SVR4 and more";
152152-153155 longDescription = ''
154154- The Ncurses (new curses) library is a free software emulation of
155155- curses in System V Release 4.0, and more. It uses Terminfo
156156- format, supports pads and color and multiple highlights and
157157- forms characters and function-key mapping, and has all the other
158158- SYSV-curses enhancements over BSD Curses.
156156+ The Ncurses (new curses) library is a free software emulation of curses in
157157+ System V Release 4.0, and more. It uses Terminfo format, supports pads and
158158+ color and multiple highlights and forms characters and function-key
159159+ mapping, and has all the other SYSV-curses enhancements over BSD Curses.
159160160160- The ncurses code was developed under GNU/Linux. It has been in
161161- use for some time with OpenBSD as the system curses library, and
162162- on FreeBSD and NetBSD as an external package. It should port
163163- easily to any ANSI/POSIX-conforming UNIX. It has even been
164164- ported to OS/2 Warp!
161161+ The ncurses code was developed under GNU/Linux. It has been in use for
162162+ some time with OpenBSD as the system curses library, and on FreeBSD and
163163+ NetBSD as an external package. It should port easily to any
164164+ ANSI/POSIX-conforming UNIX. It has even been ported to OS/2 Warp!
165165 '';
166166-167167- homepage = "https://www.gnu.org/software/ncurses/";
168168-169169- license = lib.licenses.mit;
170170- platforms = lib.platforms.all;
166166+ license = licenses.mit;
167167+ platforms = platforms.all;
171168 };
172169173170 passthru = {
174171 ldflags = "-lncurses";
175175- inherit unicode abiVersion;
172172+ inherit unicodeSupport abiVersion;
176173 };
177174}
+21-1
pkgs/development/libraries/opencv/4.x.nix
···275275 propagatedBuildInputs = lib.optional enablePython pythonPackages.numpy
276276 ++ lib.optionals enableCuda [ cudatoolkit nvidia-optical-flow-sdk ];
277277278278- nativeBuildInputs = [ cmake pkg-config unzip ];
278278+ nativeBuildInputs = [ cmake pkg-config unzip ]
279279+ ++ lib.optionals enablePython [
280280+ pythonPackages.pip
281281+ pythonPackages.wheel
282282+ pythonPackages.setuptools
283283+ ];
279284280285 NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
281286···333338 postInstall = ''
334339 sed -i "s|{exec_prefix}/$out|{exec_prefix}|;s|{prefix}/$out|{prefix}|" \
335340 "$out/lib/pkgconfig/opencv4.pc"
341341+ ''
342342+ # install python distribution information, so other packages can `import opencv`
343343+ + lib.optionalString enablePython ''
344344+ pushd $NIX_BUILD_TOP/$sourceRoot/modules/python/package
345345+ python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
346346+347347+ pushd dist
348348+ python -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache
349349+350350+ # the cv2/__init__.py just tries to check provide "nice user feedback" if the installation is bad
351351+ # however, this also causes infinite recursion when used by other packages
352352+ rm -r $out/${pythonPackages.python.sitePackages}/cv2
353353+354354+ popd
355355+ popd
336356 '';
337357338358 passthru = lib.optionalAttrs enablePython { pythonPath = [ ]; };