From bf4ada00a845e08e552f0521d245c23f04c47b1f Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 23 Dec 2020 14:48:17 -0800 Subject: might want to run nightly rust --- rust-nightly.nix | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 21 +++++++++-- 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 rust-nightly.nix diff --git a/rust-nightly.nix b/rust-nightly.nix new file mode 100644 index 0000000..3f1fbe4 --- /dev/null +++ b/rust-nightly.nix @@ -0,0 +1,106 @@ +{ stdenv, lib, buildEnv, makeWrapper, runCommand, fetchurl, zlib, rsync, curl }: + +# rustc and cargo nightly binaries + +let + convertPlatform = system: + if system == "i686-linux" then "i686-unknown-linux-gnu" + else if system == "x86_64-linux" then "x86_64-unknown-linux-gnu" + else if system == "i686-darwin" then "i686-apple-darwin" + else if system == "x86_64-darwin" then "x86_64-apple-darwin" + else abort "no snapshot to bootstrap for this platform (missing target triple)"; + + thisSys = convertPlatform stdenv.system; + + defaultDateFile = builtins.fetchurl + "https://static.rust-lang.org/dist/channel-rust-nightly-date.txt"; + defaultDate = lib.removeSuffix "\n" (builtins.readFile defaultDateFile); + + mkUrl = { pname, archive, date, system }: + "${archive}/${date}/${pname}-nightly-${system}.tar.gz"; + + fetch = args: let + url = mkUrl { inherit (args) pname archive date system; }; + download = builtins.fetchurl (url + ".sha256"); + contents = builtins.readFile download; + sha256 = args.hash or (lib.head (lib.strings.splitString " " contents)); + in fetchurl { inherit url sha256; }; + + generic = { pname, archive, exes }: + { date ? defaultDate, system ? thisSys, ... } @ args: + stdenv.mkDerivation rec { + name = "${pname}-${version}"; + version = "nightly-${date}"; + preferLocalBuild = true; + # TODO meta; + outputs = [ "out" "doc" ]; + src = fetch (args // { inherit pname archive system date; }); + nativeBuildInputs = [ rsync ]; + dontStrip = true; + installPhase = '' + rsync --chmod=u+w -r ./*/ $out/ + ''; + preFixup = if stdenv.isLinux then let + # it's overkill, but fixup will prune + rpath = "$out/lib:" + lib.makeLibraryPath [ zlib stdenv.cc.cc.lib curl ]; + in '' + for executable in ${lib.concatStringsSep " " exes}; do + patchelf \ + --interpreter "$(< $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath "${rpath}" \ + "$out/bin/$executable" + done + for library in $out/lib/*.so; do + patchelf --set-rpath "${rpath}" "$library" + done + '' else ""; + }; + +in rec { + rustc = generic { + pname = "rustc"; + archive = "https://static.rust-lang.org/dist"; + exes = [ "rustc" "rustdoc" ]; + }; + + rustcWithSysroots = { rustc, sysroots ? [] }: buildEnv { + name = "combined-sysroots"; + paths = [ rustc ] ++ sysroots; + pathsToLink = [ "/lib" "/share" ]; + #buildInputs = [ makeWrapper ]; + # Can't use wrapper script because of https://github.com/rust-lang/rust/issues/31943 + postBuild = '' + mkdir -p $out/bin/ + cp ${rustc}/bin/* $out/bin/ + ''; + }; + + rust-std = { date ? defaultDate, system ? thisSys, ... } @ args: + stdenv.mkDerivation rec { + # Strip install.sh, etc + pname = "rust-std"; + version = "nightly-${date}"; + name = "${pname}-${version}-${system}"; + src = fetch (args // { + inherit pname date system; + archive = "https://static.rust-lang.org/dist"; + }); + installPhase = '' + mkdir -p $out + mv ./*/* $out/ + rm $out/manifest.in + ''; + }; + + cargo = generic { + pname = "cargo"; + archive = "https://static.rust-lang.org/dist"; + exes = [ "cargo" ]; + }; + + rust = generic { + pname = "rust"; + archive = "https://static.rust-lang.org/dist"; + exes = [ "rustc" "rustdoc" "cargo" ]; + }; +} diff --git a/shell.nix b/shell.nix index 0860ad5..7cc2faf 100644 --- a/shell.nix +++ b/shell.nix @@ -7,14 +7,31 @@ let sha256 = "17mmf5sqn0fmpqrf52icq92nf1sy5yacwx9vafk43piaq433ba56"; }; crate2nix = pkgs.callPackage (import crate2nix-src) { }; + #rustPackages = pkgs.callPackage ./rust-nightly.nix { }; in pkgs.mkShell { - buildInputs = with pkgs; [ + buildInputs = (with pkgs; [ cargo cmake crate2nix go pkgconfig rustc - ]; + ]); + /* + ++ (with rustPackages; [ + (cargo { + date = "2020-12-20"; + hash= "0rnbf2hb94yrs7xl567i35641z52by3jlijxwjn8m1slvnqvzshc"; + }) + (rustc { + date = "2020-12-20"; + hash= "1asahv0lv78r2v0117hc56a62hkssnnsl6qyzyh43wrwv70jv6i7"; + }) + (rust-std { + date = "2020-12-20"; + hash= "0x4qpwgqibljdsplrqap8r7n8kfc6lnys46c2czqva87w4fhzpwp"; + }) + ]); + */ } -- cgit 1.4.1