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 }:
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 , # If there is a collision, check whether the contents and permissions match
27 # and only if not, throw a collision error.
28 checkCollisionContents ? true
30 , # The paths (relative to each element of `paths') that we want to
31 # symlink (e.g., ["/bin"]). Any file not inside any of the
32 # directories in the list is not symlinked.
35 , # The package outputs to include. By default, only the default
37 extraOutputsToInstall ? []
39 , # Root the result in directory "$out${extraPrefix}", e.g. "/share".
42 , # Shell commands to run after building the symlink tree.
46 , nativeBuildInputs ? [] # Handy e.g. if using makeWrapper in `postBuild`.
55 inherit manifest ignoreCollisions checkCollisionContents passthru
56 meta pathsToLink extraPrefix postBuild
57 nativeBuildInputs buildInputs;
58 pkgs = builtins.toJSON (map (drv: {
60 # First add the usual output(s): respect if user has chosen explicitly,
61 # and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
62 # to exist in mkDerivation-created cases. The other cases (e.g. runCommand)
63 # aren't expected to have multiple outputs.
64 (if (! drv ? outputSpecified || ! drv.outputSpecified)
65 && drv.meta.outputsToInstall or null != null
66 then map (outName: drv.${outName}) drv.meta.outputsToInstall
68 # Add any extra outputs specified by the caller of `buildEnv`.
69 ++ lib.filter (p: p!=null)
70 (builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
71 priority = drv.meta.priority or lib.meta.defaultPriority;
73 preferLocalBuild = true;
74 allowSubstitutes = false;
75 # XXX: The size is somewhat arbitrary
76 passAsFile = if builtins.stringLength pkgs >= 128*1024 then [ "pkgs" ] else [ ];
79 ${buildPackages.perl}/bin/perl -w ${builder}