lol

symlinkJoin: ability to strip prefix from tree (#345127)

authored by philiptaron.tngl.sh and committed by

GitHub 68fdbf5f ff597438

+180 -2
+43 -2
pkgs/build-support/trivial-builders/default.nix
··· 3 3 let 4 4 inherit (lib) 5 5 optionalAttrs 6 + optionalString 7 + hasPrefix 6 8 warn 9 + map 10 + isList 7 11 ; 8 12 in 9 13 ··· 468 472 ... 469 473 470 474 475 + To create a directory structure from a specific subdirectory of input `paths` instead of their full trees, 476 + you can either append the subdirectory path to each input path, or use the `stripPrefix` argument to 477 + remove the common prefix during linking. 478 + 479 + Example: 480 + 481 + 482 + # create symlinks of tmpfiles.d rules from multiple packages 483 + symlinkJoin { name = "tmpfiles.d"; paths = [ pkgs.lvm2 pkgs.nix ]; stripPrefix = "/lib/tmpfiles.d"; } 484 + 485 + 486 + This creates a derivation with a directory structure like the following: 487 + 488 + 489 + /nix/store/m5s775yicb763hfa133jwml5hwmwzv14-tmpfiles.d 490 + |-- lvm2.conf -> /nix/store/k6js0l5f0zpvrhay49579fj939j77p2w-lvm2-2.03.29/lib/tmpfiles.d/lvm2.conf 491 + `-- nix-daemon.conf -> /nix/store/z4v2s3s3y79fmabhps5hakb3c5dwaj5a-nix-1.33.7/lib/tmpfiles.d/nix-daemon.conf 492 + 493 + 494 + By default, packages that don't contain the specified subdirectory are silently skipped. 495 + Set `failOnMissing = true` to make the build fail if any input package is missing the subdirectory 496 + (this is the default behavior when not using stripPrefix). 497 + 471 498 symlinkJoin and linkFarm are similar functions, but they output 472 499 derivations with different structure. 473 500 ··· 490 517 "symlinkJoin requires either a `name` OR `pname` and `version`"; 491 518 "${args_.pname}-${args_.version}" 492 519 , paths 520 + , stripPrefix ? "" 493 521 , preferLocalBuild ? true 494 522 , allowSubstitutes ? false 495 523 , postBuild ? "" 524 + , failOnMissing ? stripPrefix == "" 496 525 , ... 497 526 }: 527 + assert lib.assertMsg (stripPrefix != "" -> (hasPrefix "/" stripPrefix && stripPrefix != "/")) '' 528 + stripPrefix must be either an empty string (disable stripping behavior), or relative path prefixed with /. 529 + 530 + Ensure that the path starts with / and specifies path to the subdirectory. 531 + ''; 532 + 498 533 let 499 - args = removeAttrs args_ [ "name" "postBuild" ] 534 + mapPaths = f: paths: map (path: 535 + if path == null then null 536 + else if isList path then mapPaths f path 537 + else f path 538 + ) paths; 539 + args = removeAttrs args_ [ "name" "postBuild" "stripPrefix" "paths" "failOnMissing" ] 500 540 // { 501 541 inherit preferLocalBuild allowSubstitutes; 542 + paths = mapPaths (path: "${path}${stripPrefix}") paths; 502 543 passAsFile = [ "paths" ]; 503 544 }; # pass the defaults 504 545 in ··· 506 547 '' 507 548 mkdir -p $out 508 549 for i in $(cat $pathsPath); do 509 - ${lndir}/bin/lndir -silent $i $out 550 + ${optionalString (!failOnMissing) "if test -d $i; then "}${lndir}/bin/lndir -silent $i $out${optionalString (!failOnMissing) "; fi"} 510 551 done 511 552 ${postBuild} 512 553 '';
+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 {};