Commit 4e37d03b authored by Yueh-Shun Li's avatar Yueh-Shun Li
Browse files

fetchgit: reference hash from finalAttrs.hash

parent ae800ea5
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ lib.makeOverridable (

      # Hashes, handled by `lib.fetchers.withNormalizedHash`
      # whose outputs contain outputHash* attributes.
      "hash"
      # Use `hash` when overriding with `<pkg>.overrideAttrs`.
      "sha256"
    ];

@@ -131,6 +131,11 @@ lib.makeOverridable (
          server admins start using the new version?
        */

        let
          finalHashHasColon = lib.hasInfix ":" finalAttrs.hash;
          finalHashColonMatch = lib.match "([^:]+)[:](.*)" finalAttrs.hash;
        in

        derivationArgs
        // {
          inherit name;
@@ -145,7 +150,20 @@ lib.makeOverridable (
          ++ lib.optionals fetchLFS [ git-lfs ]
          ++ nativeBuildInputs;

          inherit outputHash outputHashAlgo;
          hash =
            if outputHashAlgo == null || outputHash == "" || lib.hasPrefix outputHashAlgo outputHash then
              outputHash
            else
              "${outputHashAlgo}:${outputHash}";

          outputHash =
            if finalAttrs.hash == "" then
              lib.fakeHash
            else if finalHashHasColon then
              lib.elemAt finalHashColonMatch 1
            else
              finalAttrs.hash;
          outputHashAlgo = if finalHashHasColon then lib.head finalHashColonMatch else null;
          outputHashMode = "recursive";

          sparseCheckout =
+46 −0
Original line number Diff line number Diff line
@@ -137,6 +137,52 @@ let
      };
    };

  tests-fetchgit =
    let
      src-with-sha256 = pkgs.fetchgit {
        url = "https://example.com/source.git";
        sha256 = lib.fakeSha256;
      };
    in
    {
      test-fetchgit-hash-compat = {
        expr = {
          inherit (src-with-sha256)
            outputHash
            outputHashAlgo
            ;
        };
        expected = {
          outputHash = lib.fakeSha256;
          outputHashAlgo = "sha256";
        };
      };
      test-fetchgit-overrideAttrs-hash = {
        expr = {
          inherit (src-with-sha256.overrideAttrs { hash = pkgs.nix.src.hash; })
            outputHash
            outputHashAlgo
            ;
        };
        expected = {
          outputHash = pkgs.nix.src.hash;
          outputHashAlgo = null;
        };
      };
      test-fetchurl-overrideAttrs-hash-empty = {
        expr = {
          inherit (src-with-sha256.overrideAttrs { hash = ""; })
            outputHash
            outputHashAlgo
            ;
        };
        expected = {
          outputHash = lib.fakeHash;
          outputHashAlgo = null;
        };
      };
    };

  tests-fetchurl =
    let
      src-with-sha256 = pkgs.fetchurl {