Skip to content

Commit

Permalink
Revert "Rework flake and overlay structures" due to downstream breakage
Browse files Browse the repository at this point in the history
This reverts commit cf102ae, reversing
changes made to ffe47b9.

Nix doesn't allow a dependent flake to have relative inputs.
```
error: cannot fetch input 'path:./systems.nix?lastModified=1&narHash=sh
a256-cyfZqnwhPNzdfQnmUUUVK5fon88TSm/0CwgE7Lf%2BLDU%3D' because it uses a relat
ive path
```

Closes #125
  • Loading branch information
oxalica committed Apr 17, 2023
1 parent cf102ae commit b79de03
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 191 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,13 @@ jobs:
os: [ubuntu-latest, macos-latest]
rust-channel: [stable, beta, nightly]
profile: [minimal, default]
nixpkgs-channel: [nixpkgs-unstable, nixos-22.05]
exclude:
# Stable channel is not for macOS.
- os: macos-latest
nixpkgs-channel: nixos-22.05
nixpkgs-channel: [nixpkgs-unstable, nixos-22.11]
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: 1 addition & 91 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,92 +1,2 @@
# The overlay.
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;
}
(import ./rust-overlay.nix final) (prev // (import ./manifest.nix final prev))
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 [`default.nix`](../default.nix) and [`lib.nix`](../lib.nix).
For more details, see also the source code of [`rust-overlay.nix`](../rust-overlay.nix).
38 changes: 29 additions & 9 deletions flake.lock

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

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

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, systems, nixpkgs }: let
outputs = { self, nixpkgs, flake-utils }: let
inherit (nixpkgs.lib)
elem filterAttrs head mapAttrs mapAttrs' optionalAttrs replaceStrings warnIf;

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

overlay = import ./.;

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 ]; };
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"
];

in {
overlays = {
Expand All @@ -51,43 +50,41 @@
"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);

# TODO: Flake outputs other than `overlay[s]` are not stabilized yet.
} // 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.

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

checks = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};

inherit (overlayOutputFor system) rust-bin rustChannelOf latest;
inherit (rust-bin) fromRustupToolchain fromRustupToolchainFile stable beta nightly;
checks = let
inherit (pkgs) rust-bin rustChannelOf;
inherit (pkgs.rust-bin) fromRustupToolchain fromRustupToolchainFile stable beta nightly;

rustHostPlatform = pkgs.rust.toRustTarget pkgs.hostPlatform;

assertEq = lhs: rhs: assert lhs == rhs; pkgs.runCommandNoCCLocal "OK" { } ">$out";
assertEq = (flake-utils.lib.check-utils system).isEqual;
assertUrl = drv: url: assertEq (head drv.src.urls) url;
in
# Check only tier 1 targets.
Expand All @@ -111,9 +108,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 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;
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;

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 @@ -170,6 +167,6 @@
targets = [ "x86_64-apple-darwin" ];
targetExtensions = [ "rust-docs" ];
};
});
};
};
});
}
22 changes: 16 additions & 6 deletions manifest.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Manifests which describe the content of each version.
{ lib, distRoot }:
final: prev:
let
inherit (builtins) match isString toString;

inherit (lib)
inherit (final.lib)
attrNames concatMap elemAt filter hasAttr mapAttrs mapAttrs' removeSuffix;

targets = import ./manifests/targets.nix // { _ = "*"; };
renamesList = import ./manifests/renames.nix;
profilesList = import ./manifests/profiles.nix;

inherit (final.rust-bin) distRoot;

# Extensions for mixed `rust` pkg.
components = [
"rustc"
Expand Down Expand Up @@ -109,7 +110,16 @@ let
in ret // { latest = ret.${set.latest}; };

in {
stable = uncompressManifestSet "stable" (import ./manifests/stable);
beta = uncompressManifestSet "beta" (import ./manifests/beta);
nightly = uncompressManifestSet "nightly" (import ./manifests/nightly);
rust-bin = (prev.rust-bin or {}) // {
# The dist url for fetching.
# Override it if you want to use a mirror server.
distRoot = "https://static.rust-lang.org/dist";

# For internal usage.
manifests = {
stable = uncompressManifestSet "stable" (import ./manifests/stable);
beta = uncompressManifestSet "beta" (import ./manifests/beta);
nightly = uncompressManifestSet "nightly" (import ./manifests/nightly);
};
};
}
Loading

0 comments on commit b79de03

Please sign in to comment.