Something went wrong. Try again.
What happens if I push all of nixpkgs
Something went wrong. Try again.
6.6 kB · 260 lines
Nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261{ bash, coreutils, devShellTools, emptyFile, gnugrep, lib, runCommand, stdenv, hello, writeText, zlib, nixosTests,}:let inherit (lib) concatLines escapeShellArg isString mapAttrsToList ;inlib.recurseIntoAttrs {
# nix-build -A tests.devShellTools.nixos nixos = nixosTests.docker-tools-nix-shell;
# nix-build -A tests.devShellTools.valueToString valueToString = let inherit (devShellTools) valueToString; in
stdenv.mkDerivation { name = "devShellTools-valueToString-built-tests";
# Test inputs inherit emptyFile hello; one = 1; boolTrue = true; boolFalse = false; foo = "foo"; list = [ 1 2 3 ]; pathDefaultNix = ./default.nix; packages = [ hello emptyFile ]; # TODO: nested lists
buildCommand = '' touch $out ( set -x [[ "$one" = ${escapeShellArg (valueToString 1)} ]] [[ "$boolTrue" = ${escapeShellArg (valueToString true)} ]] [[ "$boolFalse" = ${escapeShellArg (valueToString false)} ]] [[ "$foo" = ${escapeShellArg (valueToString "foo")} ]] [[ "$hello" = ${escapeShellArg (valueToString hello)} ]] [[ "$list" = ${ escapeShellArg (valueToString [ 1 2 3 ]) } ]] [[ "$packages" = ${ escapeShellArg (valueToString [ hello emptyFile ]) } ]] [[ "$pathDefaultNix" = ${escapeShellArg (valueToString ./default.nix)} ]] [[ "$emptyFile" = ${escapeShellArg (valueToString emptyFile)} ]] ) >log 2>&1 || { cat log; exit 1; } ''; };
# nix-build -A tests.devShellTools.valueToString unstructuredDerivationInputEnv = let inherit (devShellTools) unstructuredDerivationInputEnv;
drvAttrs = { one = 1; boolTrue = true; boolFalse = false; foo = "foo"; list = [ 1 2 3 ]; pathDefaultNix = ./default.nix; stringWithDep = "Exe: ${hello}/bin/hello"; aPackageAttrSet = hello; anOutPath = hello.outPath; anAnAlternateOutput = zlib.dev; args = [ "args must not be added to the environment" "Nix doesn't do it." ];
passAsFile = [ "bar" ]; bar = '' bar ${writeText "qux" "yea"} ''; }; result = unstructuredDerivationInputEnv { inherit drvAttrs; }; in assert result // { barPath = "<check later>"; } == { one = "1"; boolTrue = "1"; boolFalse = ""; foo = "foo"; list = "1 2 3"; pathDefaultNix = "${./default.nix}"; stringWithDep = "Exe: ${hello}/bin/hello"; aPackageAttrSet = "${hello}"; anOutPath = "${hello.outPath}"; anAnAlternateOutput = "${zlib.dev}";
passAsFile = "bar"; barPath = "<check later>"; };
# Not runCommand, because it alters `passAsFile` stdenv.mkDerivation ( { name = "devShellTools-unstructuredDerivationInputEnv-built-tests";
exampleBarPathString = assert isString result.barPath; result.barPath;
dontUnpack = true; dontBuild = true; dontFixup = true; doCheck = true;
installPhase = "touch $out";
checkPhase = '' fail() { echo "$@" >&2 exit 1 } checkAttr() { echo checking attribute $1... if [[ "$2" != "$3" ]]; then echo "expected: $3" echo "actual: $2" exit 1 fi } ${concatLines ( mapAttrsToList (name: value: "checkAttr ${name} \"\$${name}\" ${escapeShellArg value}") ( removeAttrs result [ "args"
# Nix puts it in workdir, which is not a concept for # unstructuredDerivationInputEnv, so we have to put it in the # store instead. This means the full path won't match. "barPath" ] ) )} ( set -x
diff $exampleBarPathString $barPath
${lib.optionalString (builtins ? convertHash) '' [[ "$(basename $exampleBarPathString)" = "$(basename $barPath)" ]] ''} )
''${args:+fail "args should not be set by Nix. We don't expect it to and unstructuredDerivationInputEnv removes it."} if [[ "''${builder:-x}" == x ]]; then fail "builder should be set by Nix. We don't remove it in unstructuredDerivationInputEnv." fi ''; } // removeAttrs drvAttrs [ # This would break the derivation. Instead, we have a check in the derivation to make sure Nix doesn't set it. "args" ] );
# derivation: Call it directly so that we get a minimal environment to run in buildHelloInShell = derivation { inherit (stdenv.buildPlatform) system; name = "buildHelloInShell"; builder = "${bash}/bin/bash"; PATH = lib.makeBinPath [ coreutils gnugrep ]; args = [ "-euo" "pipefail" "-c" '' ${lib.getExe hello.devShell} -c 'genericBuild && ln -s $out "'"$PWD"'/result"' ls -al ./result/bin/hello | grep -i 'hello, world' (set -x; [[ ! -e $out ]]) touch $out '' ]; } // { # Required package attributes for Nixpkgs (CI) meta = { }; };
various = let hello2 = hello.overrideAttrs (o: { shellHook = '' echo 'shellHook says hi :)' ''; }); inherit (hello2) devShell; in derivation { inherit (stdenv.buildPlatform) system; name = "various"; builder = "${bash}/bin/bash"; PATH = lib.makeBinPath [ coreutils gnugrep ]; args = [ "-euo" "pipefail" "-c" '' ${lib.getExe devShell} -c 'echo "hello, world"' \ | grep -F 'hello, world' ${lib.getExe devShell} -c 'echo "hello, world"' \ | grep -F 'hello, world'
ls -al (set -x; [[ ! -e $out ]]) touch $out '' ]; } // { # Required package attributes for Nixpkgs (CI) meta = { }; };}