Skip to content

Commit

Permalink
Rework flake and overlay structures
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Apr 17, 2023
2 parents ffe47b9 + a73957c commit cf102ae
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 162 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,20 @@ jobs:
os: [ubuntu-latest, macos-latest]
rust-channel: [stable, beta, nightly]
profile: [minimal, default]
nixpkgs-channel: [nixpkgs-unstable, nixos-22.11]
nixpkgs-channel: [nixpkgs-unstable, nixos-22.05]
exclude:
# Stable channel is not for macOS.
- os: macos-latest
nixpkgs-channel: nixos-22.05
include:
# The legacy package, used by compatible functions.
- os: ubuntu-latest
rust-channel: stable
profile: rust
nixpkgs-channel: nixpkgs-unstable
# Use old Nix for stable channels.
- nixpkgs-channel: nixos-22.05
nix_install_url: https://releases.nixos.org/nix/nix-2.8.1/install

runs-on: ${{ matrix.os }}
env:
Expand Down
92 changes: 91 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,92 @@
# The overlay.
final: prev:
(import ./rust-overlay.nix final) (prev // (import ./manifest.nix final prev))
let
inherit (builtins) mapAttrs trace;

manifests = import ./manifest.nix {
inherit (final) lib;
inherit (final.rust-bin) distRoot;
};

inherit (import ./lib.nix { inherit (final) lib pkgs rust-bin; })
fromRustcRev
fromRustupToolchain
fromRustupToolchainFile
overrideToolchain
selectLatestNightlyWith
selectManifest
toolchainFromManifest
toolchainFromManifestFile
;

in {
# For each channel:
# rust-bin.stable.latest.{minimal,default,complete} # Profiles.
# rust-bin.stable.latest.rust # Pre-aggregate from upstream.
# rust-bin.stable.latest.cargo # Components...
# rust-bin.stable.latest.rustc
# rust-bin.stable.latest.rust-docs
# ...
#
# For a specific version of stable:
# rust-bin.stable."1.47.0".default
#
# For a specific date of beta:
# rust-bin.beta."2021-01-01".default
#
# For a specific date of nightly:
# rust-bin.nightly."2020-01-01".default
rust-bin =
(prev.rust-bin or {}) //
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) manifests //
{
# The dist url for fetching.
# Override it if you want to use a mirror server.
distRoot = "https://static.rust-lang.org/dist";

inherit fromRustupToolchain fromRustupToolchainFile;
inherit selectLatestNightlyWith;
inherit fromRustcRev;

# For internal usage.
inherit manifests;
};

# All attributes below are for compatiblity with mozilla overlay.

lib = (prev.lib or {}) // {
rustLib = (prev.lib.rustLib or {}) // {
manifest_v2_url = throw ''
`manifest_v2_url` is not supported.
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
See also README at https://github.com/oxalica/rust-overlay
'';
fromManifest = throw ''
`fromManifest` is not supported due to network access during evaluation.
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
See also README at https://github.com/oxalica/rust-overlay
'';
fromManifestFile = manifestFilePath: { stdenv, fetchurl, patchelf }@deps: trace ''
`fromManifestFile` is deprecated.
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
See also README at https://github.com/oxalica/rust-overlay
'' (overrideToolchain deps (toolchainFromManifestFile manifestFilePath));
};
};

rustChannelOf = manifestArgs: toolchainFromManifest (selectManifest manifestArgs);

latest = (prev.latest or {}) // {
rustChannels = {
stable = final.rust-bin.stable.latest;
beta = final.rust-bin.beta.latest;
nightly = final.rust-bin.nightly.latest;
};
};

rustChannelOfTargets = channel: date: targets:
(final.rustChannelOf { inherit channel date; })
.rust.override { inherit targets; };

