1 # buildEnv creates a tree of symlinks to the specified paths. This is
2 # a fork of the hardcoded buildEnv in the Nix distribution.
4 { buildPackages, runCommand, lib, substituteAll, writeClosure }:
7 builder = substituteAll {
9 inherit (builtins) storeDir;
16 , # The manifest file (if any). A symlink $out/manifest will be
20 , # The paths to symlink.
23 , # Whether to ignore collisions or abort.
24 ignoreCollisions ? false
26 , # Whether to include closures of all input paths.
27 includeClosures ? false
29 , # If there is a collision, check whether the contents and permissions match
30 # and only if not, throw a collision error.
31 checkCollisionContents ? true
33 , # The paths (relative to each element of `paths') that we want to
34 # symlink (e.g., ["/bin"]). Any file not inside any of the
35 # directories in the list is not symlinked.
38 , # The package outputs to include. By default, only the default
40 extraOutputsToInstall ? []
42 , # Root the result in directory "$out${extraPrefix}", e.g. "/share".
45 , # Shell commands to run after building the symlink tree.
49 , nativeBuildInputs ? [] # Handy e.g. if using makeWrapper in `postBuild`.
56 chosenOutputs = map (drv: {
58 # First add the usual output(s): respect if user has chosen explicitly,
59 # and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
60 # to exist in mkDerivation-created cases. The other cases (e.g. runCommand)
61 # aren't expected to have multiple outputs.
62 (if (! drv ? outputSpecified || ! drv.outputSpecified)
63 && drv.meta.outputsToInstall or null != null
64 then map (outName: drv.${outName}) drv.meta.outputsToInstall
66 # Add any extra outputs specified by the caller of `buildEnv`.
67 ++ lib.filter (p: p!=null)
68 (builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
69 priority = drv.meta.priority or lib.meta.defaultPriority;
72 pathsForClosure = lib.pipe chosenOutputs [
79 inherit manifest ignoreCollisions checkCollisionContents passthru
80 meta pathsToLink extraPrefix postBuild
81 nativeBuildInputs buildInputs;
82 pkgs = builtins.toJSON chosenOutputs;
83 extraPathsFrom = lib.optional includeClosures (writeClosure pathsForClosure);
84 preferLocalBuild = true;
85 allowSubstitutes = false;
86 # XXX: The size is somewhat arbitrary
87 passAsFile = if builtins.stringLength pkgs >= 128*1024 then [ "pkgs" ] else [ ];
90 ${buildPackages.perl}/bin/perl -w ${builder}