diff --git a/flake.lock b/flake.lock index f09ea9c..a97f62c 100644 --- a/flake.lock +++ b/flake.lock @@ -2,23 +2,40 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1701693815, - "narHash": "sha256-7BkrXykVWfkn6+c1EhFA3ko4MLi3gVG0p9G96PNnKTM=", + "lastModified": 1708294118, + "narHash": "sha256-evZzmLW7qoHXf76VCepvun1esZDxHfVRFUJtumD7L2M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "09ec6a0881e1a36c29d67497693a67a16f4da573", + "rev": "e0da498ad77ac8909a980f07eff060862417ccf7", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixpkgs-unstable", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } }, + "nixpkgs-risc0-rustc": { + "locked": { + "lastModified": 1689249710, + "narHash": "sha256-HhXiQJkQNNPKUANdnvvncfYxqv/4YD5rjXktj0Yb45o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7f792be99dc7a8732d4d0aa23c1dacb6ccd17906", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7f792be99dc7a8732d4d0aa23c1dacb6ccd17906", + "type": "github" + } + }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-risc0-rustc": "nixpkgs-risc0-rustc" } } }, diff --git a/flake.nix b/flake.nix index 1722ced..27119b9 100644 --- a/flake.nix +++ b/flake.nix @@ -12,9 +12,10 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs-risc0-rustc.url = "github:NixOS/nixpkgs/7f792be99dc7a8732d4d0aa23c1dacb6ccd17906"; }; - outputs = { self, nixpkgs, ... }: + outputs = inputs@{ self, nixpkgs, ... }: let eachSystem = systems: f: let @@ -48,7 +49,8 @@ // eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - risc0pkgs = pkgs.recurseIntoAttrs (pkgs.callPackage ./pkgs { }); + pkgs-risc0-rustc = inputs.nixpkgs-risc0-rustc.legacyPackages.${system}; + risc0pkgs = pkgs-risc0-rustc.recurseIntoAttrs (pkgs-risc0-rustc.callPackage ./pkgs { }); lib = pkgs.recurseIntoAttrs (pkgs.callPackage ./lib { pkgs = pkgs // risc0pkgs; }); in { diff --git a/pkgs/rustc0/default.nix b/pkgs/rustc0/default.nix index 0511b53..a73e1b6 100644 --- a/pkgs/rustc0/default.nix +++ b/pkgs/rustc0/default.nix @@ -1,86 +1,29 @@ -{ stdenv -, autoPatchelfHook -, fixDarwinDylibNames -, lib -, zlib -, gcc +{ rustc +, fetchpatch }: -stdenv.mkDerivation rec { - pname = "rustc0"; - version = "v2023-08-10.1"; - meta = with lib; { - homepage = "https://github.com/risc0/rust"; - description = "risc0's Rust compiler"; - platforms = [ - # Platforms with host tools from - # https://doc.rust-lang.org/nightly/rustc/platform-support.html - "x86_64-darwin" - "i686-darwin" - "aarch64-darwin" - "i686-freebsd13" - "x86_64-freebsd13" - "x86_64-solaris" - "aarch64-linux" - "armv6l-linux" - "armv7l-linux" - "i686-linux" - "loongarch64-linux" - "powerpc64-linux" - "powerpc64le-linux" - "riscv64-linux" - "s390x-linux" - "x86_64-linux" - "aarch64-netbsd" - "armv7l-netbsd" - "i686-netbsd" - "powerpc-netbsd" - "x86_64-netbsd" - "i686-openbsd" - "x86_64-openbsd" - "i686-windows" - "x86_64-windows" - ]; - }; +# How to update the risc0's rustc derivation: +# 1. Find the latest nixpkgs revision that includes the rust version that risc0's rust is based on: +# 1.1 Go to https://github.com/NixOS/nixpkgs/commits/master/pkgs/development/compilers/rust and grep for the version +# 1.2 Copy the revision and update the nixpkgs-risc0-rustc input in the flake.nix, by replacing the revision hash - src = - if stdenv.hostPlatform.isLinux - then - builtins.fetchurl - { - url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-x86_64-unknown-linux-gnu.tar.gz"; - sha256 = "sha256-ilCDZk+YY8lUFqdITR1w1OxBsjNVfUlYUTQDzk2/D9s="; - } - else if stdenv.hostPlatform.system == "x86_64-darwin" - then - builtins.fetchurl - { - url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-x86_64-apple-darwin.tar.gz"; - sha256 = "sha256:1nhnsbclpmpsakf5vz77jbhh4ak7k30frh6hp4lg6aasmvif0fp3"; - } - else - builtins.fetchurl { - url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-aarch64-apple-darwin.tar.gz"; - sha256 = "sha256:0vvf6j14vm9n3kb39m0xdzfc7fdycwr3iqzlnyy7razgi3i5vk9l"; - }; +# 2. Update the version attribute below. - sourceRoot = "."; - - nativeBuildInputs = [ - ] - ++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook - ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; - - buildInputs = [ zlib gcc.cc.lib ]; - - dontStrip = stdenv.hostPlatform.isDarwin; - - installPhase = '' - runHook preInstall - mkdir -p $out/bin - cp -r lib $out/lib - install -m755 bin/rustc $out/bin/rustc - install -m755 bin/rustdoc $out/bin/rustdoc - runHook postInstall - ''; -} +# Alternative: +# 2. Obtain the diff file that includes all the changes that risc0's fork introduces: +# 2.1 Go to https://github.com/rust-lang/rust/compare/master...risc0:rust:risc0 +# 2.2 Change the base repository's branch/tag to the version that risc0's release is based on +# 2.3 Change the head repository's branch/tag to the risc0 release version +# 2.4 Download the diff by appending `.diff` to the URL e.g. https://github.com/rust-lang/rust/compare/1.70.0...risc0:rust:v2024-01-31.1.diff +# 2.5 Add the diff file next to this file (default.nix) +# 2.6 Modify the diff and remove the .github/workflows/ci.yml changes +rustc.overrideAttrs (final: prev: { + version = "v2024-01-31.1"; + patches = (prev.patches or [ ]) ++ [ + (fetchpatch { + url = "https://github.com/rust-lang/rust/compare/${prev.version}...risc0:rust:${final.version}.diff"; + hash = "sha256-kUCb4SXq7T0vNctMfLywjvEtlEdRRQhsy3RVP+/0Wmo="; + excludes = [ ".github/workflows/ci.yml" ]; + }) + ]; +})