rustChannels = final.latest.rustChannels;
}
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ All public attributes provided by the overlay are below. Fields not defined here
}
```

For more details, see also the source code of [`rust-overlay.nix`](../rust-overlay.nix).
For more details, see also the source code of [`default.nix`](../default.nix) and [`lib.nix`](../lib.nix).
38 changes: 9 additions & 29 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 40 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
'';

inputs = {
# See: https://github.com/nix-systems/nix-systems
systems.url = "path:./systems.nix";
systems.flake = false;
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }: let
outputs = { self, systems, nixpkgs }: let
inherit (nixpkgs.lib)
elem filterAttrs head mapAttrs mapAttrs' optionalAttrs replaceStrings warnIf;

Expand All @@ -18,20 +20,19 @@

overlay = import ./.;

allSystems = [
"aarch64-darwin"
"aarch64-linux"
"armv5tel-linux"
"armv6l-linux"
"armv7a-linux"
"armv7l-linux"
"i686-linux"
# "mipsel-linux" # Missing `busybox`.
"powerpc64le-linux"
"riscv64-linux"
"x86_64-darwin"
"x86_64-linux"
];
eachSystem = nixpkgs.lib.genAttrs (import systems);

overlayOutputFor = system:
# Prefer to reuse may-be-evaluated flake output.
if nixpkgs ? legacyPackages.${system} then
let
super = nixpkgs.legacyPackages.${system};
final = super // overlay final super;
in
final
# Otherwise, fallback to import.
else
import nixpkgs { inherit system; overlays = [ overlay ]; };

in {
overlays = {
Expand All @@ -50,41 +51,43 @@
"rust-overlay's flake output `defaultPackage.<system>` is deprecated in favor of `packages.<system>.default` for Nix >= 2.7"
(mapAttrs (_: pkgs: pkgs.default) self.packages);

} // flake-utils.lib.eachSystem allSystems (system: let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
in {
# TODO: Flake outputs except `overlay[s]` are not stabilized yet.
# TODO: Flake outputs other than `overlay[s]` are not stabilized yet.

packages = let
select = version: comps: if version == "latest" then null else comps.default or null;
result =
resultOf = rust-bin:
mapAttrs' (version: comps: {
name = "rust_${replaceStrings ["."] ["_"] version}";
value = select version comps;
}) pkgs.rust-bin.stable //
}) rust-bin.stable //
mapAttrs' (version: comps: {
name = "rust-nightly_${version}";
value = select version comps;
}) pkgs.rust-bin.nightly //
}) rust-bin.nightly //
mapAttrs' (version: comps: {
name = "rust-beta_${version}";
value = select version comps;
}) pkgs.rust-bin.beta //
}) rust-bin.beta //
rec {
rust = pkgs.rust-bin.stable.latest.default;
rust-beta = pkgs.rust-bin.beta.latest.default;
rust-nightly = pkgs.rust-bin.nightly.latest.default;
rust = rust-bin.stable.latest.default;
rust-beta = rust-bin.beta.latest.default;
rust-nightly = rust-bin.nightly.latest.default;
default = rust;
};
in filterAttrs (name: drv: drv != null) result;
in
eachSystem (system:
filterAttrs (name: drv: drv != null)
(resultOf ((overlayOutputFor system).rust-bin)));

checks = let
inherit (pkgs) rust-bin rustChannelOf;
inherit (pkgs.rust-bin) fromRustupToolchain fromRustupToolchainFile stable beta nightly;
checks = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};

inherit (overlayOutputFor system) rust-bin rustChannelOf latest;
inherit (rust-bin) fromRustupToolchain fromRustupToolchainFile stable beta nightly;

rustHostPlatform = pkgs.rust.toRustTarget pkgs.hostPlatform;

assertEq = (flake-utils.lib.check-utils system).isEqual;
assertEq = lhs: rhs: assert lhs == rhs; pkgs.runCommandNoCCLocal "OK" { } ">$out";
assertUrl = drv: url: assertEq (head drv.src.urls) url;
in
# Check only tier 1 targets.
Expand All @@ -108,9 +111,9 @@
rename-unavailable = assertEq (stable."1.30.0" ? rustfmt) false;
rename-available = assertEq stable."1.48.0".rustfmt stable."1.48.0".rustfmt-preview;

latest-stable-legacy = assertEq pkgs.latest.rustChannels.stable.rustc stable.latest.rustc;
latest-beta-legacy = assertEq pkgs.latest.rustChannels.beta.rustc beta.latest.rustc;
latest-nightly-legacy = assertEq pkgs.latest.rustChannels.nightly.rustc nightly.latest.rustc;
latest-stable-legacy = assertEq latest.rustChannels.stable.rustc stable.latest.rustc;
latest-beta-legacy = assertEq latest.rustChannels.beta.rustc beta.latest.rustc;
latest-nightly-legacy = assertEq latest.rustChannels.nightly.rustc nightly.latest.rustc;

rust-channel-of-stable = assertEq (rustChannelOf { channel = "stable"; }).rustc stable.latest.rustc;
rust-channel-of-beta = assertEq (rustChannelOf { channel = "beta"; }).rustc beta.latest.rustc;
Expand Down Expand Up @@ -167,6 +170,6 @@
targets = [ "x86_64-apple-darwin" ];
targetExtensions = [ "rust-docs" ];
};
};
});
});
};
}
Loading

0 comments on commit cf102ae

Please sign in to comment.