Skip to content

Commit

Permalink
Integrate sources with subpaths into mkDerivation
Browse files Browse the repository at this point in the history
Make root, subpath internal

Adapted from NixOS#112083

Co-Authored-By: Robert Hensing <[email protected]>
  • Loading branch information
infinisil and roberth committed Jun 14, 2023
1 parent 14e18fe commit 4576c67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/fileset.nix
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ in {
fileset :: FileSet,
} -> {
outPath :: String,
root :: String,
subpath :: String,
_root :: String,
_subpath :: String,
}
*/
importToStore = { name ? "source", base ? entryPoint, entryPoint, fileset }:
Expand Down Expand Up @@ -497,8 +497,8 @@ in {
};
components = removePrefix base entryPoint;
in {
inherit root;
subpath = toSubpath components;
_root = root;
_subpath = toSubpath components;
outPath =
if components == [] then
root
Expand Down
14 changes: 14 additions & 0 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,20 @@ else let
inherit doCheck doInstallCheck;

inherit outputs;

${if attrs ? src then "src" else null} =
if attrs.src ? _root && attrs.src ? _subpath then
attrs.src.root
else
attrs.src;

# TODO simplify by adding to unpackPhase instead.
# This wasn't done yet to avoid a mass rebuild while working on this.
postUnpack = if attrs.src ? _root && attrs.src ? _subpath && attrs.src._subpath != "./." then ''
sourceRoot="$sourceRoot"/${lib.escapeShellArg attrs.src._subpath}
${attrs.postUnpack or ""}
'' else attrs.postUnpack or null;

} // lib.optionalAttrs (__contentAddressed) {
inherit __contentAddressed;
# Provide default values for outputHashMode and outputHashAlgo because
Expand Down

0 comments on commit 4576c67

Please sign in to comment.