Last active
February 13, 2019 20:39
-
-
Save greglearns/192a4cc31aef8acdf3190fefa4f124ee to your computer and use it in GitHub Desktop.
NixOS default.nix for compiling Nightly Rust using Mozilla overlay, also with a specific RustRegistry for specific date, to handle "version not found" issues. Doesn't actually work, so do not use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
pkgs ? ( | |
let | |
pkgs = import <nixpkgs>; | |
pkgs_ = (pkgs {}); | |
rustOverlay = (pkgs_.fetchFromGitHub { | |
owner = "mozilla"; | |
repo = "nixpkgs-mozilla"; | |
rev = "1608d31f7e5b2415fb80b5d76f97c009507bc45f"; | |
sha256 = "0mznf82k7bxpjyvigxvvwpmi6gvg3b30l58z36x192q2xxv47v1k"; | |
}); | |
in (pkgs { | |
overlays = [ | |
(import (builtins.toPath "${rustOverlay}/rust-overlay.nix")) | |
(self: super: { rustRegistry = super.callPackage ./rust-packages.nix { }; }) # by adding the rustRegistry entry here in the overlay, the specific rustRegistry date / SHA will be used in the later overlays and compiles. | |
(self: super: | |
let | |
# base = super.rustChannels.nightly; | |
base = super.rustChannelOf { date = "2017-07-12"; channel = "nightly"; }; | |
in | |
{ | |
rust = { | |
rustc = base.rust; | |
cargo = base.cargo; | |
}; | |
rustPlatform = super.recurseIntoAttrs (super.makeRustPlatform { | |
rustc = base.rust; | |
cargo = base.cargo; | |
}); | |
}) | |
]; | |
})) | |
}: | |
pkgs.rustPlatform.buildRustPackage rec { | |
name = "thingname-${version}"; | |
version = "0.3"; | |
src = ./.; | |
depsSha256 = "0pch039h4nqpdm5f0r6n1xskrmjrf01l0zj881pz4rl1iihdhqr5"; | |
buildInputs = [ pkgs.rustc pkgs.cargo pkgs.entr ]; | |
#... etc. | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the `name` and `rev`values to select specific dates/commit-SHAs that will be used to download a specific SHA / date to use for nix rust. | |
# This file defines the source of Rust / cargo's crates registry | |
# | |
# buildRustPackage will automatically download dependencies from the registry | |
# version that we define here. If you're having problems downloading / finding | |
# a Rust library, try updating this to a newer commit. | |
{ stdenv, fetchFromGitHub, git }: | |
stdenv.mkDerivation { | |
name = "rustRegistry-2017-07-12"; | |
src = fetchFromGitHub { | |
owner = "rust-lang"; | |
repo = "crates.io-index"; | |
rev = "727fb516b25dd4f9fff535a8e507cd3ed21a1d6e"; | |
sha256 = "1srzy7w0402s9hfp90lq7i245wlwqmmwir6qik3m4zkfq41ymhls"; | |
# rev = "de7301b4aa5a933658ab14dba972cc2cab77da1c"; | |
# sha256 = "0dyx5n789pkmvk7x876v8rnagzp7xc8r2iysj2b70vcsqdvidnax"; | |
}; | |
phases = [ "unpackPhase" "installPhase" ]; | |
installPhase = '' | |
# For some reason, cargo doesn't like fetchgit's git repositories, not even | |
# if we set leaveDotGit to true, set the fetchgit branch to 'master' and clone | |
# the repository (tested with registry rev | |
# 965b634156cc5c6f10c7a458392bfd6f27436e7e), failing with the message: | |
# | |
# "Target OID for the reference doesn't exist on the repository" | |
# | |
# So we'll just have to create a new git repository from scratch with the | |
# contents downloaded with fetchgit... | |
mkdir -p $out | |
cp -r ./* $out/ | |
cd $out | |
git="${git}/bin/git" | |
$git init | |
$git config --local user.email "[email protected]" | |
$git config --local user.name "example" | |
$git add . | |
$git commit --quiet -m 'Rust registry commit' | |
touch $out/touch . "$out/.cargo-index-lock" | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment