From 147b5a68758a1bd1fae0cf84f056fd4bb3080450 Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 17 Nov 2023 20:43:39 +0100 Subject: [PATCH 1/4] Allow overriding the dist server --- default.nix | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/default.nix b/default.nix index 8f8dfadf..71e92f6d 100644 --- a/default.nix +++ b/default.nix @@ -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.url; sha256 = src.hash; }) (filterAttrs (_: src: src ? available && src.available) (mapAttrs (_: pkg: pkg.target."*" or pkg.target.${target} or null) manifest.pkg)); @@ -55,11 +57,11 @@ 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 @@ -67,7 +69,7 @@ let 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; }); @@ -110,7 +112,7 @@ let ++ 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; @@ -118,16 +120,16 @@ let 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; @@ -135,9 +137,9 @@ nightlyToolchains.${v} // rec { fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v 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 @@ -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; }) From 44eb22ac616bded012f882bf599d677d1f37a952 Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 17 Nov 2023 21:09:40 +0100 Subject: [PATCH 2/4] Add root optional argument to fromToolchainFile --- default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/default.nix b/default.nix index 71e92f6d..68b5c97d 100644 --- a/default.nix +++ b/default.nix @@ -74,12 +74,12 @@ let 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; }) @@ -88,7 +88,7 @@ let 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 @@ -98,14 +98,14 @@ 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"} @@ -135,7 +135,7 @@ nightlyToolchains.${v} // rec { fromToolchainFile = fromToolchainFile' v; - fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v name sha256; + fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v default_dist_server name sha256; stable = fromManifest' v default_dist_server "-stable" (importJSON ./data/stable.json); From 923c3fa863e4c6ef2d83b8321861c845a4700df2 Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 20 Nov 2023 19:17:07 +0100 Subject: [PATCH 3/4] Use xz url instead of gz url Panamax only mirrors the xz url by default, and the xz URLs are much better compressed. --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 68b5c97d..b6ee8f55 100644 --- a/default.nix +++ b/default.nix @@ -42,7 +42,7 @@ let toolchain = mkToolchain suffix { inherit (manifest) date; components = mapAttrs - (_: src: { url = builtins.replaceStrings [ default_dist_server ] [ root ] 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)); From cbff06c431c60e6d430997f51dff58a509381547 Mon Sep 17 00:00:00 2001 From: roblabla Date: Wed, 3 Jan 2024 15:36:40 +0100 Subject: [PATCH 4/4] Allow using beta channels with fromToolchainName --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index b6ee8f55..3a554009 100644 --- a/default.nix +++ b/default.nix @@ -84,7 +84,7 @@ let 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: