Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding the dist server #124

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ let
(_: mapAttrs (profile: mkToolchain "-nightly-${profile}"))
(importJSON ./data/nightly.json);

fromManifest' = target: suffix: manifest:
default_dist_server = "https://static.rust-lang.org/dist";

fromManifest' = target: root: suffix: manifest:
let
toolchain = mkToolchain suffix {
inherit (manifest) date;
components = mapAttrs
(_: src: { inherit (src) url; sha256 = src.hash; })
(_: src: { url = builtins.replaceStrings [ default_dist_server ] [ root ] src.xz_url; sha256 = src.xz_hash; })
(filterAttrs (_: src: src ? available && src.available) (mapAttrs
(_: pkg: pkg.target."*" or pkg.target.${target} or null)
manifest.pkg));
Expand All @@ -55,38 +57,38 @@ let
inherit manifest;
};

fromManifestFile' = target: name: file:
fromManifest' target name (importTOML file);
fromManifestFile' = target: root: name: file:
fromManifest' target root name (importTOML file);

toolchainOf' = target:
{ root ? "https://static.rust-lang.org/dist"
{ root ? default_dist_server
, channel ? "nightly"
, date ? null
, sha256 ? null
}:
let
url = "${root}${optionalString (date != null) "/${date}"}/channel-rust-${channel}.toml";
in
fromManifestFile' target "-${channel}" (if (sha256 == null) then
fromManifestFile' target root "-${channel}" (if (sha256 == null) then
builtins.fetchurl url
else
pkgs.fetchurl { inherit url sha256; });

fromToolchainName' = target: name: sha256:
fromToolchainName' = target: root: name: sha256:
mapNullable
(matches:
let target' = elemAt matches 5; in
toolchainOf' (if target' == null then target else target') {
inherit sha256;
inherit root sha256;
channel = elemAt matches 0;
date = elemAt matches 3;
})
(match
"^(stable|beta|nightly|[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?)(-([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}))?(-([-[:alnum:]]+))?\n?$"
"^(stable|beta|nightly|[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+(-beta\.[[:digit:]]+)?)?)(-([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}))?(-([-[:alnum:]]+))?\n?$"
name);

fromToolchainFile' = target:
{ file ? null, dir ? null, sha256 ? null }:
{ root ? default_dist_server, file ? null, dir ? null, sha256 ? null }:
let
text = readFile (if file == null && dir != null then
findFirst pathIsRegularFile
Expand All @@ -96,48 +98,48 @@ let
file
else
throw "One and only one of `file` and `dir` should be specified");
toolchain = fromToolchainName' target text sha256;
toolchain = fromToolchainName' target root text sha256;
in
if toolchain == null then
let t = (fromTOML text).toolchain; in
if t ? path then
throw "fenix doesn't support toolchain.path"
else
let toolchain = fromToolchainName' target t.channel sha256; in
let toolchain = fromToolchainName' target root t.channel sha256; in
combine' "rust-${t.channel}" (attrVals
(filter (component: toolchain ? ${component}) (unique
(toolchain.manifest.profiles.${t.profile or "default"}
++ t.components or [ ])))
toolchain ++ map
(target:
(fromManifest' target "-${t.channel}" toolchain.manifest).rust-std)
(fromManifest' target root "-${t.channel}" toolchain.manifest).rust-std)
(t.targets or [ ]))
else
toolchain.defaultToolchain;

mkToolchains = channel:
let manifest = importJSON (./data + "/${channel}.json"); in
mapAttrs
(target: _: { ${channel} = fromManifest' target "-${channel}" manifest; })
(target: _: { ${channel} = fromManifest' target default_dist_server "-${channel}" manifest; })
manifest.pkg.rust-std.target;
in

nightlyToolchains.${v} // rec {
combine = combine' "rust-mixed";

fromManifest = fromManifest' v "";
fromManifest = fromManifest' v default_dist_server "";

fromManifestFile = fromManifestFile' v "";
fromManifestFile = fromManifestFile' v default_dist_server "";

toolchainOf = toolchainOf' v;

fromToolchainFile = fromToolchainFile' v;

fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v name sha256;
fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v default_dist_server name sha256;

stable = fromManifest' v "-stable" (importJSON ./data/stable.json);
stable = fromManifest' v default_dist_server "-stable" (importJSON ./data/stable.json);

beta = fromManifest' v "-beta" (importJSON ./data/beta.json);
beta = fromManifest' v default_dist_server "-beta" (importJSON ./data/beta.json);

targets =
let
Expand All @@ -150,8 +152,8 @@ nightlyToolchains.${v} // rec {
mapAttrs
(target: v:
v // {
fromManifest = fromManifest' target "";
fromManifestFile = fromManifestFile' target "";
fromManifest = fromManifest' target default_dist_server "";
fromManifestFile = fromManifestFile' target default_dist_server "";
toolchainOf = toolchainOf' target;
fromToolchainFile = fromToolchainFile' target;
})
Expand Down