rewritten default.nix/flake.nix

This commit is contained in:
Mitchell Hashimoto 2022-08-22 19:07:41 -07:00
parent 1e89c6da81
commit f0c4a8c91b
No known key found for this signature in database
GPG key ID: 523D5DC389D273BC
2 changed files with 31 additions and 15 deletions

View file

@ -3,8 +3,10 @@
let
inherit (pkgs) lib;
releases = builtins.fromJSON (lib.strings.fileContents ./sources.json);
mkDerivation = { url, version, sha256 }: pkgs.stdenv.mkDerivation {
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";
@ -20,13 +22,26 @@ let
cp zig $out/bin/zig
'';
};
in lib.attrsets.mapAttrs (k: v:
# This determines the latest /released/ version.
latest = lib.lists.last (
builtins.sort
(x: y: (builtins.compareVersions x y) < 0)
(builtins.filter (x: x != "master") (builtins.attrNames sources))
);
# This is the full list of packages
packages = lib.attrsets.mapAttrs (k: v:
if k == "master" then
lib.attrsets.mapAttrs (k: v: (mkDerivation {
lib.attrsets.mapAttrs (k: v: (mkBinaryInstall {
inherit (v.${system}) version url sha256;
})) v
else
mkDerivation {
mkBinaryInstall {
inherit (v.${system}) version url sha256;
})
releases
sources;
in
# We want the packages but also add a "default" that just points to the
# latest released version.
packages // { "default" = packages.${latest}; }

View file

@ -14,8 +14,9 @@
let pkgs = nixpkgs.legacyPackages.${system};
in rec {
packages = import ./default.nix { inherit system pkgs; };
defaultPackage = packages."0.9.1";
apps.zig = flake-utils.lib.mkApp { drv = defaultPackage; };
defaultApp = apps.zig;
apps = rec {
default = apps.zig;
zig = flake-utils.lib.mkApp { drv = packages.default; };
};
});
}