lol

symlinkJoin: documentation & tests for stripPrefix

+167 -6
+30 -6
pkgs/build-support/trivial-builders/default.nix
··· 466 466 ... 467 467 468 468 469 + To create a directory structure from a specific subdirectory of input `paths` instead of their full trees, 470 + you can either append the subdirectory path to each input path, or use the `stripPrefix` argument to 471 + remove the common prefix during linking. 472 + 473 + Example: 474 + 475 + 476 + # create symlinks of tmpfiles.d rules from multiple packages 477 + symlinkJoin { name = "tmpfiles.d"; paths = [ pkgs.lvm2 pkgs.nix ]; stripPrefix = "/lib/tmpfiles.d"; } 478 + 479 + 480 + This creates a derivation with a directory structure like the following: 481 + 482 + 483 + /nix/store/m5s775yicb763hfa133jwml5hwmwzv14-tmpfiles.d 484 + |-- lvm2.conf -> /nix/store/k6js0l5f0zpvrhay49579fj939j77p2w-lvm2-2.03.29/lib/tmpfiles.d/lvm2.conf 485 + `-- nix-daemon.conf -> /nix/store/z4v2s3s3y79fmabhps5hakb3c5dwaj5a-nix-1.33.7/lib/tmpfiles.d/nix-daemon.conf 486 + 487 + 488 + By default, packages that don't contain the specified subdirectory are silently skipped. 489 + Set `failOnMissing = true` to make the build fail if any input package is missing the subdirectory 490 + (this is the default behavior when not using stripPrefix). 491 + 469 492 symlinkJoin and linkFarm are similar functions, but they output 470 493 derivations with different structure. 471 494 ··· 495 518 , failOnMissing ? stripPrefix == "" 496 519 , ... 497 520 }: 498 - # Ensure no partial paths used, it will be confusing considering 499 - # most of the time symlinkJoin is used with packages. 500 - assert (stripPrefix == "" || (hasPrefix "/" stripPrefix) && stripPrefix != "/"); 521 + assert lib.assertMsg (stripPrefix != "" -> (hasPrefix "/" stripPrefix && stripPrefix != "/")) '' 522 + stripPrefix must be either an empty string (disable stripping behavior), or relative path prefixed with /. 523 + 524 + Ensure that the path starts with / and specifies path to the subdirectory. 525 + ''; 526 + 501 527 let 502 528 mapPaths = f: paths: map (path: 503 529 if path == null then null ··· 510 536 paths = mapPaths (path: "${path}${stripPrefix}") paths; 511 537 passAsFile = [ "paths" ]; 512 538 }; # pass the defaults 513 - ignoreMissing = optionalString (!failOnMissing) "test -d $i && "; 514 - ignoreError = optionalString (!failOnMissing) " || true"; 515 539 in 516 540 runCommand name args 517 541 '' 518 542 mkdir -p $out 519 543 for i in $(cat $pathsPath); do 520 - ${ignoreMissing}${lndir}/bin/lndir -silent $i $out${ignoreError} 544 + ${optionalString (!failOnMissing) "if test -d $i; then "}${lndir}/bin/lndir -silent $i $out${optionalString (!failOnMissing) "; fi"} 521 545 done 522 546 ${postBuild} 523 547 '';
+1
pkgs/build-support/trivial-builders/test/default.nix
··· 19 19 recurseIntoAttrs { 20 20 concat = callPackage ./concat-test.nix {}; 21 21 linkFarm = callPackage ./link-farm.nix {}; 22 + symlinkJoin = recurseIntoAttrs (callPackage ./symlink-join.nix {}); 22 23 overriding = callPackage ../test-overriding.nix {}; 23 24 inherit references; 24 25 writeCBin = callPackage ./writeCBin.nix {};