From e509bf390e4fdbdc31dadfe769500344739fca57 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Fri, 21 Jan 2022 10:45:36 +1100 Subject: linkOutputs: rewrite to use script instead of environment variable Previous implementation had issues when linking large numbers of outputs due to large environment variables (buildCommand). This patch reimplements linkOutputs to place the linking commands in a script rather than hold the commands in an environment variable. --- default.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/default.nix b/default.nix index 3ec0450..842f55a 100644 --- a/default.nix +++ b/default.nix @@ -89,12 +89,8 @@ let def = f: defs: attrs: f (defs // attrs); linkOutputs = x: - with lib; - nixpkgs.stdenvNoCC.mkDerivation { - name = "link-outputs"; - outputs = [ "out" ] ++ attrNames x; - nativeBuildInputs = [ pkgs.perl ]; - buildCommand = + let + cmds = let recurse = x: if x ? type && x.type == "derivation" then @@ -104,14 +100,18 @@ let else abort "linkOutputs: unsupported type"; link = dst: src: '' - ln -s ${recurse src} $(perl -e 'print $ENV{"${dst}"}') ; ln -s ${ - recurse src - } $out/${dst} - ''; + ln -s ${recurse src} $(perl -e 'print $ENV{"${dst}"}') ; ln -s ${recurse src} $out/${dst} + ''; in '' - mkdir $out - '' + (concatStringsSep "\n" (mapAttrsToList link x)); + mkdir $out + ${lib.concatStringsSep "\n" (lib.mapAttrsToList link x)} + ''; + in + pkgs.stdenvNoCC.mkDerivation { + name = "link-outputs"; + nativeBuildInputs = [ pkgs.perl ]; + buildCommand = "exec sh ${pkgs.writeScript "make-links" cmds}"; passthru.linkInputs = x; }; -- cgit v1.2.3