nix fmt and support aarch64-darwin

This commit is contained in:
Mitchell Hashimoto 2022-08-22 19:55:54 -07:00
parent 941ed4d57e
commit c4a460a991
No known key found for this signature in database
GPG key ID: 523D5DC389D273BC
2 changed files with 77 additions and 55 deletions

View file

@ -1,50 +1,64 @@
{ pkgs ? import <nixpkgs> {}, {
system ? builtins.currentSystem }: pkgs ? import <nixpkgs> {},
system ? builtins.currentSystem,
let }: let
inherit (pkgs) lib; inherit (pkgs) lib;
sources = builtins.fromJSON (lib.strings.fileContents ./sources.json); sources = builtins.fromJSON (lib.strings.fileContents ./sources.json);
# mkBinaryInstall makes a derivation that installs Zig from a binary. # mkBinaryInstall makes a derivation that installs Zig from a binary.
mkBinaryInstall = { url, version, sha256 }: pkgs.stdenv.mkDerivation { mkBinaryInstall = {
inherit version; url,
version,
sha256,
}:
pkgs.stdenv.mkDerivation {
inherit version;
pname = "zig"; pname = "zig";
src = pkgs.fetchurl { inherit url sha256; }; src = pkgs.fetchurl {inherit url sha256;};
dontConfigure = true; dontConfigure = true;
dontBuild = true; dontBuild = true;
dontFixup = true; dontFixup = true;
installPhase = '' installPhase = ''
mkdir -p $out/{doc,bin,lib} mkdir -p $out/{doc,bin,lib}
[ -d docs ] && cp -r docs/* $out/doc [ -d docs ] && cp -r docs/* $out/doc
[ -d doc ] && cp -r doc/* $out/doc [ -d doc ] && cp -r doc/* $out/doc
cp -r lib/* $out/lib cp -r lib/* $out/lib
cp zig $out/bin/zig cp zig $out/bin/zig
''; '';
}; };
# The packages that are tagged releases # The packages that are tagged releases
taggedPackages = lib.attrsets.mapAttrs taggedPackages =
(k: v: mkBinaryInstall { inherit (v.${system}) version url sha256; }) lib.attrsets.mapAttrs
(k: v: mkBinaryInstall {inherit (v.${system}) version url sha256;})
(lib.attrsets.filterAttrs (lib.attrsets.filterAttrs
(k: v: (builtins.hasAttr system v) && (v.${system}.url != null)) (k: v: (builtins.hasAttr system v) && (v.${system}.url != null))
(builtins.removeAttrs sources ["master"])); (builtins.removeAttrs sources ["master"]));
# The master packages # The master packages
masterPackages = lib.attrsets.mapAttrs' masterPackages =
(k: v: lib.attrsets.nameValuePair lib.attrsets.mapAttrs' (
(if k == "latest" then "master" else ("master-" + k)) k: v:
(mkBinaryInstall { inherit (v.${system}) version url sha256; }) lib.attrsets.nameValuePair
(
if k == "latest"
then "master"
else ("master-" + k)
)
(mkBinaryInstall {inherit (v.${system}) version url sha256;})
) )
sources.master; (lib.attrsets.filterAttrs
(k: v: (builtins.hasAttr system v) && (v.${system}.url != null))
sources.master);
# This determines the latest /released/ version. # This determines the latest /released/ version.
latest = lib.lists.last ( latest = lib.lists.last (
builtins.sort builtins.sort
(x: y: (builtins.compareVersions x y) < 0) (x: y: (builtins.compareVersions x y) < 0)
(builtins.attrNames taggedPackages) (builtins.attrNames taggedPackages)
); );
in in
# We want the packages but also add a "default" that just points to the # We want the packages but also add a "default" that just points to the
# latest released version. # latest released version.
taggedPackages // masterPackages // { "default" = taggedPackages.${latest}; } taggedPackages // masterPackages // {"default" = taggedPackages.${latest};}

View file

@ -6,32 +6,40 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils, ... }: outputs = {
# List of systems where binaries are provided. self,
let nixpkgs,
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; flake-utils,
outputs = flake-utils.lib.eachSystem systems (system: ...
let pkgs = nixpkgs.legacyPackages.${system}; }: let
in rec { systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
# The packages exported by the Flake: outputs = flake-utils.lib.eachSystem systems (system: let
# - default - latest /released/ version pkgs = nixpkgs.legacyPackages.${system};
# - <version> - tagged version in rec {
# - master - latest nightly (updated daily) # The packages exported by the Flake:
# - master-<date> - nightly by date # - default - latest /released/ version
packages = import ./default.nix { inherit system pkgs; }; # - <version> - tagged version
# - master - latest nightly (updated daily)
# - master-<date> - nightly by date
packages = import ./default.nix {inherit system pkgs;};
# "Apps" so that `nix run` works. If you run `nix run .` then # "Apps" so that `nix run` works. If you run `nix run .` then
# this will use the latest default. # this will use the latest default.
apps = rec { apps = rec {
default = apps.zig; default = apps.zig;
zig = flake-utils.lib.mkApp { drv = packages.default; }; zig = flake-utils.lib.mkApp {drv = packages.default;};
};
});
in outputs // {
# Overlay that can be imported so you can access the packages
# using zigpkgs.master.latest or whatever you'd like.
overlays.default = final: prev: {
zigpkgs = outputs.packages.${prev.system};
};
}; };
# nix fmt
formatter = pkgs.alejandra;
});
in
outputs
// {
# Overlay that can be imported so you can access the packages
# using zigpkgs.master.latest or whatever you'd like.
overlays.default = final: prev: {
zigpkgs = outputs.packages.${prev.system};
};
};
} }