···466466 ...
467467468468469469+ To create a directory structure from a specific subdirectory of input `paths` instead of their full trees,
470470+ you can either append the subdirectory path to each input path, or use the `stripPrefix` argument to
471471+ remove the common prefix during linking.
472472+473473+ Example:
474474+475475+476476+ # create symlinks of tmpfiles.d rules from multiple packages
477477+ symlinkJoin { name = "tmpfiles.d"; paths = [ pkgs.lvm2 pkgs.nix ]; stripPrefix = "/lib/tmpfiles.d"; }
478478+479479+480480+ This creates a derivation with a directory structure like the following:
481481+482482+483483+ /nix/store/m5s775yicb763hfa133jwml5hwmwzv14-tmpfiles.d
484484+ |-- lvm2.conf -> /nix/store/k6js0l5f0zpvrhay49579fj939j77p2w-lvm2-2.03.29/lib/tmpfiles.d/lvm2.conf
485485+ `-- nix-daemon.conf -> /nix/store/z4v2s3s3y79fmabhps5hakb3c5dwaj5a-nix-1.33.7/lib/tmpfiles.d/nix-daemon.conf
486486+487487+488488+ By default, packages that don't contain the specified subdirectory are silently skipped.
489489+ Set `failOnMissing = true` to make the build fail if any input package is missing the subdirectory
490490+ (this is the default behavior when not using stripPrefix).
491491+469492 symlinkJoin and linkFarm are similar functions, but they output
470493 derivations with different structure.
471494···495518 , failOnMissing ? stripPrefix == ""
496519 , ...
497520 }:
498498- # Ensure no partial paths used, it will be confusing considering
499499- # most of the time symlinkJoin is used with packages.
500500- assert (stripPrefix == "" || (hasPrefix "/" stripPrefix) && stripPrefix != "/");
521521+ assert lib.assertMsg (stripPrefix != "" -> (hasPrefix "/" stripPrefix && stripPrefix != "/")) ''
522522+ stripPrefix must be either an empty string (disable stripping behavior), or relative path prefixed with /.
523523+524524+ Ensure that the path starts with / and specifies path to the subdirectory.
525525+ '';
526526+501527 let
502528 mapPaths = f: paths: map (path:
503529 if path == null then null
···510536 paths = mapPaths (path: "${path}${stripPrefix}") paths;
511537 passAsFile = [ "paths" ];
512538 }; # pass the defaults
513513- ignoreMissing = optionalString (!failOnMissing) "test -d $i && ";
514514- ignoreError = optionalString (!failOnMissing) " || true";
515539 in
516540 runCommand name args
517541 ''
518542 mkdir -p $out
519543 for i in $(cat $pathsPath); do
520520- ${ignoreMissing}${lndir}/bin/lndir -silent $i $out${ignoreError}
544544+ ${optionalString (!failOnMissing) "if test -d $i; then "}${lndir}/bin/lndir -silent $i $out${optionalString (!failOnMissing) "; fi"}
521545 done
522546 ${postBuild}
523547 '';