about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorBernardo Meurer <bernardo@meurer.org>2022-04-25 16:17:21 -0700
committerBernardo Meurer <bernardo@meurer.org>2022-11-15 11:01:52 -0500
commita93aed5bab972d3b5201d6067ecec998d8d62eaa (patch)
tree6e3f229327e6dcf653ffe09bd33b2a990592cbe4 /pkgs/build-support
parentb54257fb36b7d2c05778e6ff177dffad965186f4 (diff)
linkFarm: allow entries to be an attrset
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/trivial-builders.nix32
1 files changed, 22 insertions, 10 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 31313a30fa131..bd74ff7bb5321 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -458,8 +458,11 @@ rec {
    *
    * This creates a simple derivation with symlinks to all inputs.
    *
-   * entries is a list of attribute sets like
-   * { name = "name" ; path = "/nix/store/..."; }
+   * entries can be a list of attribute sets like
+   * [ { name = "name" ; path = "/nix/store/..."; } ]
+   *
+   * or an attribute set name -> path like:
+   * { name = "/nix/store/..."; other = "/nix/store/..."; }
    *
    * Example:
    *
@@ -475,17 +478,26 @@ rec {
    *
    * See the note on symlinkJoin for the difference between linkFarm and symlinkJoin.
    */
-   linkFarm = name: entries: runCommand name {
-     preferLocalBuild = true;
-     allowSubstitutes = false;
-     passthru = lib.listToAttrs (map (x: lib.nameValuePair x.name x.path) entries);
+  linkFarm = name: entries:
+  let
+    entries' =
+      if (lib.isAttrs entries) then entries
+      else if (lib.isList entries) then lib.listToAttrs (map (x: lib.nameValuePair x.name x.path) entries)
+      else throw "linkFarm entries must be either attrs or a list!";
+
+    linkCommands = lib.mapAttrsToList (name: path: ''
+      mkdir -p "$(dirname ${lib.escapeShellArg "${name}"})"
+      ln -s ${lib.escapeShellArg "${path}"} ${lib.escapeShellArg "${name}"}
+    '') entries';
+  in
+  runCommand name {
+    preferLocalBuild = true;
+    allowSubstitutes = false;
+    passthru.entries = entries';
    } ''
     mkdir -p $out
     cd $out
-    ${lib.concatMapStrings (x: ''
-      mkdir -p "$(dirname ${lib.escapeShellArg x.name})"
-      ln -s ${lib.escapeShellArg "${x.path}"} ${lib.escapeShellArg x.name}
-    '') entries}
+    ${lib.concatStrings linkCommands}
   '';
 
   /*