1
0
Fork 0
mirror of https://github.com/mitchellh/zig-overlay.git synced 2025-05-08 18:46:02 +03:00
zig-overlay/default.nix

90 lines
2.5 KiB
Nix
Raw Normal View History

2022-08-22 19:55:54 -07:00
{
pkgs ? import <nixpkgs> {},
system ? builtins.currentSystem,
}: let
inherit (pkgs) lib;
2022-08-22 19:07:41 -07:00
sources = builtins.fromJSON (lib.strings.fileContents ./sources.json);
# mkBinaryInstall makes a derivation that installs Zig from a binary.
2022-08-22 19:55:54 -07:00
mkBinaryInstall = {
url,
version,
sha256,
}:
pkgs.stdenv.mkDerivation {
inherit version;
2022-08-22 17:50:25 -07:00
2022-08-22 19:55:54 -07:00
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
'';
};
2022-08-22 19:07:41 -07:00
# The packages that are tagged releases
2022-08-22 19:55:54 -07:00
taggedPackages =
lib.attrsets.mapAttrs
(k: v: mkBinaryInstall {inherit (v.${system}) version url sha256;})
(lib.attrsets.filterAttrs
2025-04-07 11:03:46 +02:00
(k: v:
(builtins.hasAttr system v)
&& (v.${system}.url != null)
&& (v.${system}.sha256 != null)
&& !(lib.strings.hasSuffix "mach" k))
(builtins.removeAttrs sources ["master" "mach-latest"]));
# The master packages
2022-08-22 19:55:54 -07:00
masterPackages =
lib.attrsets.mapAttrs' (
k: v:
lib.attrsets.nameValuePair
(
if k == "latest"
then "master"
else ("master-" + k)
)
(mkBinaryInstall {inherit (v.${system}) version url sha256;})
)
2022-08-22 19:55:54 -07:00
(lib.attrsets.filterAttrs
(k: v: (builtins.hasAttr system v) && (v.${system}.url != null))
sources.master);
2025-04-07 11:03:46 +02:00
# Mach nominated versions
# https://machengine.org/docs/nominated-zig/
machPackages =
lib.attrsets.mapAttrs
(k: v: mkBinaryInstall {inherit (v.${system}) version url sha256;})
(lib.attrsets.filterAttrs (k: v: lib.strings.hasSuffix "mach" k)
(builtins.removeAttrs sources ["master"]));
2022-08-22 19:07:41 -07:00
# This determines the latest /released/ version.
latest = lib.lists.last (
builtins.sort
2022-08-22 19:55:54 -07:00
(x: y: (builtins.compareVersions x y) < 0)
(builtins.attrNames taggedPackages)
2022-08-22 19:07:41 -07:00
);
2025-04-07 11:03:46 +02:00
# Latest Mach nominated version
machLatest = lib.lists.last (
builtins.sort
(x: y: (builtins.compareVersions x y) < 0)
(builtins.attrNames machPackages)
);
2022-08-22 19:07:41 -07:00
in
# We want the packages but also add a "default" that just points to the
# latest released version.
2025-04-07 11:03:46 +02:00
taggedPackages
// masterPackages
// machPackages
// {
"default" = taggedPackages.${latest};
mach-latest = machPackages.${machLatest};
}