about summary refs log tree commit diff
path: root/nixpkgs/pkgs/test
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/test')
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/cc-main.c7
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/cflags-main.c10
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/core-foundation-main.c7
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/cxx-main.cc7
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/default.nix80
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/foo.c4
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/ldflags-main.c12
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/multilib.nix37
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/nostdinc-main.c8
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/sanitizers.c8
-rw-r--r--nixpkgs/pkgs/test/cc-wrapper/stdio.h1
-rw-r--r--nixpkgs/pkgs/test/cross/default.nix113
-rw-r--r--nixpkgs/pkgs/test/cuda/cuda-library-samples/default.nix42
-rw-r--r--nixpkgs/pkgs/test/cuda/cuda-library-samples/generic.nix70
-rw-r--r--nixpkgs/pkgs/test/cuda/cuda-samples/default.nix44
-rw-r--r--nixpkgs/pkgs/test/cuda/cuda-samples/generic.nix51
-rw-r--r--nixpkgs/pkgs/test/cuda/default.nix24
-rw-r--r--nixpkgs/pkgs/test/default.nix58
-rw-r--r--nixpkgs/pkgs/test/haskell/default.nix7
-rw-r--r--nixpkgs/pkgs/test/haskell/documentationTarball/default.nix17
-rw-r--r--nixpkgs/pkgs/test/haskell/setBuildTarget/Bar.hs4
-rw-r--r--nixpkgs/pkgs/test/haskell/setBuildTarget/Foo.hs4
-rw-r--r--nixpkgs/pkgs/test/haskell/setBuildTarget/Setup.hs2
-rw-r--r--nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix38
-rw-r--r--nixpkgs/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal16
-rw-r--r--nixpkgs/pkgs/test/haskell/shellFor/default.nix33
-rw-r--r--nixpkgs/pkgs/test/install-shell-files/default.nix125
-rw-r--r--nixpkgs/pkgs/test/kernel.nix79
-rw-r--r--nixpkgs/pkgs/test/ld-library-path/default.nix88
-rw-r--r--nixpkgs/pkgs/test/macos-sierra-shared/default.nix90
-rw-r--r--nixpkgs/pkgs/test/mkOption/declare.nix53
-rw-r--r--nixpkgs/pkgs/test/mkOption/keep.nix11
-rw-r--r--nixpkgs/pkgs/test/mkOption/keep.ref57
-rw-r--r--nixpkgs/pkgs/test/mkOption/merge.nix15
-rw-r--r--nixpkgs/pkgs/test/mkOption/merge.ref20
-rwxr-xr-xnixpkgs/pkgs/test/mkOption/test.sh9
-rw-r--r--nixpkgs/pkgs/test/nixos-functions/default.nix41
-rw-r--r--nixpkgs/pkgs/test/patch-shebangs/default.nix70
-rw-r--r--nixpkgs/pkgs/test/rust-sysroot/default.nix60
-rw-r--r--nixpkgs/pkgs/test/simple/builder.sh42
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/bar.c3
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/cc-main.c7
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/default.nix68
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/foo.c3
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/include-main.c13
-rw-r--r--nixpkgs/pkgs/test/stdenv-inputs/lib-main.c14
-rw-r--r--nixpkgs/pkgs/test/texlive/default.nix122
-rw-r--r--nixpkgs/pkgs/test/vim/default.nix63
48 files changed, 1757 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/test/cc-wrapper/cc-main.c b/nixpkgs/pkgs/test/cc-wrapper/cc-main.c
new file mode 100644
index 000000000000..06f28bc33c69
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/cc-main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/cflags-main.c b/nixpkgs/pkgs/test/cc-wrapper/cflags-main.c
new file mode 100644
index 000000000000..9491232b5387
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/cflags-main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <foo.h>
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42)
+    return 1;
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/core-foundation-main.c b/nixpkgs/pkgs/test/cc-wrapper/core-foundation-main.c
new file mode 100644
index 000000000000..fb3bd3126191
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/core-foundation-main.c
@@ -0,0 +1,7 @@
+#include <CoreFoundation/CoreFoundation.h>
+
+int main(int argc, char** argv)
+{
+  CFShow(CFSTR("ok"));
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/cxx-main.cc b/nixpkgs/pkgs/test/cc-wrapper/cxx-main.cc
new file mode 100644
index 000000000000..83f704617a46
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/cxx-main.cc
@@ -0,0 +1,7 @@
+#include <iostream>
+
+int main(int argc, char **argv)
+{
+  std::cerr << "ok" << std::endl;
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/default.nix b/nixpkgs/pkgs/test/cc-wrapper/default.nix
new file mode 100644
index 000000000000..b483372dea04
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/default.nix
@@ -0,0 +1,80 @@
+{ lib, stdenv, glibc }:
+
+let
+  # Sanitizers are not supported on Darwin.
+  # Sanitizer headers aren't available in older libc++ stdenvs due to a bug
+  sanitizersWorking = !stdenv.hostPlatform.isMusl && (
+    (stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion stdenv.cc.name) "5.0.0")
+    || (stdenv.cc.isGNU && stdenv.isLinux)
+  );
+  staticLibc = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "-L ${glibc.static}/lib";
+in stdenv.mkDerivation {
+  name = "cc-wrapper-test";
+
+  buildCommand = ''
+    NIX_DEBUG=1 $CC -v
+    NIX_DEBUG=1 $CXX -v
+
+    printf "checking whether compiler builds valid C binaries... " >&2
+    $CC -o cc-check ${./cc-main.c}
+    ./cc-check
+
+    printf "checking whether compiler builds valid C++ binaries... " >&2
+    $CXX -o cxx-check ${./cxx-main.cc}
+    ./cxx-check
+
+    ${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) ''
+      printf "checking whether compiler can build with CoreFoundation.framework... " >&2
+      mkdir -p foo/lib
+      $CC -framework CoreFoundation -o core-foundation-check ${./core-foundation-main.c}
+      ./core-foundation-check
+    ''}
+
+
+    ${lib.optionalString (!stdenv.isDarwin) ''
+      printf "checking whether compiler builds valid static C binaries... " >&2
+      $CC ${staticLibc} -static -o cc-static ${./cc-main.c}
+      ./cc-static
+      ${lib.optionalString (stdenv.cc.isGNU && lib.versionAtLeast (lib.getVersion stdenv.cc.name) "8.0.0") ''
+        printf "checking whether compiler builds valid static pie C binaries... " >&2
+        $CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c}
+        ./cc-static-pie
+      ''}
+    ''}
+
+    printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2
+    mkdir -p foo/include
+    cp ${./foo.c} foo/include/foo.h
+    NIX_CFLAGS_COMPILE="-Ifoo/include -DVALUE=42" $CC -o cflags-check ${./cflags-main.c}
+    ./cflags-check
+
+    printf "checking whether compiler uses NIX_LDFLAGS... " >&2
+    mkdir -p foo/lib
+    $CC -shared \
+      ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,@rpath/libfoo.dylib"} \
+      -DVALUE=42 \
+      -o foo/lib/libfoo${stdenv.hostPlatform.extensions.sharedLibrary} \
+      ${./foo.c}
+
+    NIX_LDFLAGS="-L$NIX_BUILD_TOP/foo/lib -rpath $NIX_BUILD_TOP/foo/lib" $CC -lfoo -o ldflags-check ${./ldflags-main.c}
+    ./ldflags-check
+
+    printf "Check whether -nostdinc and -nostdinc++ is handled correctly" >&2
+    mkdir -p std-include
+    cp ${./stdio.h} std-include/stdio.h
+    NIX_DEBUG=1 $CC -I std-include -nostdinc -o nostdinc-main ${./nostdinc-main.c}
+    ./nostdinc-main
+    $CXX -I std-include -nostdinc++ -o nostdinc-main++ ${./nostdinc-main.c}
+    ./nostdinc-main++
+
+    ${lib.optionalString sanitizersWorking ''
+      printf "checking whether sanitizers are fully functional... ">&2
+      $CC -o sanitizers -fsanitize=address,undefined ${./sanitizers.c}
+      ./sanitizers
+    ''}
+
+    touch $out
+  '';
+
+  meta.platforms = lib.platforms.all;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/foo.c b/nixpkgs/pkgs/test/cc-wrapper/foo.c
new file mode 100644
index 000000000000..8be674be3103
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/foo.c
@@ -0,0 +1,4 @@
+unsigned int foo(void)
+{
+  return VALUE;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/ldflags-main.c b/nixpkgs/pkgs/test/cc-wrapper/ldflags-main.c
new file mode 100644
index 000000000000..89832b3bbad2
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/ldflags-main.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+extern unsigned int foo(void);
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42) {
+    return 1;
+  }
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/multilib.nix b/nixpkgs/pkgs/test/cc-wrapper/multilib.nix
new file mode 100644
index 000000000000..828ad67f6c87
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/multilib.nix
@@ -0,0 +1,37 @@
+{ lib, stdenv }:
+
+stdenv.mkDerivation {
+  name = "cc-multilib-test";
+
+  # XXX: "depend" on cc-wrapper test?
+
+  # TODO: Have tests report pointer size or something; ensure they are what we asked for
+  buildCommand = ''
+    NIX_DEBUG=1 $CC -v
+    NIX_DEBUG=1 $CXX -v
+
+    printf "checking whether compiler builds valid C binaries... " >&2
+    $CC -o cc-check ${./cc-main.c}
+    ./cc-check
+
+    printf "checking whether compiler builds valid 32bit C binaries... " >&2
+    $CC -m32 -o c32-check ${./cc-main.c}
+    ./c32-check
+
+    printf "checking whether compiler builds valid 64bit C binaries... " >&2
+    $CC -m64 -o c64-check ${./cc-main.c}
+    ./c64-check
+
+    printf "checking whether compiler builds valid 32bit C++ binaries... " >&2
+    $CXX -m32 -o cxx32-check ${./cxx-main.cc}
+    ./cxx32-check
+
+    printf "checking whether compiler builds valid 64bit C++ binaries... " >&2
+    $CXX -m64 -o cxx64-check ${./cxx-main.cc}
+    ./cxx64-check
+
+    touch $out
+  '';
+
+  meta.platforms = lib.platforms.x86_64;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/nostdinc-main.c b/nixpkgs/pkgs/test/cc-wrapper/nostdinc-main.c
new file mode 100644
index 000000000000..f71d155b1b27
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/nostdinc-main.c
@@ -0,0 +1,8 @@
+// This one should not come from libc because of -nostdinc
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+  // provided by our own stdio.h
+  foo();
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/sanitizers.c b/nixpkgs/pkgs/test/cc-wrapper/sanitizers.c
new file mode 100644
index 000000000000..93dd78a903ce
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/sanitizers.c
@@ -0,0 +1,8 @@
+#include <sanitizer/asan_interface.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/cc-wrapper/stdio.h b/nixpkgs/pkgs/test/cc-wrapper/stdio.h
new file mode 100644
index 000000000000..4bddf1d9d486
--- /dev/null
+++ b/nixpkgs/pkgs/test/cc-wrapper/stdio.h
@@ -0,0 +1 @@
+static void foo(void) {}
diff --git a/nixpkgs/pkgs/test/cross/default.nix b/nixpkgs/pkgs/test/cross/default.nix
new file mode 100644
index 000000000000..c5a241437732
--- /dev/null
+++ b/nixpkgs/pkgs/test/cross/default.nix
@@ -0,0 +1,113 @@
+{ pkgs, lib }:
+
+let
+
+  testedSystems = lib.filterAttrs (name: value: let
+    platform = lib.systems.elaborate value;
+  in platform.isLinux || platform.isWindows
+  ) lib.systems.examples;
+
+  getExecutable = pkgs: pkgFun: exec:
+    "${pkgFun pkgs}${exec}${pkgs.hostPlatform.extensions.executable}";
+
+  compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let
+    pkgName = (pkgFun hostPkgs).name;
+    args' = lib.concatStringsSep " " args;
+  in crossPkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" {
+    nativeBuildInputs = [ pkgs.dos2unix ];
+  } ''
+    # Just in case we are using wine, get rid of that annoying extra
+    # stuff.
+    export WINEDEBUG=-all
+
+    HOME=$(pwd)
+    mkdir -p $out
+
+    # We need to remove whitespace, unfortunately
+    # Windows programs use \r but Unix programs use \n
+
+    echo Running native-built program natively
+
+    # find expected value natively
+    ${getExecutable hostPkgs pkgFun exec} ${args'} \
+      | dos2unix > $out/expected
+
+    echo Running cross-built program in emulator
+
+    # run emulator to get actual value
+    ${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \
+      | dos2unix > $out/actual
+
+    echo Comparing results...
+
+    if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then
+      echo "${pkgName} did not output expected value:"
+      cat $out/expected
+      echo "instead it output:"
+      cat $out/actual
+      exit 1
+    else
+      echo "${pkgName} test passed"
+      echo "both produced output:"
+      cat $out/actual
+    fi
+  '';
+
+  mapMultiPlatformTest = crossSystemFun: test: lib.mapAttrs (name: system: test rec {
+    crossPkgs = import pkgs.path {
+      localSystem = { inherit (pkgs.hostPlatform) config; };
+      crossSystem = crossSystemFun system;
+    };
+
+    emulator = crossPkgs.hostPlatform.emulator pkgs;
+
+    # Apply some transformation on windows to get dlls in the right
+    # place. Unfortunately mingw doesn’t seem to be able to do linking
+    # properly.
+    platformFun = pkg: if crossPkgs.hostPlatform.isWindows then
+      pkgs.buildEnv {
+        name = "${pkg.name}-winlinks";
+        paths = [pkg] ++ pkg.buildInputs;
+      } else pkg;
+  }) testedSystems;
+
+  tests = {
+
+    file = {platformFun, crossPkgs, emulator}: compareTest {
+      inherit emulator crossPkgs;
+      hostPkgs = pkgs;
+      exec = "/bin/file";
+      args = [
+        "${pkgs.file}/share/man/man1/file.1.gz"
+        "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf"
+      ];
+      pkgFun = pkgs: platformFun pkgs.file;
+    };
+
+    hello = {platformFun, crossPkgs, emulator}: compareTest {
+      inherit emulator crossPkgs;
+      hostPkgs = pkgs;
+      exec = "/bin/hello";
+      pkgFun = pkgs: pkgs.hello;
+    };
+
+    pkg-config = {platformFun, crossPkgs, emulator}: crossPkgs.runCommand
+      "test-pkg-config-${crossPkgs.hostPlatform.config}"
+    {
+      depsBuildBuild = [ crossPkgs.pkgsBuildBuild.pkg-config ];
+      nativeBuildInputs = [ crossPkgs.pkgsBuildHost.pkg-config crossPkgs.buildPackages.zlib ];
+      depsBuildTarget = [ crossPkgs.pkgsBuildTarget.pkg-config ];
+      buildInputs = [ crossPkgs.zlib ];
+      NIX_DEBUG = 7;
+    } ''
+       mkdir $out
+       ${crossPkgs.pkgsBuildBuild.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-build"
+       ${crossPkgs.pkgsBuildHost.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-host"
+       ! diff "$out/for-build" "$out/for-host"
+    '';
+  };
+
+in {
+  gcc = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = false;})) tests);
+  llvm = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = true;})) tests);
+}
diff --git a/nixpkgs/pkgs/test/cuda/cuda-library-samples/default.nix b/nixpkgs/pkgs/test/cuda/cuda-library-samples/default.nix
new file mode 100644
index 000000000000..91095fbd3ac4
--- /dev/null
+++ b/nixpkgs/pkgs/test/cuda/cuda-library-samples/default.nix
@@ -0,0 +1,42 @@
+{ callPackage
+, cudatoolkit_10_1, cudatoolkit_10_2
+, cudatoolkit_11_0, cudatoolkit_11_1, cudatoolkit_11_2
+, cutensor_cudatoolkit_10_1, cutensor_cudatoolkit_10_2
+, cutensor_cudatoolkit_11_0, cutensor_cudatoolkit_11_1, cutensor_cudatoolkit_11_2
+}:
+
+rec {
+
+  cuda-library-samples_cudatoolkit_10_1 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_10_1;
+    cutensor_cudatoolkit = cutensor_cudatoolkit_10_1;
+  };
+
+  cuda-library-samples_cudatoolkit_10_2 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_10_2;
+    cutensor_cudatoolkit = cutensor_cudatoolkit_10_2;
+  };
+
+  cuda-library-samples_cudatoolkit_10 =
+    cuda-library-samples_cudatoolkit_10_2;
+
+  ##
+
+  cuda-library-samples_cudatoolkit_11_0 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_0;
+    cutensor_cudatoolkit = cutensor_cudatoolkit_11_0;
+  };
+
+  cuda-library-samples_cudatoolkit_11_1 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_1;
+    cutensor_cudatoolkit = cutensor_cudatoolkit_11_1;
+  };
+
+  cuda-library-samples_cudatoolkit_11_2 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_2;
+    cutensor_cudatoolkit = cutensor_cudatoolkit_11_2;
+  };
+
+  cuda-library-samples_cudatoolkit_11 =
+    cuda-library-samples_cudatoolkit_11_2;
+}
diff --git a/nixpkgs/pkgs/test/cuda/cuda-library-samples/generic.nix b/nixpkgs/pkgs/test/cuda/cuda-library-samples/generic.nix
new file mode 100644
index 000000000000..f1ce243bfa6a
--- /dev/null
+++ b/nixpkgs/pkgs/test/cuda/cuda-library-samples/generic.nix
@@ -0,0 +1,70 @@
+{ lib, stdenv, fetchFromGitHub
+, cmake, addOpenGLRunpath
+, cudatoolkit
+, cutensor_cudatoolkit
+}:
+
+let
+  rev = "5aab680905d853bce0dbad4c488e4f7e9f7b2302";
+  src = fetchFromGitHub {
+    owner = "NVIDIA";
+    repo = "CUDALibrarySamples";
+    inherit rev;
+    sha256 = "0gwgbkq05ygrfgg5hk07lmap7n7ampxv0ha1axrv8qb748ph81xs";
+  };
+  commonAttrs = {
+    version = lib.strings.substring 0 7 rev + "-" + lib.versions.majorMinor cudatoolkit.version;
+    nativeBuildInputs = [ cmake addOpenGLRunpath ];
+    buildInputs = [ cudatoolkit ];
+    enableParallelBuilding = true;
+    postFixup = ''
+      for exe in $out/bin/*; do
+        addOpenGLRunpath $exe
+      done
+    '';
+    meta = {
+      description = "examples of using libraries using CUDA";
+      longDescription = ''
+        CUDA Library Samples contains examples demonstrating the use of
+        features in the math and image processing libraries cuBLAS, cuTENSOR,
+        cuSPARSE, cuSOLVER, cuFFT, cuRAND, NPP and nvJPEG.
+      '';
+      license = lib.licenses.bsd3;
+      maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
+    };
+  };
+in
+
+{
+  cublas = stdenv.mkDerivation (commonAttrs // {
+    pname = "cuda-library-samples-cublas";
+
+    src = "${src}/cuBLASLt";
+  });
+
+  cusolver = stdenv.mkDerivation (commonAttrs // {
+    pname = "cuda-library-samples-cusolver";
+
+    src = "${src}/cuSOLVER";
+
+    sourceRoot = "cuSOLVER/gesv";
+  });
+
+  cutensor = stdenv.mkDerivation (commonAttrs // {
+    pname = "cuda-library-samples-cutensor";
+
+    src = "${src}/cuTENSOR";
+
+    cmakeFlags = [
+      "-DCUTENSOR_EXAMPLE_BINARY_INSTALL_DIR=${builtins.placeholder "out"}/bin"
+    ];
+
+    # CUTENSOR_ROOT is double escaped
+    postPatch = ''
+      substituteInPlace CMakeLists.txt \
+        --replace "\''${CUTENSOR_ROOT}/include" "${cutensor_cudatoolkit.dev}/include"
+    '';
+
+    CUTENSOR_ROOT = cutensor_cudatoolkit;
+  });
+}
diff --git a/nixpkgs/pkgs/test/cuda/cuda-samples/default.nix b/nixpkgs/pkgs/test/cuda/cuda-samples/default.nix
new file mode 100644
index 000000000000..1a361c57214c
--- /dev/null
+++ b/nixpkgs/pkgs/test/cuda/cuda-samples/default.nix
@@ -0,0 +1,44 @@
+{ callPackage
+, cudatoolkit_10_0, cudatoolkit_10_1, cudatoolkit_10_2
+, cudatoolkit_11_0, cudatoolkit_11_1, cudatoolkit_11_2
+}:
+
+rec {
+  ##
+
+  cuda-samples_cudatoolkit_10_0 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_10_0;
+    sha256 = "1zvh4xsdyc59m87brpcmssxsjlp9dkynh4asnkcmc3g94f53l0jw";
+  };
+
+  cuda-samples_cudatoolkit_10_1 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_10_1;
+    sha256 = "1s8ka0hznrni36ajhzf2gqpdrl8kd8fi047qijxks5l2abc093qd";
+  };
+
+  cuda-samples_cudatoolkit_10_2 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_10_2;
+    sha256 = "01p1innzgh9siacpld6nsqimj8jkg93rk4gj8q4crn62pa5vhd94";
+  };
+
+  cuda-samples_cudatoolkit_10 = cuda-samples_cudatoolkit_10_2;
+
+  ##
+
+  cuda-samples_cudatoolkit_11_0 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_0;
+    sha256 = "1n3vjc8c7zdig2xgl5fppavrphqzhdiv9m9nk6smh4f99fwi0705";
+  };
+
+  cuda-samples_cudatoolkit_11_1 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_1;
+    sha256 = "1kjixk50i8y1bkiwbdn5lkv342crvkmbvy1xl5j3lsa1ica21kwh";
+  };
+
+  cuda-samples_cudatoolkit_11_2 = callPackage ./generic.nix {
+    cudatoolkit = cudatoolkit_11_2;
+    sha256 = "1p1qjvfbm28l933mmnln02rqrf0cy9kbpsyb488d1haiqzvrazl1";
+  };
+
+  cuda-samples_cudatoolkit_11 = cuda-samples_cudatoolkit_11_2;
+}
diff --git a/nixpkgs/pkgs/test/cuda/cuda-samples/generic.nix b/nixpkgs/pkgs/test/cuda/cuda-samples/generic.nix
new file mode 100644
index 000000000000..2e3dcc8891f4
--- /dev/null
+++ b/nixpkgs/pkgs/test/cuda/cuda-samples/generic.nix
@@ -0,0 +1,51 @@
+{ lib, stdenv, fetchFromGitHub
+, pkg-config, addOpenGLRunpath
+, sha256, cudatoolkit
+}:
+
+let
+  pname = "cuda-samples";
+  version = lib.versions.majorMinor cudatoolkit.version;
+in
+
+stdenv.mkDerivation {
+  inherit pname version;
+
+  src = fetchFromGitHub {
+    owner = "NVIDIA";
+    repo = pname;
+    rev = "v${version}";
+    inherit sha256;
+  };
+
+  nativeBuildInputs = [ pkg-config addOpenGLRunpath ];
+
+  buildInputs = [ cudatoolkit ];
+
+  enableParallelBuilding = true;
+
+  preConfigure = ''
+    export CUDA_PATH=${cudatoolkit}
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    install -Dm755 -t $out/bin bin/${stdenv.hostPlatform.parsed.cpu.name}/${stdenv.hostPlatform.parsed.kernel.name}/release/*
+
+    runHook postInstall
+  '';
+
+  postFixup = ''
+    for exe in $out/bin/*; do
+      addOpenGLRunpath $exe
+    done
+  '';
+
+  meta = {
+    description = "Samples for CUDA Developers which demonstrates features in CUDA Toolkit";
+    # CUDA itself is proprietary, but these sample apps are not.
+    license = lib.licenses.bsd3;
+    maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
+  };
+}
diff --git a/nixpkgs/pkgs/test/cuda/default.nix b/nixpkgs/pkgs/test/cuda/default.nix
new file mode 100644
index 000000000000..aac52e6a4f5d
--- /dev/null
+++ b/nixpkgs/pkgs/test/cuda/default.nix
@@ -0,0 +1,24 @@
+{ callPackage }:
+
+rec {
+  cuda-samplesPackages = callPackage ./cuda-samples { };
+  inherit (cuda-samplesPackages)
+    cuda-samples_cudatoolkit_10
+    cuda-samples_cudatoolkit_10_0
+    cuda-samples_cudatoolkit_10_1
+    cuda-samples_cudatoolkit_10_2
+    cuda-samples_cudatoolkit_11
+    cuda-samples_cudatoolkit_11_0
+    cuda-samples_cudatoolkit_11_1
+    cuda-samples_cudatoolkit_11_2;
+
+  cuda-library-samplesPackages = callPackage ./cuda-library-samples { };
+  inherit (cuda-library-samplesPackages)
+    cuda-library-samples_cudatoolkit_10
+    cuda-library-samples_cudatoolkit_10_1
+    cuda-library-samples_cudatoolkit_10_2
+    cuda-library-samples_cudatoolkit_11
+    cuda-library-samples_cudatoolkit_11_0
+    cuda-library-samples_cudatoolkit_11_1
+    cuda-library-samples_cudatoolkit_11_2;
+}
diff --git a/nixpkgs/pkgs/test/default.nix b/nixpkgs/pkgs/test/default.nix
new file mode 100644
index 000000000000..ebf732839cea
--- /dev/null
+++ b/nixpkgs/pkgs/test/default.nix
@@ -0,0 +1,58 @@
+{ pkgs, callPackage }:
+
+with pkgs;
+
+{
+  cc-wrapper = callPackage ./cc-wrapper { };
+  cc-wrapper-gcc = callPackage ./cc-wrapper { stdenv = gccStdenv; };
+  cc-wrapper-gcc7 = callPackage ./cc-wrapper { stdenv = gcc7Stdenv; };
+  cc-wrapper-gcc8 = callPackage ./cc-wrapper { stdenv = gcc8Stdenv; };
+  cc-wrapper-gcc9 = callPackage ./cc-wrapper { stdenv = gcc9Stdenv; };
+  cc-wrapper-clang = callPackage ./cc-wrapper { stdenv = llvmPackages.stdenv; };
+  cc-wrapper-libcxx = callPackage ./cc-wrapper { stdenv = llvmPackages.libcxxStdenv; };
+  cc-wrapper-clang-5 = callPackage ./cc-wrapper { stdenv = llvmPackages_5.stdenv; };
+  cc-wrapper-libcxx-5 = callPackage ./cc-wrapper { stdenv = llvmPackages_5.libcxxStdenv; };
+  cc-wrapper-clang-6 = callPackage ./cc-wrapper { stdenv = llvmPackages_6.stdenv; };
+  cc-wrapper-libcxx-6 = callPackage ./cc-wrapper { stdenv = llvmPackages_6.libcxxStdenv; };
+  cc-wrapper-clang-7 = callPackage ./cc-wrapper { stdenv = llvmPackages_7.stdenv; };
+  cc-wrapper-libcxx-7 = callPackage ./cc-wrapper { stdenv = llvmPackages_7.libcxxStdenv; };
+  cc-wrapper-clang-8 = callPackage ./cc-wrapper { stdenv = llvmPackages_8.stdenv; };
+  cc-wrapper-libcxx-8 = callPackage ./cc-wrapper { stdenv = llvmPackages_8.libcxxStdenv; };
+  cc-wrapper-clang-9 = callPackage ./cc-wrapper { stdenv = llvmPackages_9.stdenv; };
+  cc-wrapper-libcxx-9 = callPackage ./cc-wrapper { stdenv = llvmPackages_9.libcxxStdenv; };
+  stdenv-inputs = callPackage ./stdenv-inputs { };
+
+  haskell = callPackage ./haskell { };
+
+  cc-multilib-gcc = callPackage ./cc-wrapper/multilib.nix { stdenv = gccMultiStdenv; };
+  cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; };
+
+  install-shell-files = callPackage ./install-shell-files {};
+
+  kernel-config = callPackage ./kernel.nix {};
+
+  ld-library-path = callPackage ./ld-library-path {};
+
+  macOSSierraShared = callPackage ./macos-sierra-shared {};
+
+  cross = callPackage ./cross {};
+
+  rustCustomSysroot = callPackage ./rust-sysroot {};
+  buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { };
+  importCargoLock = callPackage ../build-support/rust/test/import-cargo-lock { };
+
+  vim = callPackage ./vim {};
+
+  nixos-functions = callPackage ./nixos-functions {};
+
+  patch-shebangs = callPackage ./patch-shebangs {};
+
+  texlive = callPackage ./texlive {};
+
+  cuda = callPackage ./cuda { };
+
+  trivial = callPackage ../build-support/trivial-builders/test.nix {};
+  trivial-overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
+
+  writers = callPackage ../build-support/writers/test.nix {};
+}
diff --git a/nixpkgs/pkgs/test/haskell/default.nix b/nixpkgs/pkgs/test/haskell/default.nix
new file mode 100644
index 000000000000..eb389f4051f8
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/default.nix
@@ -0,0 +1,7 @@
+{ lib, callPackage }:
+
+lib.recurseIntoAttrs {
+  shellFor = callPackage ./shellFor { };
+  documentationTarball = callPackage ./documentationTarball { };
+  setBuildTarget = callPackage ./setBuildTarget { };
+}
diff --git a/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix b/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix
new file mode 100644
index 000000000000..aec3dc41f268
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix
@@ -0,0 +1,17 @@
+{ pkgs, haskellPackages }:
+
+let
+  drv = haskellPackages.vector;
+  docs = pkgs.haskell.lib.documentationTarball drv;
+
+in pkgs.runCommand "test haskell.lib.documentationTarball" { } ''
+  tar xvzf "${docs}/${drv.name}-docs.tar.gz"
+
+  # Check for Haddock html
+  find "${drv.name}-docs" | grep -q "Data-Vector.html"
+
+  # Check for source html
+  find "${drv.name}-docs" | grep -q  "src/Data.Vector.html"
+
+  touch "$out"
+''
diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/Bar.hs b/nixpkgs/pkgs/test/haskell/setBuildTarget/Bar.hs
new file mode 100644
index 000000000000..010014082c7d
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/Bar.hs
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = putStrLn "Hello, Bar!"
diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/Foo.hs b/nixpkgs/pkgs/test/haskell/setBuildTarget/Foo.hs
new file mode 100644
index 000000000000..fec7bb11fe6c
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/Foo.hs
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = putStrLn "Hello, Foo!"
diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/Setup.hs b/nixpkgs/pkgs/test/haskell/setBuildTarget/Setup.hs
new file mode 100644
index 000000000000..9a994af677b0
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix b/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix
new file mode 100644
index 000000000000..b1335e2a74cf
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix
@@ -0,0 +1,38 @@
+{ pkgs, haskellPackages }:
+
+let
+  # This can be regenerated by running `cabal2nix .` in the current directory.
+  pkgDef =
+    { mkDerivation, base, lib }:
+      mkDerivation {
+        pname = "haskell-setBuildTarget";
+        version = "0.1.0.0";
+        src = ./.;
+        isLibrary = false;
+        isExecutable = true;
+        executableHaskellDepends = [ base ];
+        license = lib.licenses.bsd3;
+      };
+
+  drv = haskellPackages.callPackage pkgDef {};
+
+  test  = target: excluded:
+    let only = pkgs.haskell.lib.setBuildTarget drv target;
+    in ''
+         if [[ ! -f "${only}/bin/${target}" ]]; then
+           echo "${target} was not built"
+           exit 1
+         fi
+
+         if [[ -f "${only}/bin/${excluded}" ]]; then
+           echo "${excluded} was built, when it should not have been"
+           exit 1
+         fi
+     '';
+
+in pkgs.runCommand "test haskell.lib.setBuildTarget" {} ''
+  ${test "foo" "bar"}
+  ${test "bar" "foo"}
+  touch "$out"
+''
+
diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal b/nixpkgs/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
new file mode 100644
index 000000000000..7395e139451c
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
@@ -0,0 +1,16 @@
+cabal-version:       >=1.10
+name:                haskell-setBuildTarget
+version:             0.1.0.0
+author:              Isaac Shapira
+maintainer:          fresheyeball@protonmail.com
+build-type:          Simple
+
+executable foo
+  main-is:             Foo.hs
+  build-depends:       base
+  default-language:    Haskell2010
+
+executable bar
+  main-is:             Bar.hs
+  build-depends:       base
+  default-language:    Haskell2010
diff --git a/nixpkgs/pkgs/test/haskell/shellFor/default.nix b/nixpkgs/pkgs/test/haskell/shellFor/default.nix
new file mode 100644
index 000000000000..37ad2e90d89e
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/shellFor/default.nix
@@ -0,0 +1,33 @@
+{ lib, writeText, haskellPackages, cabal-install }:
+
+(haskellPackages.shellFor {
+  packages = p: [ p.constraints p.linear ];
+  nativeBuildInputs = [ cabal-install ];
+  phases = [ "unpackPhase" "buildPhase" "installPhase" ];
+  unpackPhase = ''
+    sourceRoot=$(pwd)/scratch
+    mkdir -p "$sourceRoot"
+    cd "$sourceRoot"
+    tar -xf ${haskellPackages.constraints.src}
+    tar -xf ${haskellPackages.linear.src}
+    cp ${writeText "cabal.project" "packages: constraints* linear*"} cabal.project
+  '';
+  buildPhase = ''
+    export HOME=$(mktemp -d)
+    mkdir -p $HOME/.cabal
+    touch $HOME/.cabal/config
+    cabal v2-build --offline --verbose constraints linear --ghc-options="-O0 -j$NIX_BUILD_CORES"
+  '';
+  installPhase = ''
+    touch $out
+  '';
+}).overrideAttrs (oldAttrs: {
+  meta =
+    let
+      oldMeta = oldAttrs.meta or {};
+      oldMaintainers = oldMeta.maintainers or [];
+      additionalMaintainers = with lib.maintainers; [ cdepillabout ];
+      allMaintainers = oldMaintainers ++ additionalMaintainers;
+    in
+    oldMeta // { maintainers = allMaintainers; };
+})
diff --git a/nixpkgs/pkgs/test/install-shell-files/default.nix b/nixpkgs/pkgs/test/install-shell-files/default.nix
new file mode 100644
index 000000000000..aef5acc1de6b
--- /dev/null
+++ b/nixpkgs/pkgs/test/install-shell-files/default.nix
@@ -0,0 +1,125 @@
+{ lib, runCommandLocal, recurseIntoAttrs, installShellFiles }:
+
+let
+  runTest = name: env: buildCommand:
+    runCommandLocal "install-shell-files--${name}" ({
+      nativeBuildInputs = [ installShellFiles ];
+      meta.platforms = lib.platforms.all;
+    } // env) buildCommand;
+in
+
+recurseIntoAttrs {
+  # installManPage
+
+  install-manpage = runTest "install-manpage" {} ''
+    mkdir -p doc
+    echo foo > doc/foo.1
+    echo bar > doc/bar.2.gz
+    echo baz > doc/baz.3
+
+    installManPage doc/*
+
+    cmp doc/foo.1 $out/share/man/man1/foo.1
+    cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz
+    cmp doc/baz.3 $out/share/man/man3/baz.3
+  '';
+  install-manpage-outputs = runTest "install-manpage-outputs" {
+    outputs = [ "out" "man" "devman" ];
+  } ''
+    mkdir -p doc
+    echo foo > doc/foo.1
+    echo bar > doc/bar.3
+
+    installManPage doc/*
+
+    # assert they didn't go into $out
+    [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]]
+
+    # foo.1 alone went into man
+    cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1
+    [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]]
+
+    # bar.3 alone went into devman
+    cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3
+    [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]]
+
+    touch $out
+  '';
+
+  # installShellCompletion
+
+  install-completion = runTest "install-completion" {} ''
+    echo foo > foo
+    echo bar > bar
+    echo baz > baz
+    echo qux > qux.zsh
+    echo quux > quux
+
+    installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux
+
+    cmp foo $out/share/bash-completion/completions/foo
+    cmp bar $out/share/bash-completion/completions/bar
+    cmp baz $out/share/zsh/site-functions/_baz
+    cmp qux.zsh $out/share/zsh/site-functions/_qux
+    cmp quux $out/share/fish/vendor_completions.d/quux
+  '';
+  install-completion-output = runTest "install-completion-output" {
+    outputs = [ "out" "bin" ];
+  } ''
+    echo foo > foo
+
+    installShellCompletion --bash foo
+
+    # assert it didn't go into $out
+    [[ ! -f $out/share/bash-completion/completions/foo ]]
+
+    cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo
+
+    touch $out
+  '';
+  install-completion-name = runTest "install-completion-name" {} ''
+    echo foo > foo
+    echo bar > bar
+    echo baz > baz
+
+    installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz
+
+    cmp foo $out/share/bash-completion/completions/foobar.bash
+    cmp bar $out/share/zsh/site-functions/_foobar
+    cmp baz $out/share/fish/vendor_completions.d/baz
+  '';
+  install-completion-inference = runTest "install-completion-inference" {} ''
+    echo foo > foo.bash
+    echo bar > bar.zsh
+    echo baz > baz.fish
+
+    installShellCompletion foo.bash bar.zsh baz.fish
+
+    cmp foo.bash $out/share/bash-completion/completions/foo.bash
+    cmp bar.zsh $out/share/zsh/site-functions/_bar
+    cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish
+  '';
+  install-completion-cmd = runTest "install-completion-cmd" {} ''
+    echo foo > foo.bash
+    echo bar > bar.zsh
+    echo baz > baz.fish
+    echo qux > qux.fish
+
+    installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish
+
+    cmp foo.bash $out/share/bash-completion/completions/foobar.bash
+    cmp bar.zsh $out/share/zsh/site-functions/_foobar
+    cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish
+    cmp qux.fish $out/share/fish/vendor_completions.d/qux
+  '';
+  install-completion-fifo = runTest "install-completion-fifo" {} ''
+    installShellCompletion \
+      --bash --name foo.bash <(echo foo) \
+      --zsh --name _foo <(echo bar) \
+      --fish --name foo.fish <(echo baz)
+
+    [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; }
+    [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; }
+    [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; }
+  '';
+}
diff --git a/nixpkgs/pkgs/test/kernel.nix b/nixpkgs/pkgs/test/kernel.nix
new file mode 100644
index 000000000000..a4da10030332
--- /dev/null
+++ b/nixpkgs/pkgs/test/kernel.nix
@@ -0,0 +1,79 @@
+# to run these tests:
+# nix-instantiate --eval --strict . -A tests.kernel-config
+#
+# make sure to use NON EXISTING kernel settings else they may conflict with
+# common-config.nix
+{ lib, pkgs }:
+
+with lib;
+with kernel;
+
+let
+  lts_kernel = pkgs.linuxPackages.kernel;
+
+  # to see the result once the module transformed the lose structured config
+  getConfig = structuredConfig:
+    (lts_kernel.override {
+      structuredExtraConfig = structuredConfig;
+    }).configfile.structuredConfig;
+
+  mandatoryVsOptionalConfig = mkMerge [
+    { NIXOS_FAKE_USB_DEBUG = yes;}
+    { NIXOS_FAKE_USB_DEBUG = option yes; }
+  ];
+
+  freeformConfig = mkMerge [
+    { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error
+    { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great:
+  ];
+
+  yesWinsOverNoConfig = mkMerge [
+    # default for "NIXOS_TEST_BOOLEAN" is no
+    { "NIXOS_TEST_BOOLEAN"  = yes; } # yes wins over no by default
+    { "NIXOS_TEST_BOOLEAN"  = no; }
+  ];
+
+  optionalNoWins = mkMerge [
+    { NIXOS_FAKE_USB_DEBUG = option yes;}
+    { NIXOS_FAKE_USB_DEBUG = yes;}
+  ];
+
+  allOptionalRemainOptional = mkMerge [
+    { NIXOS_FAKE_USB_DEBUG = option yes;}
+    { NIXOS_FAKE_USB_DEBUG = option yes;}
+  ];
+
+in
+runTests {
+  testEasy = {
+    expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG;
+    expected = { tristate = "y"; optional = false; freeform = null; };
+  };
+
+  # mandatory flag should win over optional
+  testMandatoryCheck = {
+    expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional;
+    expected = false;
+  };
+
+  testYesWinsOverNo = {
+    expr = (getConfig yesWinsOverNoConfig)."NIXOS_TEST_BOOLEAN".tristate;
+    expected = "y";
+  };
+
+  testAllOptionalRemainOptional = {
+    expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional;
+    expected = true;
+  };
+
+  # check that freeform options are unique
+  # Should trigger
+  # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'
+  testTreeform = let
+    res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform);
+  in {
+    expr = res.success;
+    expected = false;
+  };
+
+}
diff --git a/nixpkgs/pkgs/test/ld-library-path/default.nix b/nixpkgs/pkgs/test/ld-library-path/default.nix
new file mode 100644
index 000000000000..74c52cef2532
--- /dev/null
+++ b/nixpkgs/pkgs/test/ld-library-path/default.nix
@@ -0,0 +1,88 @@
+{ lib, stdenv }:
+
+# This tests that libraries listed in LD_LIBRARY_PATH take precedence over those listed in RPATH.
+
+let
+  # A simple test library: libgreeting.so which exports a single function getGreeting() returning the good old hello greeting.
+  libgreeting = stdenv.mkDerivation {
+    name = "libgreeting";
+
+    code = ''
+      const char* getGreeting() { return "Hello, world!"; }
+    '';
+
+    unpackPhase = ''
+      echo "$code" > libgreeting.c
+    '';
+
+    installPhase = ''
+      mkdir -p $out/lib
+      $CC -c -fpic libgreeting.c
+      $CC -shared libgreeting.o -o $out/lib/libgreeting.so
+    '';
+  };
+
+  # A variant of libgreeting.so that returns a different message.
+  libgoodbye = libgreeting.overrideAttrs (_: {
+    name = "libgoodbye";
+    code = ''
+      const char* getGreeting() { return "Goodbye, world!"; }
+    '';
+  });
+
+  # A simple consumer of libgreeting.so that just prints the greeting to stdout.
+  testProgram = stdenv.mkDerivation {
+    name = "greeting-test";
+
+    buildInputs = [ libgreeting ];
+
+    code = ''
+      #include <stdio.h>
+
+      extern const char* getGreeting(void);
+
+      int main() {
+        puts(getGreeting());
+      }
+    '';
+
+    unpackPhase = ''
+      echo "$code" > greeting-test.c
+    '';
+
+    installPhase = ''
+      mkdir -p $out/bin
+      $CC -c greeting-test.c
+      $CC greeting-test.o -lgreeting -o $out/bin/greeting-test
+
+      # Now test the installed binaries right after compiling them. In particular,
+      # don't do this in installCheckPhase because fixupPhase has been run by then!
+      (
+        export PATH=$out/bin
+        set -x
+
+        # Verify that our unmodified binary works as expected.
+        [ "$(greeting-test)" = "Hello, world!" ]
+
+        # And finally, test that a library in LD_LIBRARY_PATH takes precedence over the linked-in library.
+        [ "$(LD_LIBRARY_PATH=${libgoodbye}/lib greeting-test)" = "Goodbye, world!" ]
+      )
+    '';
+
+  };
+in stdenv.mkDerivation {
+  name = "test-LD_LIBRARY_PATH";
+  nativeBuildInputs = [ testProgram ];
+
+  buildCommand = ''
+    # And for good measure, repeat the tests again from a separate derivation,
+    # as fixupPhase done by the stdenv can (and has!) affect the result.
+
+    [ "$(greeting-test)" = "Hello, world!" ]
+    [ "$(LD_LIBRARY_PATH=${libgoodbye}/lib greeting-test)" = "Goodbye, world!" ]
+
+    touch $out
+  '';
+
+  meta.platforms = lib.platforms.linux;
+}
diff --git a/nixpkgs/pkgs/test/macos-sierra-shared/default.nix b/nixpkgs/pkgs/test/macos-sierra-shared/default.nix
new file mode 100644
index 000000000000..810d5d97829b
--- /dev/null
+++ b/nixpkgs/pkgs/test/macos-sierra-shared/default.nix
@@ -0,0 +1,90 @@
+{ lib, clangStdenv, clang-sierraHack-stdenv, stdenvNoCC }:
+
+let
+  makeBigExe = stdenv: prefix: rec {
+
+    count = 320;
+
+    sillyLibs = lib.genList (i: stdenv.mkDerivation rec {
+      name = "${prefix}-fluff-${toString i}";
+      unpackPhase = ''
+        src=$PWD
+        cat << 'EOF' > ${name}.c
+        unsigned int asdf_${toString i}(void) {
+          return ${toString i};
+        }
+        EOF
+      '';
+      buildPhase = ''
+        $CC -std=c99 -shared ${name}.c -o lib${name}.dylib -Wl,-install_name,$out/lib/lib${name}.dylib
+      '';
+      installPhase = ''
+        mkdir -p "$out/lib"
+        mv lib${name}.dylib "$out/lib"
+      '';
+      meta.platforms = lib.platforms.darwin;
+    }) count;
+
+    finalExe = stdenv.mkDerivation {
+      name = "${prefix}-final-asdf";
+      unpackPhase = ''
+        src=$PWD
+        cat << 'EOF' > main.cxx
+
+        #include <cstdlib>
+        #include <iostream>
+
+        ${toString (lib.genList (i: "extern \"C\" unsigned int asdf_${toString i}(void); ") count)}
+
+        unsigned int (*funs[])(void) = {
+          ${toString (lib.genList (i: "asdf_${toString i},") count)}
+        };
+
+        int main(int argc, char **argv) {
+          bool ret;
+          unsigned int i = 0;
+          for (auto f : funs) {
+            if (f() != i++) {
+              std::cerr << "Failed to get expected response from function #" << i << std::endl;
+              return EXIT_FAILURE;
+            }
+          }
+          return EXIT_SUCCESS;
+        }
+        EOF
+      '';
+      buildPhase = ''
+        $CXX -std=c++11 main.cxx ${toString (map (x: "-l${x.name}") sillyLibs)} -o ${prefix}-asdf
+      '';
+      buildInputs = sillyLibs;
+      installPhase = ''
+        mkdir -p "$out/bin"
+        mv ${prefix}-asdf "$out/bin"
+      '';
+      meta.platforms = lib.platforms.darwin;
+    };
+
+  };
+
+  good = makeBigExe clang-sierraHack-stdenv "good";
+
+  bad  = makeBigExe clangStdenv             "bad";
+
+in stdenvNoCC.mkDerivation {
+  name = "macos-sierra-shared-test";
+  buildInputs = [ good.finalExe bad.finalExe ];
+  # TODO(@Ericson2314): Be impure or require exact MacOS version of builder?
+  buildCommand = ''
+    if bad-asdf &> /dev/null
+    then echo "WARNING: bad-asdf did not fail, not running on sierra?" >&2
+    else echo "bad-asdf should fail on sierra, OK" >&2
+    fi
+
+    # Must succeed on all supported MacOS versions
+    good-asdf
+    echo "good-asdf should succeed on sierra, OK"
+
+    touch $out
+  '';
+  meta.platforms = lib.platforms.darwin;
+}
diff --git a/nixpkgs/pkgs/test/mkOption/declare.nix b/nixpkgs/pkgs/test/mkOption/declare.nix
new file mode 100644
index 000000000000..9e89a1c096da
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/declare.nix
@@ -0,0 +1,53 @@
+# sets of small configurations:
+# Each configuration
+rec {
+  # has 2 arguments pkgs and this.
+  configA = pkgs: this: {
+    # Can depends on other configuration
+    require = configB;
+
+    # Defines new options
+    optionA = pkgs.lib.mkOption {
+      # With default values
+      default = false;
+      # And merging functions.
+      merge = pkgs.lib.mergeEnableOption;
+    };
+
+    # Add a new definition to other options.
+    optionB = this.optionA;
+  };
+
+  # Can be used for option header.
+  configB = pkgs: this: {
+    # Can depends on more than one configuration.
+    require = [ configC configD ];
+
+    optionB = pkgs.lib.mkOption {
+      default = false;
+    };
+
+    # Is not obliged to define other options.
+  };
+
+  configC = pkgs: this: {
+    require = [ configA ];
+
+    optionC = pkgs.lib.mkOption {
+      default = false;
+    };
+
+    # Use the default value if it is not overwritten.
+    optionA = this.optionC;
+  };
+
+  # Can also be used as option configuration only.
+  # without any arguments (backward compatibility)
+  configD = {
+    # Is not forced to specify the require attribute.
+
+    # Is not force to make new options.
+    optionA = true;
+    optionD = false;
+  };
+}
diff --git a/nixpkgs/pkgs/test/mkOption/keep.nix b/nixpkgs/pkgs/test/mkOption/keep.nix
new file mode 100644
index 000000000000..26fb8c28dd59
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/keep.nix
@@ -0,0 +1,11 @@
+let
+  pkgs = import ../../.. {};
+  config = import ./declare.nix;
+in
+  with (pkgs.lib);
+
+  finalReferenceOptionSets
+    filterOptionSets
+    pkgs
+    # List of main configurations.
+    [ config.configB config.configC ]
diff --git a/nixpkgs/pkgs/test/mkOption/keep.ref b/nixpkgs/pkgs/test/mkOption/keep.ref
new file mode 100644
index 000000000000..a3a051eb48c4
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/keep.ref
@@ -0,0 +1,57 @@
+<?xml version='1.0' encoding='utf-8'?>
+<expr>
+  <attrs>
+    <attr name="optionA">
+      <list>
+        <attrs>
+          <attr name="_type">
+            <string value="option" />
+          </attr>
+          <attr name="default">
+            <bool value="false" />
+          </attr>
+          <attr name="merge">
+            <unevaluated />
+          </attr>
+          <attr name="name">
+            <string value="optionA" />
+          </attr>
+        </attrs>
+      </list>
+    </attr>
+    <attr name="optionB">
+      <list>
+        <attrs>
+          <attr name="_type">
+            <string value="option" />
+          </attr>
+          <attr name="default">
+            <bool value="false" />
+          </attr>
+          <attr name="name">
+            <string value="optionB" />
+          </attr>
+        </attrs>
+      </list>
+    </attr>
+    <attr name="optionC">
+      <list>
+        <attrs>
+          <attr name="_type">
+            <string value="option" />
+          </attr>
+          <attr name="default">
+            <bool value="false" />
+          </attr>
+          <attr name="name">
+            <string value="optionC" />
+          </attr>
+        </attrs>
+      </list>
+    </attr>
+    <attr name="optionD">
+      <attrs>
+      </attrs>
+    </attr>
+  </attrs>
+</expr>
diff --git a/nixpkgs/pkgs/test/mkOption/merge.nix b/nixpkgs/pkgs/test/mkOption/merge.nix
new file mode 100644
index 000000000000..bbf68218aa09
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/merge.nix
@@ -0,0 +1,15 @@
+let
+  pkgs = import ../../.. {};
+  config = import ./declare.nix;
+
+  # Define the handler of unbound options.
+  noOption = name: values:
+    builtins.trace "Attribute named '${name}' does not match any option declaration." values;
+in
+  with (pkgs.lib);
+
+  finalReferenceOptionSets
+    (mergeOptionSets noOption)
+    pkgs
+    # List of main configurations.
+    [ config.configB config.configC ]
diff --git a/nixpkgs/pkgs/test/mkOption/merge.ref b/nixpkgs/pkgs/test/mkOption/merge.ref
new file mode 100644
index 000000000000..6956f65dbbcc
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/merge.ref
@@ -0,0 +1,20 @@
+trace: Str("Attribute named 'optionD' does not match any option declaration.",[])
+<?xml version='1.0' encoding='utf-8'?>
+<expr>
+  <attrs>
+    <attr name="optionA">
+      <bool value="true" />
+    </attr>
+    <attr name="optionB">
+      <bool value="true" />
+    </attr>
+    <attr name="optionC">
+      <bool value="false" />
+    </attr>
+    <attr name="optionD">
+      <list>
+        <bool value="false" />
+      </list>
+    </attr>
+  </attrs>
+</expr>
diff --git a/nixpkgs/pkgs/test/mkOption/test.sh b/nixpkgs/pkgs/test/mkOption/test.sh
new file mode 100755
index 000000000000..5478846d563f
--- /dev/null
+++ b/nixpkgs/pkgs/test/mkOption/test.sh
@@ -0,0 +1,9 @@
+#! /bin/sh -e
+
+echo 1>&2 "Test: Merge of option bindings."
+nix-instantiate merge.nix --eval-only --strict --xml >& merge.out
+diff merge.ref merge.out
+
+echo 1>&2 "Test: Filter of option declarations."
+nix-instantiate keep.nix --eval-only --strict --xml >& keep.out
+diff keep.ref keep.out
diff --git a/nixpkgs/pkgs/test/nixos-functions/default.nix b/nixpkgs/pkgs/test/nixos-functions/default.nix
new file mode 100644
index 000000000000..6a4f3164f929
--- /dev/null
+++ b/nixpkgs/pkgs/test/nixos-functions/default.nix
@@ -0,0 +1,41 @@
+/*
+
+This file is a test that makes sure that the `pkgs.nixos` and
+`pkgs.nixosTest` functions work. It's far from a perfect test suite,
+but better than not checking them at all on hydra.
+
+To run this test:
+
+    nixpkgs$ nix-build -A tests.nixos-functions
+
+ */
+{ pkgs, lib, stdenv, ... }:
+
+let
+  dummyVersioning = {
+    revision = "test";
+    versionSuffix = "test";
+    label = "test";
+  };
+in lib.optionalAttrs stdenv.hostPlatform.isLinux (
+  pkgs.recurseIntoAttrs {
+
+    nixos-test = (pkgs.nixos {
+      system.nixos = dummyVersioning;
+      boot.loader.grub.enable = false;
+      fileSystems."/".device = "/dev/null";
+    }).toplevel;
+
+    nixosTest-test = pkgs.nixosTest ({ lib, pkgs, ... }: {
+      name = "nixosTest-test";
+      machine = { pkgs, ... }: {
+        system.nixos = dummyVersioning;
+        environment.systemPackages = [ pkgs.hello ];
+      };
+      testScript = ''
+        machine.succeed("hello")
+      '';
+    });
+
+  }
+)
diff --git a/nixpkgs/pkgs/test/patch-shebangs/default.nix b/nixpkgs/pkgs/test/patch-shebangs/default.nix
new file mode 100644
index 000000000000..5c49787eee3b
--- /dev/null
+++ b/nixpkgs/pkgs/test/patch-shebangs/default.nix
@@ -0,0 +1,70 @@
+{ lib, stdenv, runCommand }:
+
+let
+  tests = {
+    bad-shebang = stdenv.mkDerivation {
+      name         = "bad-shebang";
+      dontUnpack = true;
+      installPhase = ''
+        mkdir -p $out/bin
+        echo "#!/bin/sh" > $out/bin/test
+        echo "echo -n hello" >> $out/bin/test
+        chmod +x $out/bin/test
+      '';
+      passthru = {
+        assertion = "grep -v '^#!/bin/sh' $out/bin/test > /dev/null";
+      };
+    };
+
+    ignores-nix-store = stdenv.mkDerivation {
+      name = "ignores-nix-store";
+      dontUnpack = true;
+      installPhase = ''
+        mkdir -p $out/bin
+        echo "#!$NIX_STORE/path/to/sh" > $out/bin/test
+        echo "echo -n hello" >> $out/bin/test
+        chmod +x $out/bin/test
+      '';
+      passthru = {
+        assertion = "grep \"^#!$NIX_STORE/path/to/sh\" $out/bin/test > /dev/null";
+      };
+    };
+  };
+in runCommand "patch-shebangs-test" {
+  passthru = { inherit (tests) bad-shebang ignores-nix-store; };
+  meta.platforms = lib.platforms.all;
+} ''
+  validate() {
+    local name=$1
+    local testout=$2
+    local assertion=$3
+
+    echo -n "... $name: " >&2
+
+    local rc=0
+    (out=$testout eval "$assertion") || rc=1
+
+    if [ "$rc" -eq 0 ]; then
+      echo "yes" >&2
+    else
+      echo "no" >&2
+    fi
+
+    return "$rc"
+  }
+
+  echo "checking whether patchShebangs works properly... ">&2
+
+  fail=
+  ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
+    validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1
+  '') tests)}
+
+  if [ "$fail" ]; then
+    echo "failed"
+    exit 1
+  else
+    echo "succeeded"
+    touch $out
+  fi
+''
diff --git a/nixpkgs/pkgs/test/rust-sysroot/default.nix b/nixpkgs/pkgs/test/rust-sysroot/default.nix
new file mode 100644
index 000000000000..a5a1596504f9
--- /dev/null
+++ b/nixpkgs/pkgs/test/rust-sysroot/default.nix
@@ -0,0 +1,60 @@
+{ lib, rust, rustPlatform, fetchFromGitHub }:
+
+let
+  mkBlogOsTest = target: rustPlatform.buildRustPackage rec {
+    name = "blog_os-sysroot-test";
+
+    src = fetchFromGitHub {
+        owner = "phil-opp";
+        repo = "blog_os";
+        rev = "4e38e7ddf8dd021c3cd7e4609dfa01afb827797b";
+        sha256 = "0k9ipm9ddm1bad7bs7368wzzp6xwrhyfzfpckdax54l4ffqwljcg";
+    };
+
+    cargoSha256 = "1x8iwgy1irgfkv2yjkxm6479nwbrk82b0c80jm7y4kw0s32r01lg";
+
+    inherit target;
+
+    RUSTFLAGS = "-C link-arg=-nostartfiles";
+
+    # Tests don't work for `no_std`. See https://os.phil-opp.com/testing/
+    doCheck = false;
+
+    meta = with lib; {
+        description = "Test for using custom sysroots with buildRustPackage";
+        maintainers = with maintainers; [ aaronjanse ];
+        platforms = lib.platforms.x86_64;
+    };
+  };
+
+  # The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS.
+  # The justification in the book for using rust-lld suggests that gcc can still be used for testing:
+  # > Instead of using the platform's default linker (which might not support Linux targets),
+  # > we use the cross platform LLD linker that is shipped with Rust for linking our kernel.
+  # https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157
+  targetContents = {
+    "llvm-target" = "x86_64-unknown-none";
+    "data-layout" = "e-m:e-i64:64-f80:128-n8:16:32:64-S128";
+    "arch" = "x86_64";
+    "target-endian" = "little";
+    "target-pointer-width" = "64";
+    "target-c-int-width" = "32";
+    "os" = "none";
+    "executables" = true;
+    "linker-flavor" = "gcc";
+    "panic-strategy" = "abort";
+    "disable-redzone" = true;
+    "features" = "-mmx,-sse,+soft-float";
+  };
+
+in {
+  blogOS-targetByFile = mkBlogOsTest (builtins.toFile "x86_64-blog_os.json" (builtins.toJSON targetContents));
+  blogOS-targetByNix = let
+    plat = lib.systems.elaborate { config = "x86_64-none"; } // {
+      rustc = {
+        config = "x86_64-blog_os";
+        platform = targetContents;
+      };
+    };
+    in mkBlogOsTest (rust.toRustTargetSpec plat);
+}
diff --git a/nixpkgs/pkgs/test/simple/builder.sh b/nixpkgs/pkgs/test/simple/builder.sh
new file mode 100644
index 000000000000..65f7e4c11ba1
--- /dev/null
+++ b/nixpkgs/pkgs/test/simple/builder.sh
@@ -0,0 +1,42 @@
+set -x
+
+export NIX_DEBUG=1
+
+source $stdenv/setup
+
+export NIX_ENFORCE_PURITY=1
+
+mkdir $out
+mkdir $out/bin
+
+cat > hello.c <<EOF
+#include <stdio.h>
+
+int main(int argc, char * * argv)
+{
+    printf("Hello World!\n");
+    return 0;
+}
+EOF
+
+#gcc -I/nix/store/foo -I /nix/store/foo -I/usr/lib -I /usr/lib hello.c -o $out/bin/hello
+gcc -I`pwd` -L /nix/store/abcd/lib -isystem /usr/lib hello.c -o $out/bin/hello
+
+$out/bin/hello
+
+cat > hello2.cc <<EOF
+#include <iostream>
+
+int main(int argc, char * * argv)
+{
+    std::cout << "Hello World!\n";
+    std::cout << VALUE << std::endl;
+    return 0;
+}
+EOF
+
+g++ hello2.cc -o $out/bin/hello2 -DVALUE="1 + 2 * 3"
+
+$out/bin/hello2
+
+ld -v
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/bar.c b/nixpkgs/pkgs/test/stdenv-inputs/bar.c
new file mode 100644
index 000000000000..2d7299c2d462
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/bar.c
@@ -0,0 +1,3 @@
+unsigned int bar(void) {
+  return 42;
+}
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/cc-main.c b/nixpkgs/pkgs/test/stdenv-inputs/cc-main.c
new file mode 100644
index 000000000000..06f28bc33c69
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/cc-main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/default.nix b/nixpkgs/pkgs/test/stdenv-inputs/default.nix
new file mode 100644
index 000000000000..6a2e441d0191
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/default.nix
@@ -0,0 +1,68 @@
+{ lib, stdenv }:
+
+let
+  foo = stdenv.mkDerivation {
+    name = "foo-test";
+
+    dontUnpack = true;
+
+    installPhase = ''
+      mkdir -p $out/bin $out/include $out/lib
+      $CC -o $out/bin/foo ${./cc-main.c}
+      chmod +x $out/bin/foo
+      cp ${./foo.c} $out/include/foo.h
+      $CC -shared \
+        ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/libfoo.dylib"} \
+        -o $out/lib/libfoo${stdenv.hostPlatform.extensions.sharedLibrary} \
+        ${./foo.c}
+    '';
+  };
+
+  bar = stdenv.mkDerivation {
+    name = "bar-test";
+    outputs = [ "out" "dev" ];
+
+    dontUnpack = true;
+
+    installPhase = ''
+      mkdir -p $out/bin $dev/include $dev/lib
+      $CC -o $out/bin/bar ${./cc-main.c}
+      chmod +x $out/bin/bar
+      cp ${./bar.c} $dev/include/bar.h
+      $CC -shared \
+        ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,$dev/lib/libbar.dylib"} \
+        -o $dev/lib/libbar${stdenv.hostPlatform.extensions.sharedLibrary} \
+        ${./bar.c}
+    '';
+  };
+in
+
+stdenv.mkDerivation {
+  name = "stdenv-inputs-test";
+  phases = [ "buildPhase" ];
+
+  buildInputs = [ foo bar ];
+
+  buildPhase = ''
+    env
+
+    printf "checking whether binaries are available... " >&2
+    foo && bar
+
+    printf "checking whether compiler can find headers... " >&2
+    $CC -o include-check ${./include-main.c}
+    ./include-check
+
+    printf "checking whether compiler can find headers... " >&2
+    $CC -o include-check ${./include-main.c}
+    ./include-check
+
+    printf "checking whether compiler can find libraries... " >&2
+    $CC -lfoo -lbar -o lib-check ${./lib-main.c}
+    ./lib-check
+
+    touch $out
+  '';
+
+  meta.platforms = lib.platforms.all;
+}
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/foo.c b/nixpkgs/pkgs/test/stdenv-inputs/foo.c
new file mode 100644
index 000000000000..0253a26d5d2c
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/foo.c
@@ -0,0 +1,3 @@
+unsigned int foo(void) {
+  return 42;
+}
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/include-main.c b/nixpkgs/pkgs/test/stdenv-inputs/include-main.c
new file mode 100644
index 000000000000..35e5ee0d90f7
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/include-main.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <foo.h>
+#include <bar.h>
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42)
+    return 1;
+  if (bar() != 42)
+    return 1;
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/stdenv-inputs/lib-main.c b/nixpkgs/pkgs/test/stdenv-inputs/lib-main.c
new file mode 100644
index 000000000000..c9488fe43e55
--- /dev/null
+++ b/nixpkgs/pkgs/test/stdenv-inputs/lib-main.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+extern unsigned int foo(void);
+extern unsigned int bar(void);
+
+int main(int argc, char **argv)
+{
+  if (foo() != 42)
+    return 1;
+  if (bar() != 42)
+    return 1;
+  fprintf(stderr, "ok\n");
+  return 0;
+}
diff --git a/nixpkgs/pkgs/test/texlive/default.nix b/nixpkgs/pkgs/test/texlive/default.nix
new file mode 100644
index 000000000000..86c0a7f795b7
--- /dev/null
+++ b/nixpkgs/pkgs/test/texlive/default.nix
@@ -0,0 +1,122 @@
+{ lib, runCommandNoCC, fetchurl, file, texlive, writeShellScript }:
+
+{
+  chktex = runCommandNoCC "texlive-test-chktex" {
+    nativeBuildInputs = [
+      (with texlive; combine { inherit scheme-infraonly chktex; })
+    ];
+    input = builtins.toFile "chktex-sample.tex" ''
+      \documentclass{article}
+      \begin{document}
+        \LaTeX is great
+      \end{document}
+    '';
+  } ''
+    chktex -v -nall -w1 "$input" 2>&1 | tee "$out"
+    grep "One warning printed" "$out"
+  '';
+
+  dvipng = lib.recurseIntoAttrs {
+    # https://github.com/NixOS/nixpkgs/issues/75605
+    basic = runCommandNoCC "texlive-test-dvipng-basic" {
+      nativeBuildInputs = [ file texlive.combined.scheme-medium ];
+      input = fetchurl {
+        name = "test_dvipng.tex";
+        url = "http://git.savannah.nongnu.org/cgit/dvipng.git/plain/test_dvipng.tex?id=b872753590a18605260078f56cbd6f28d39dc035";
+        sha256 = "1pjpf1jvwj2pv5crzdgcrzvbmn7kfmgxa39pcvskl4pa0c9hl88n";
+      };
+    } ''
+      cp "$input" ./document.tex
+
+      latex document.tex
+      dvipng -T tight -strict -picky document.dvi
+      for f in document*.png; do
+        file "$f" | tee output
+        grep PNG output
+      done
+
+      mkdir "$out"
+      mv document*.png "$out"/
+    '';
+
+    # test dvipng's limited capability to render postscript specials via GS
+    ghostscript = runCommandNoCC "texlive-test-ghostscript" {
+      nativeBuildInputs = [ file (with texlive; combine { inherit scheme-small dvipng; }) ];
+      input = builtins.toFile "postscript-sample.tex" ''
+        \documentclass{minimal}
+        \begin{document}
+          Ni
+          \special{ps:
+            newpath
+            0 0 moveto
+            7 7 rlineto
+            0 7 moveto
+            7 -7 rlineto
+            stroke
+            showpage
+          }
+        \end{document}
+      '';
+      gs_trap = writeShellScript "gs_trap.sh" ''
+        exit 1
+      '';
+    } ''
+      cp "$gs_trap" ./gs
+      export PATH=$PWD:$PATH
+      # check that the trap works
+      gs && exit 1
+
+      cp "$input" ./document.tex
+
+      latex document.tex
+      dvipng -T 1in,1in -strict -picky document.dvi
+      for f in document*.png; do
+        file "$f" | tee output
+        grep PNG output
+      done
+
+      mkdir "$out"
+      mv document*.png "$out"/
+    '';
+  };
+
+  # https://github.com/NixOS/nixpkgs/issues/75070
+  dvisvgm = runCommandNoCC "texlive-test-dvisvgm" {
+    nativeBuildInputs = [ file texlive.combined.scheme-medium ];
+    input = builtins.toFile "dvisvgm-sample.tex" ''
+      \documentclass{article}
+      \begin{document}
+        mwe
+      \end{document}
+    '';
+  } ''
+    cp "$input" ./document.tex
+
+    latex document.tex
+    dvisvgm document.dvi -n -o document_dvi.svg
+    cat document_dvi.svg
+    file document_dvi.svg | grep SVG
+
+    pdflatex document.tex
+    dvisvgm -P document.pdf -n -o document_pdf.svg
+    cat document_pdf.svg
+    file document_pdf.svg | grep SVG
+
+    mkdir "$out"
+    mv document*.svg "$out"/
+  '';
+
+  texdoc = runCommandNoCC "texlive-test-texdoc" {
+    nativeBuildInputs = [
+      (with texlive; combine {
+        inherit scheme-infraonly luatex texdoc;
+        pkgFilter = pkg: lib.elem pkg.tlType [ "run" "bin" "doc" ];
+      })
+    ];
+  } ''
+    texdoc --version
+
+    texdoc --debug --list texdoc | tee "$out"
+    grep texdoc.pdf "$out"
+  '';
+}
diff --git a/nixpkgs/pkgs/test/vim/default.nix b/nixpkgs/pkgs/test/vim/default.nix
new file mode 100644
index 000000000000..cb3953a63f52
--- /dev/null
+++ b/nixpkgs/pkgs/test/vim/default.nix
@@ -0,0 +1,63 @@
+{ vimUtils, vim_configurable, writeText, vimPlugins
+, lib, fetchFromGitHub
+, pkgs
+}:
+let
+  inherit (vimUtils) buildVimPluginFrom2Nix;
+
+  packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
+
+in
+  pkgs.recurseIntoAttrs (rec {
+  vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
+
+  ### vim tests
+  ##################
+  vim_with_vim2nix = vim_configurable.customize {
+    name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
+  };
+
+  # test cases:
+  test_vim_with_vim_nix_using_vam = vim_configurable.customize {
+   name = "vim-with-vim-addon-nix-using-vam";
+    vimrcConfig.vam.pluginDictionaries = [{name = "vim-nix"; }];
+  };
+
+  test_vim_with_vim_nix_using_pathogen = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix-using-pathogen";
+    vimrcConfig.pathogen.pluginNames = [ "vim-nix" ];
+  };
+
+  test_vim_with_vim_nix_using_plug = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix-using-plug";
+    vimrcConfig.plug.plugins = with vimPlugins; [ vim-nix ];
+  };
+
+  test_vim_with_vim_nix = vim_configurable.customize {
+    name = "vim-with-vim-addon-nix";
+    vimrcConfig.packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
+  };
+
+  # regression test for https://github.com/NixOS/nixpkgs/issues/53112
+  # The user may have specified their own plugins which may not be formatted
+  # exactly as the generated ones. In particular, they may not have the `pname`
+  # attribute.
+  test_vim_with_custom_plugin = vim_configurable.customize {
+    name = "vim_with_custom_plugin";
+    vimrcConfig.vam.knownPlugins =
+      vimPlugins // ({
+        vim-trailing-whitespace = buildVimPluginFrom2Nix {
+          name = "vim-trailing-whitespace";
+          src = fetchFromGitHub {
+            owner = "bronson";
+            repo = "vim-trailing-whitespace";
+            rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
+            sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
+          };
+          # make sure string dependencies are handled
+          dependencies = [ "vim-nix" ];
+        };
+      });
+    vimrcConfig.vam.pluginDictionaries = [ { names = [ "vim-trailing-whitespace" ]; } ];
+  };
+})