Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at master 73 lines 2.1 kB view raw
1{ 2 lib, 3 stdenv, 4 buildEnv, 5}: 6 7# A special kind of derivation that is only meant to be consumed by the 8# nix-shell. 9{ 10 name ? "nix-shell", 11 # a list of packages to add to the shell environment 12 packages ? [ ], 13 # propagate all the inputs from the given derivations 14 inputsFrom ? [ ], 15 buildInputs ? [ ], 16 nativeBuildInputs ? [ ], 17 propagatedBuildInputs ? [ ], 18 propagatedNativeBuildInputs ? [ ], 19 ... 20}@attrs: 21let 22 mergeInputs = 23 name: 24 (attrs.${name} or [ ]) 25 ++ 26 # 1. get all `{build,nativeBuild,...}Inputs` from the elements of `inputsFrom` 27 # 2. since that is a list of lists, `flatten` that into a regular list 28 # 3. filter out of the result everything that's in `inputsFrom` itself 29 # this leaves actual dependencies of the derivations in `inputsFrom`, but never the derivations themselves 30 (lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom))); 31 32 rest = removeAttrs attrs [ 33 "name" 34 "packages" 35 "inputsFrom" 36 "buildInputs" 37 "nativeBuildInputs" 38 "propagatedBuildInputs" 39 "propagatedNativeBuildInputs" 40 "shellHook" 41 ]; 42in 43 44stdenv.mkDerivation ( 45 { 46 inherit name; 47 48 buildInputs = mergeInputs "buildInputs"; 49 nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs"); 50 propagatedBuildInputs = mergeInputs "propagatedBuildInputs"; 51 propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs"; 52 53 shellHook = lib.concatStringsSep "\n" ( 54 lib.catAttrs "shellHook" (lib.reverseList inputsFrom ++ [ attrs ]) 55 ); 56 57 phases = [ "buildPhase" ]; 58 59 buildPhase = '' 60 { echo "------------------------------------------------------------"; 61 echo " WARNING: the existence of this path is not guaranteed."; 62 echo " It is an internal implementation detail for pkgs.mkShell."; 63 echo "------------------------------------------------------------"; 64 echo; 65 # Record all build inputs as runtime dependencies 66 export; 67 } >> "$out" 68 ''; 69 70 preferLocalBuild = true; 71 } 72 // rest 73)