summary refs log tree commit diff
path: root/pkgs/lib/customisation.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/lib/customisation.nix')
-rw-r--r--pkgs/lib/customisation.nix17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix
index 18cec3209f97..a35b44e9f6ee 100644
--- a/pkgs/lib/customisation.nix
+++ b/pkgs/lib/customisation.nix
@@ -99,4 +99,21 @@ rec {
     let f = if builtins.isFunction fn then fn else import fn; in
     makeOverridable f ((builtins.intersectAttrs (builtins.functionArgs f) autoArgs) // args);
 
+  /* Add attributes to each output of a derivation without changing the derivation itself */
+  addPassthru = drv: passthru:
+    let
+      outputs = drv.outputs or [ "out" ];
+
+      commonAttrs = drv // (builtins.listToAttrs outputsList) //
+        ({ all = map (x: x.value) outputsList; }) // passthru;
+
+      outputToAttrListElement = outputName:
+        { name = outputName;
+          value = commonAttrs // {
+            inherit (builtins.getAttr outputName drv) outPath drvPath type outputName;
+          };
+        };
+
+      outputsList = map outputToAttrListElement outputs;
+  in builtins.getAttr drv.outputName commonAttrs;
 }