Unverified Commit 3551efc2 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

symlinkJoin: to extendMkDerivation, enable finalAttrs (#489233)

parents dbe52311 e0ce766f
Loading
Loading
Loading
Loading
+67 −60
Original line number Diff line number Diff line
@@ -572,13 +572,24 @@ rec {
    other derivations.  A derivation created with linkFarm is often used in CI
    as a easy way to build multiple derivations at once.
  */
  symlinkJoin =
    args_@{
  symlinkJoin = lib.extendMkDerivation {
    constructDrv = stdenvNoCC.mkDerivation;

    excludeDrvArgNames = [
      "postBuild"
      "stripPrefix"
      "paths"
      "failOnMissing"
    ];

    extendDrvArgs =
      finalAttrs:
      args@{
        name ?
          assert lib.assertMsg (
          args_ ? pname && args_ ? version
            finalAttrs ? pname && finalAttrs ? version
          ) "symlinkJoin requires either a `name` OR `pname` and `version`";
        "${args_.pname}-${args_.version}",
          "${finalAttrs.pname}-${finalAttrs.version}",
        paths,
        stripPrefix ? "",
        preferLocalBuild ? true,
@@ -592,10 +603,9 @@ rec {

        Ensure that the path starts with / and specifies path to the subdirectory.
      '';

      let
        mapPaths =
        f: paths:
          f:
          map (
            path:
            if path == null then
@@ -604,29 +614,17 @@ rec {
              mapPaths f path
            else
              f path
        ) paths;
      args =
        removeAttrs args_ [
          "name"
          "postBuild"
          "stripPrefix"
          );
      in
      {
        enableParallelBuilding = true;
        inherit name allowSubstitutes preferLocalBuild;
        passAsFile = [
          "buildCommand"
          "paths"
          "failOnMissing"
        ]
        // {
          # Allow getting the proper position of the output derivation.
          # Since one of these are required, it should be fairly accurate.
          pos =
            if args_ ? pname then
              builtins.unsafeGetAttrPos "pname" args_
            else
              builtins.unsafeGetAttrPos "name" args_;
          inherit preferLocalBuild allowSubstitutes;
        ];
        paths = mapPaths (path: "${path}${stripPrefix}") paths;
          passAsFile = [ "paths" ];
        }; # pass the defaults
    in
    runCommand name args ''
        buildCommand = ''
          mkdir -p $out
          for i in $(cat $pathsPath); do
            ${optionalString (!failOnMissing) "if test -d $i; then "}${lndir}/bin/lndir -silent $i $out${
@@ -635,6 +633,15 @@ rec {
          done
          ${postBuild}
        '';
      }
      // lib.optionalAttrs (!args ? meta) {
        pos =
          if args ? pname then
            builtins.unsafeGetAttrPos "pname" args
          else
            builtins.unsafeGetAttrPos "name" args;
      };
  };

  # TODO: move linkFarm docs to the Nixpkgs manual
  /*
+3 −3
Original line number Diff line number Diff line
@@ -6,10 +6,10 @@
  kak-tree-sitter-unwrapped,
}:

symlinkJoin rec {
symlinkJoin (finalAttrs: {
  pname = lib.replaceStrings [ "-unwrapped" ] [ "" ] kak-tree-sitter-unwrapped.pname;
  inherit (kak-tree-sitter-unwrapped) version;
  name = "${pname}-${version}";
  name = "${finalAttrs.pname}-${finalAttrs.version}";

  paths = [ kak-tree-sitter-unwrapped ];
  nativeBuildInputs = [ makeWrapper ];
@@ -24,4 +24,4 @@ symlinkJoin rec {
  '';

  inherit (kak-tree-sitter-unwrapped) meta;
}
})