about summary refs log tree commit diff
path: root/nix/fetchGoModule/default.nix
blob: 3f0784ad8fe76c0f67a840bff1f77f4eaaaed98d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{ 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"
    unpackFile "$TMPDIR/src.zip"
    mv "$unpackDir/${path}@v${version}" "$out"
  '';
}).overrideAttrs ({ nativeBuildInputs ? [], ... }: {
  nativeBuildInputs = nativeBuildInputs ++ [ pkgs.unzip ];
})