about summary refs log blame commit diff
path: root/nix/fetchGoModule/default.nix
blob: 4f0cdb4b78cb8905b940ac3a28ff73d7fdecd686 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                     


                          
               
                  
                                                                       










                                          
                                                             

                                              
 
{ lib, pkgs, ... }:

let

  inherit (lib)
    lowerChars
    replaceStrings
    upperChars
  ;

  caseFold = replaceStrings upperChars (map (c: "!" + c) lowerChars);

in

{ path, version, sha256 }:

pkgs.fetchurl {
  name = "source";
  url = "https://proxy.golang.org/${caseFold path}/@v/v${version}.zip";
  inherit sha256;

  recursiveHash = true;
  downloadToTemp = true;

  postFetch = ''
    unpackDir="$TMPDIR/unpack"
    mkdir "$unpackDir"
    cd "$unpackDir"

    mv "$downloadedFile" "$TMPDIR/src.zip"
    ${pkgs.unzip}/bin/unzip "$TMPDIR/src.zip" -d "$unpackDir"
    mv "$unpackDir/${path}@v${version}" "$out"
  '';
}