diff --git a/pkgs/applications/misc/alacritty/default.nix b/pkgs/applications/misc/alacritty/default.nix index 4544ed1fba3bef..98e93321265e9f 100644 --- a/pkgs/applications/misc/alacritty/default.nix +++ b/pkgs/applications/misc/alacritty/default.nix @@ -1,6 +1,6 @@ { stdenv, lib, - fetchgit, + fetchFromGitHub, rustPlatform, cmake, makeWrapper, @@ -51,18 +51,16 @@ let ]; in buildRustPackage rec { name = "alacritty-unstable-${version}"; - version = "2018-08-30"; - - # At the moment we cannot handle git dependencies in buildRustPackage. - # This fork only replaces rust-fontconfig/libfontconfig with a git submodules. - src = fetchgit { - url = https://github.com/Mic92/alacritty.git; - rev = "rev-${version}"; - sha256 = "0izvg7dwwb763jc6gnmn47i5zrkxvmh3vssn6vzrrmqhd4j3msmf"; - fetchSubmodules = true; + version = "2018-08-05"; + + src = fetchFromGitHub { + owner = "jwilm"; + repo = "alacritty"; + rev = "1adb5cb7fc05054197aa08e0d1fa957df94888ab"; + sha256 = "06rc7dy1vn59lc5hjh953h9lh0f39c0n0jmrz472mrya722fl2ab"; }; - cargoSha256 = "1ijgkwv9ij4haig1h6n2b9xbhp5vahy9vp1sx72wxaaj9476msjx"; + cargoSha256 = "0ms0248bb2lgbzcqks6i0qhn1gaiim3jf1kl17qw52c8an3rc652"; nativeBuildInputs = [ cmake diff --git a/pkgs/build-support/rust/cargo-vendor-normalise.py b/pkgs/build-support/rust/cargo-vendor-normalise.py new file mode 100755 index 00000000000000..2d7a1895718406 --- /dev/null +++ b/pkgs/build-support/rust/cargo-vendor-normalise.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import sys + +import toml + + +def quote(s: str) -> str: + escaped = s.replace('"', r"\"").replace("\n", r"\n").replace("\\", "\\\\") + return '"{}"'.format(escaped) + + +def main() -> None: + data = toml.load(sys.stdin) + + assert list(data.keys()) == ["source"] + + # this value is non deterministic + data["source"]["vendored-sources"]["directory"] = "@vendor@" + + lines = [] + inner = data["source"] + for source, attrs in sorted(inner.items()): + lines.append("[source.{}]".format(quote(source))) + if source == "vendored-sources": + lines.append('"directory" = "@vendor@"\n') + else: + for key, value in sorted(attrs.items()): + attr = "{} = {}".format(quote(key), quote(value)) + lines.append(attr) + lines.append("") + + result = "\n".join(lines) + real = toml.loads(result) + assert real == data, "output = {} while input = {}".format(real, data) + + print(result) + + +if __name__ == "__main__": + main() diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 820989a7620618..1d5de052f893b3 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,7 +1,7 @@ -{ stdenv, cacert, git, rust, cargo-vendor }: +{ stdenv, cacert, git, rust, cargo-vendor, python3 }: let fetchcargo = import ./fetchcargo.nix { - inherit stdenv cacert git rust cargo-vendor; + inherit stdenv cacert git rust cargo-vendor python3; }; in { name, cargoSha256 ? "unset" @@ -61,14 +61,12 @@ in stdenv.mkDerivation (args // { ${setupVendorDir} mkdir .cargo - cat >.cargo/config <<-EOF - [source.crates-io] - registry = 'https://github.com/rust-lang/crates.io-index' - replace-with = 'vendored-sources' - - [source.vendored-sources] - directory = '$(pwd)/$cargoDepsCopy' - EOF + config="$(pwd)/$cargoDepsCopy/.cargo/config"; + if [[ ! -e $config ]]; then + config=${./fetchcargo-default-config.toml}; + fi; + substitute $config .cargo/config \ + --subst-var-by vendor "$(pwd)/$cargoDepsCopy" unset cargoDepsCopy diff --git a/pkgs/build-support/rust/fetchcargo-default-config.toml b/pkgs/build-support/rust/fetchcargo-default-config.toml new file mode 100755 index 00000000000000..dd8ebbc32d31f6 --- /dev/null +++ b/pkgs/build-support/rust/fetchcargo-default-config.toml @@ -0,0 +1,7 @@ +[source."crates-io"] +"replace-with" = "vendored-sources" + +[source."vendored-sources"] +"directory" = "@vendor@" + + diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index 2670ed52864076..9e77f8817b24b0 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -1,8 +1,26 @@ -{ stdenv, cacert, git, rust, cargo-vendor }: +{ stdenv, cacert, git, rust, cargo-vendor, python3 }: +let cargo-vendor-normalise = stdenv.mkDerivation { + name = "cargo-vendor-normalise"; + src = ./cargo-vendor-normalise.py; + nativeBuildInputs = [ python3.pkgs.wrapPython ]; + unpackPhase = ":"; + installPhase = "install -D $src $out/bin/cargo-vendor-normalise"; + pythonPath = [ python3.pkgs.toml ]; + postFixup = "wrapPythonPrograms"; + doInstallCheck = true; + installCheckPhase = '' + # check that ./fetchcargo-default-config.toml is a fix point + reference=${./fetchcargo-default-config.toml} + < $reference $out/bin/cargo-vendor-normalise > test; + cmp test $reference + ''; + preferLocalBuild = true; +}; +in { name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }: stdenv.mkDerivation { name = "${name}-vendor"; - nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ]; + nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ]; inherit src srcs patches sourceRoot; phases = "unpackPhase patchPhase installPhase"; @@ -23,9 +41,16 @@ stdenv.mkDerivation { ${cargoUpdateHook} - cargo vendor - - cp -ar vendor $out + mkdir -p $out + cargo vendor $out | cargo-vendor-normalise > config + # fetchcargo used to never keep the config output by cargo vendor + # and instead hardcode the config in ./fetchcargo-default-config.toml. + # This broke on packages needing git dependencies, so now we keep the config. + # But not to break old cargoSha256, if the previous behavior was enough, + # we don't store the config. + if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then + install -Dt $out/.cargo config; + fi; ''; outputHashAlgo = "sha256";