-
Notifications
You must be signed in to change notification settings - Fork 31
/
default.nix
64 lines (59 loc) · 1.82 KB
/
default.nix
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
pkgs ? import <nixpkgs> {},
system ? builtins.currentSystem,
}: let
inherit (pkgs) lib;
sources = builtins.fromJSON (lib.strings.fileContents ./sources.json);
# mkBinaryInstall makes a derivation that installs Zig from a binary.
mkBinaryInstall = {
url,
version,
sha256,
}:
pkgs.stdenv.mkDerivation {
inherit version;
pname = "zig";
src = pkgs.fetchurl {inherit url sha256;};
dontConfigure = true;
dontBuild = true;
dontFixup = true;
installPhase = ''
mkdir -p $out/{doc,bin,lib}
[ -d docs ] && cp -r docs/* $out/doc
[ -d doc ] && cp -r doc/* $out/doc
cp -r lib/* $out/lib
cp zig $out/bin/zig
'';
};
# The packages that are tagged releases
taggedPackages =
lib.attrsets.mapAttrs
(k: v: mkBinaryInstall {inherit (v.${system}) version url sha256;})
(lib.attrsets.filterAttrs
(k: v: (builtins.hasAttr system v) && (v.${system}.url != null) && (v.${system}.sha256 != null))
(builtins.removeAttrs sources ["master"]));
# The master packages
masterPackages =
lib.attrsets.mapAttrs' (
k: v:
lib.attrsets.nameValuePair
(
if k == "latest"
then "master"
else ("master-" + k)
)
(mkBinaryInstall {inherit (v.${system}) version url sha256;})
)
(lib.attrsets.filterAttrs
(k: v: (builtins.hasAttr system v) && (v.${system}.url != null))
sources.master);
# This determines the latest /released/ version.
latest = lib.lists.last (
builtins.sort
(x: y: (builtins.compareVersions x y) < 0)
(builtins.attrNames taggedPackages)
);
in
# We want the packages but also add a "default" that just points to the
# latest released version.
taggedPackages // masterPackages // {"default" = taggedPackages.${latest};}