query
On this page

linkFarm

pkgs.linkFarm

Docs pulled from | This Revision | 43 minutes ago


Quickly create a set of symlinks to derivations.

This creates a simple derivation with symlinks to all inputs.

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/..."; }

Inputs

name

1. Function argument

entries

2. Function argument

Examples

linkFarm usage example

# Symlinks hello and stack paths in store to current $out/hello-test and
# $out/foobar.
linkFarm "myexample" [ { name = "hello-test"; path = pkgs.hello; } { name = "foobar"; path = pkgs.stack; } ]

This creates a derivation with a directory structure like the following:

/nix/store/qc5728m4sa344mbks99r3q05mymwm4rw-myexample
|-- foobar -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1
`-- hello-test -> /nix/store/qy93dp4a3rqyn2mz63fbxjg228hffwyw-hello-2.10


See the note on symlinkJoin for the difference between linkFarm and symlinkJoin.

Noogle detected

Implementation

The following is the current implementation of this function.

linkFarm = name: entries:
    let
      entries' =
        if (lib.isAttrs entries) then entries
        # We do this foldl to have last-wins semantics in case of repeated entries
        else if (lib.isList entries) then lib.foldl (a: b: a // { "${b.name}" = b.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.concatStrings linkCommands}
    '';