Skip to content

Commit facbc37

Browse files
authored
Merge pull request #79 from Fryuni/use-mirrors
Prefer downloading from mirrors
2 parents ad0a46e + 37d5ab4 commit facbc37

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

default.nix

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
}: let
55
inherit (pkgs) lib;
66
sources = builtins.fromJSON (lib.strings.fileContents ./sources.json);
7+
mirrors = builtins.fromJSON (lib.strings.fileContents ./mirrors.json);
78

89
# mkBinaryInstall makes a derivation that installs Zig from a binary.
910
mkBinaryInstall = {
1011
url,
1112
version,
1213
sha256,
13-
}:
14+
}: let
15+
tarballName = lib.lists.last (lib.strings.split "/" url);
16+
srcIsFromZigLang = lib.strings.hasPrefix "https://ziglang.org/" url;
17+
urlFromMirrors =
18+
builtins.map
19+
(mirror: "${mirror}/${tarballName}?source=nix-zig-overlay")
20+
mirrors;
21+
urls =
22+
if srcIsFromZigLang
23+
then urlFromMirrors ++ [url]
24+
else [url];
25+
in
1426
pkgs.stdenv.mkDerivation {
1527
inherit version;
1628

1729
pname = "zig";
18-
src = pkgs.fetchurl {inherit url sha256;};
30+
src = pkgs.fetchurl {inherit urls sha256;};
1931
dontConfigure = true;
2032
dontBuild = true;
2133
dontFixup = true;

mirrors.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
"https://pkg.machengine.org/zig",
3+
"https://zigmirror.hryx.net/zig",
4+
"https://zig.linus.dev/zig",
5+
"https://zig.squirl.dev",
6+
"https://zig.florent.dev",
7+
"https://zig.mirror.mschae23.de/zig",
8+
"https://zigmirror.meox.dev"
9+
]

update

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#! nix-shell -p curl jq minisign -i sh
33
set -e
44

5+
curl -s 'https://ziglang.org/download/community-mirrors.txt' | jq -R '.' | jq -s . > mirrors.json
6+
57
# The well known public key for Zig
68
PUBLIC_KEY="RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U"
79

0 commit comments

Comments
 (0)