Unverified Commit 1648979a authored by jopejoe1's avatar jopejoe1 Committed by GitHub
Browse files

requireFile: use lib.extendMkDerivation (#487780)

parents 0698a04e c6e75196
Loading
Loading
Loading
Loading
+87 −61
Original line number Diff line number Diff line
@@ -935,7 +935,20 @@ rec {

  # Docs in doc/build-helpers/fetchers.chapter.md
  # See https://nixos.org/manual/nixpkgs/unstable/#requirefile
  requireFile =
  requireFile = lib.extendMkDerivation {
    constructDrv = stdenv.mkDerivation;

    excludeDrvArgNames = [
      "hash"
      "hashMode"
      "message"
      "sha1"
      "sha256"
      "url"
    ];

    extendDrvArgs =
      finalAttrs:
      {
        name ? null,
        sha256 ? null,
@@ -944,7 +957,7 @@ rec {
        url ? null,
        message ? null,
        hashMode ? "flat",
    }:
      }@args:
      assert (message != null) || (url != null);
      assert (sha256 != null) || (sha1 != null) || (hash != null);
      assert (name != null) || (url != null);
@@ -978,8 +991,7 @@ rec {
            sha1;
        name_ = if name == null then baseNameOf (toString url) else name;
      in
    stdenvNoCC.mkDerivation {
      name = name_;
      {
        outputHashMode = hashMode;
        outputHashAlgo = hashAlgo_;
        outputHash = hash_;
@@ -995,6 +1007,20 @@ rec {
          _EOF_
          exit 1
        '';
      }
      // (lib.optionalAttrs (name == null) {
        # The case of providing `url`, but not `name`. This has
        # weird interactions with the positioning system

        # When we set `name` explicitly here, we override where the
        # position is read from. So we must fix it here.
        pos = lib.unsafeGetAttrPos "url" args;

        # If a name is not provided, use the basename of the url
        name = builtins.warn "providing a URL without a name is deprecated" baseNameOf (toString url);
      });

    inheritFunctionArgs = false;
  };

  # TODO: move copyPathToStore docs to the Nixpkgs manual