Unverified Commit 1b5377ce authored by K900's avatar K900 Committed by GitHub
Browse files

Revert "applyPatches: to extendMkDerivation, fix meta.position" (#489860)

parents 3f4a3c08 db847a48
Loading
Loading
Loading
Loading
+58 −52
Original line number Diff line number Diff line
@@ -1019,13 +1019,22 @@ rec {
      ];
    }
  */
  applyPatches = lib.extendMkDerivation {
    constructDrv = stdenvNoCC.mkDerivation;

    extendDrvArgs =
      finalAttrs:
  applyPatches =
    {
      src,
      name ?
        (
          if builtins.typeOf src == "path" then
            baseNameOf src
          else if builtins.isAttrs src && builtins.hasAttr "name" src then
            src.name
          else
            throw "applyPatches: please supply a `name` argument because a default name can only be computed when the `src` is a path or is an attribute set with a `name` attribute."
        )
        + "-patched",
      patches ? [ ],
      prePatch ? "",
      postPatch ? "",
      ...
    }@args:
    assert lib.assertMsg (
@@ -1034,55 +1043,52 @@ rec {
    assert lib.assertMsg (
      !args ? passthru
    ) "applyPatches will not merge 'passthru', change it in 'src' instead";
    if patches == [ ] && prePatch == "" && postPatch == "" then
      src # nothing to do, so use original src to avoid additional drv
    else
      let
        keepAttrs = names: lib.filterAttrs (name: val: lib.elem name names);
        # enables tools like nix-update to determine what src attributes to replace
        extraPassthru = lib.optionalAttrs (lib.isAttrs finalAttrs.src) (
        extraPassthru = lib.optionalAttrs (lib.isAttrs src) (
          keepAttrs [
            "rev"
            "tag"
            "url"
            "outputHash"
            "outputHashAlgo"
          ] finalAttrs.src
          ] src
        );
      in
      stdenvNoCC.mkDerivation (
        {
        name =
          args.name or (
            if builtins.isPath finalAttrs.src then
              baseNameOf finalAttrs.src + "-patched"
            else if builtins.isAttrs finalAttrs.src && (finalAttrs.src ? name) then
              let
                srcName = builtins.parseDrvName finalAttrs.src.name;
              in
              "${srcName.name}-patched${lib.optionalString (srcName.version != "") "-${srcName.version}"}"
            else
              throw "applyPatches: please supply a `name` argument because a default name can only be computed when the `src` is a path or is an attribute set with a `name` attribute."
          );

        # Manually setting `name` can mess up positioning.
        # This should fix it.
        pos = builtins.unsafeGetAttrPos "src" args;

          inherit
            name
            src
            patches
            prePatch
            postPatch
            ;
          preferLocalBuild = true;
          allowSubstitutes = false;

        dontConfigure = true;
        dontBuild = true;
        doCheck = false;

          phases = "unpackPhase patchPhase installPhase";
          installPhase = "cp -R ./ $out";

        # passthru the git and hash info for nix-update, as well
        # as all the src's passthru attrs.
        passthru = extraPassthru // finalAttrs.src.passthru or { };

        }
        # Carry (and merge) information from the underlying `src` if present.
        # If there is not src.meta, this meta block will be blank regardless.
        meta = lib.optionalAttrs (finalAttrs.src ? meta) removeAttrs finalAttrs.src.meta [ "position" ];
      };
  };
        // (optionalAttrs (src ? meta) {
          inherit (src) meta;
        })
        // (optionalAttrs (extraPassthru != { } || src ? passthru) {
          passthru = extraPassthru // src.passthru or { };
        })
        # Forward any additional arguments to the derivation
        // (removeAttrs args [
          "src"
          "name"
          "patches"
          "prePatch"
          "postPatch"
        ])
      );

  # TODO: move docs to Nixpkgs manual
  # An immutable file in the store with a length of 0 bytes.