From 4576c676752232a33a51ba565dbf8d4f8cdcf463 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 19 May 2023 17:25:30 +0200 Subject: [PATCH] Integrate sources with subpaths into mkDerivation Make root, subpath internal Adapted from https://github.com/NixOS/nixpkgs/pull/112083 Co-Authored-By: Robert Hensing --- lib/fileset.nix | 8 ++++---- pkgs/stdenv/generic/make-derivation.nix | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/fileset.nix b/lib/fileset.nix index d975068ebc911..40391960593f0 100644 --- a/lib/fileset.nix +++ b/lib/fileset.nix @@ -438,8 +438,8 @@ in { fileset :: FileSet, } -> { outPath :: String, - root :: String, - subpath :: String, + _root :: String, + _subpath :: String, } */ importToStore = { name ? "source", base ? entryPoint, entryPoint, fileset }: @@ -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 diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 40ad357739b70..52ddc9bc434d4 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -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