1 # buildEnv creates a tree of symlinks to the specified paths. This is
2 # a fork of the buildEnv in the Nix distribution. Most changes should
3 # eventually be merged back into the Nix distribution.
5 { buildPackages, runCommand, lib, substituteAll }:
10 , # The manifest file (if any). A symlink $out/manifest will be
14 , # The paths to symlink.
17 , # Whether to ignore collisions or abort.
18 ignoreCollisions ? false
20 , # If there is a collision, check whether the contents and permissions match
21 # and only if not, throw a collision error.
22 checkCollisionContents ? true
24 , # The paths (relative to each element of `paths') that we want to
25 # symlink (e.g., ["/bin"]). Any file not inside any of the
26 # directories in the list is not symlinked.
29 , # The package outputs to include. By default, only the default
31 extraOutputsToInstall ? []
33 , # Root the result in directory "$out${extraPrefix}", e.g. "/share".
36 , # Shell commands to run after building the symlink tree.
40 , nativeBuildInputs ? [] # Handy e.g. if using makeWrapper in `postBuild`.
48 builder = substituteAll {
50 inherit (builtins) storeDir;
56 inherit manifest ignoreCollisions checkCollisionContents passthru
57 meta pathsToLink extraPrefix postBuild
58 nativeBuildInputs buildInputs;
59 pkgs = builtins.toJSON (map (drv: {
61 # First add the usual output(s): respect if user has chosen explicitly,
62 # and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
63 # to exist in mkDerivation-created cases. The other cases (e.g. runCommand)
64 # aren't expected to have multiple outputs.
65 (if drv.outputUnspecified or false
66 && drv.meta.outputsToInstall or null != null
67 then map (outName: drv.${outName}) drv.meta.outputsToInstall
69 # Add any extra outputs specified by the caller of `buildEnv`.
70 ++ lib.filter (p: p!=null)
71 (builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
72 priority = drv.meta.priority or 5;
74 preferLocalBuild = true;
75 allowSubstitutes = false;
76 # XXX: The size is somewhat arbitrary
77 passAsFile = if builtins.stringLength pkgs >= 128*1024 then [ "pkgs" ] else [ ];
80 ${buildPackages.perl}/bin/perl -w ${builder}