Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non broken fetchcargo #46362

Merged
merged 7 commits into from Sep 17, 2018
Merged

Non broken fetchcargo #46362

merged 7 commits into from Sep 17, 2018

Conversation

symphorien
Copy link
Member

Motivation for this change

This builds on the work of @erictapen #45889
In this comment #45889 (comment) @Mic92 suggested the output of cargo vendor (which is not guaranteed to be stable by upstream) be filtered/normalised to ensure we get a fixed output derivation, somewhat like fetchpatch does.
This is an attempt at implementing it.

What is normalized:

  • order of key/value pairs
  • spacing
  • which quotes are used
  • the vendoring directory name

what is not normalised

fixes #41518

Things done

Tested that nix-du can build with useRealVendorConfig = true and that I can build the updated habitat
from this PR #46138 without the cargo config hack they are forced to use.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip" (nothing changes)
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@@ -64,6 +65,14 @@ When the `Cargo.lock`, provided by upstream, is not in sync with the
added in `cargoPatches` will also be prepended to the patches in `patches` at
build-time.

The `useRealVendorConfig` parameter tells cargo-vendor to include a Cargo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really have an incompatibility compared to the current state? Is the output different for packages that build at the moment? I would like to enable this by default otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise a warning or should be printed otherwise people will never know about this option or bother to migrate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The incompatibility is: this changes the expected cargoSha256. So two approaches:

  • we use the new scheme forcibly from now on and break every current hash
  • or we deprecate the old behavior, let say one nixos release for people to switch to the new behavior, and then remove the old behavior.
    This PR implements the second approach.
    I agree about the warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you would not just add this:

 [source.crates-io]
 registry = 'https://github.com/rust-lang/crates.io-index'
 replace-with = 'vendored-sources'
 [source.vendored-sources]
 directory = '$(pwd)/$cargoDepsCopy'

to keep the checksum of existing packages in tact and then append the new content as required by the Cargo.toml?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there a problem with this approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the right approach is to remove the config when it only contains crates.io. But this is a great idea indeed. I just pushed a commit which should not break any cargoSha256. It is a mass rebuild though. (it rebuilds cargo)

@symphorien
Copy link
Member Author

Here is a new commit which does not change any cargosha256 and is thus backward compatible.
I have tried to check that hashes actually don't change, but if reviewers can check it as well this would be nice.

Copy link
Contributor

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, especially that you save the generated config.

return '"{}"'.format(escaped)


def main() -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added type checking here and reformatted the code with black + some minor readability improvements.

fetchSubmodules = true;
version = "2018-08-05";

src = fetchFromGitHub {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this as a test, because it makes use of the new .cargo/config

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

@GrahamcOfBorg build alacritty

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

Can you rebase this on staging?

@GrahamcOfBorg
Copy link

Unexpected error: command failed with exit code 1 on x86_64-darwin (full log)

Attempted: alacritty

Partial log (click to expand)

   Vendoring ws2_32-sys v0.2.1 (/private/tmp/nix-build-alacritty-unstable-2018-08-05-vendor.drv-0/source/cargo-home.4Ok/registry/src/github.com-1ecc6299db9ec823/ws2_32-sys-0.2.1) to /nix/store/7aw52wn8pcppggy92w5ga12gr46bgz4n-alacritty-unstable-2018-08-05-vendor/ws2_32-sys
   Vendoring x11-dl v2.18.3 (/private/tmp/nix-build-alacritty-unstable-2018-08-05-vendor.drv-0/source/cargo-home.4Ok/registry/src/github.com-1ecc6299db9ec823/x11-dl-2.18.3) to /nix/store/7aw52wn8pcppggy92w5ga12gr46bgz4n-alacritty-unstable-2018-08-05-vendor/x11-dl
   Vendoring xdg v2.1.0 (/private/tmp/nix-build-alacritty-unstable-2018-08-05-vendor.drv-0/source/cargo-home.4Ok/registry/src/github.com-1ecc6299db9ec823/xdg-2.1.0) to /nix/store/7aw52wn8pcppggy92w5ga12gr46bgz4n-alacritty-unstable-2018-08-05-vendor/xdg
   Vendoring xml-rs v0.7.0 (/private/tmp/nix-build-alacritty-unstable-2018-08-05-vendor.drv-0/source/cargo-home.4Ok/registry/src/github.com-1ecc6299db9ec823/xml-rs-0.7.0) to /nix/store/7aw52wn8pcppggy92w5ga12gr46bgz4n-alacritty-unstable-2018-08-05-vendor/xml-rs
   Vendoring yaml-rust v0.4.0 (/private/tmp/nix-build-alacritty-unstable-2018-08-05-vendor.drv-0/source/cargo-home.4Ok/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.0) to /nix/store/7aw52wn8pcppggy92w5ga12gr46bgz4n-alacritty-unstable-2018-08-05-vendor/yaml-rust
To use vendored sources, add this to your .cargo/config for this project:

builder for '/nix/store/7zqjmaaf0k5zl3yz5g9cc7z0x5vhki1j-alacritty-unstable-2018-08-05-vendor.drv' failed with exit code 2
cannot build derivation '/nix/store/x5y8kxq2cxbclphh113hd22g6kvamgmw-alacritty-unstable-2018-08-05.drv': 1 dependencies couldn't be built
error: build of '/nix/store/x5y8kxq2cxbclphh113hd22g6kvamgmw-alacritty-unstable-2018-08-05.drv' failed

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: alacritty

Partial log (click to expand)

   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
error: Could not compile `winit`.
warning: build failed, waiting for other jobs to finish...
error: build failed
builder for '/nix/store/69pgvahdf92rlg4qsbhifn98wnvzslhc-alacritty-unstable-2018-08-05.drv' failed with exit code 101
error: build of '/nix/store/69pgvahdf92rlg4qsbhifn98wnvzslhc-alacritty-unstable-2018-08-05.drv' failed

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

@GrahamcOfBorg build fd

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

It would be great if someone with macOS could look at the failure

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

@GrahamcOfBorg build fd

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

@GrahamcOfBorg build alacritty

@Mic92
Copy link
Member

Mic92 commented Sep 11, 2018

too bad, staging will never finish in time.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: fd

Partial log (click to expand)

post-installation fixup
moving /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0/man to /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0/share/man
shrinking RPATHs of ELF executables and libraries in /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0
shrinking /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0/bin/fd
gzipping man pages under /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0/share/man/
strip is /nix/store/rf59n87kcrrnrnw3l3s94q879m8vaspm-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0/bin
patching script interpreter paths in /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0
checking for references to /build in /nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0...
/nix/store/f6k43h2zp448skjf1252hgndwhlsrz54-fd-7.1.0

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: alacritty

Partial log (click to expand)

post-installation fixup
gzipping man pages under /nix/store/49liwkbackpkin2f3g0xm9iqchwfkk7n-alacritty-unstable-2018-08-05/share/man/
strip is /nix/store/rf59n87kcrrnrnw3l3s94q879m8vaspm-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/49liwkbackpkin2f3g0xm9iqchwfkk7n-alacritty-unstable-2018-08-05/bin
patching script interpreter paths in /nix/store/49liwkbackpkin2f3g0xm9iqchwfkk7n-alacritty-unstable-2018-08-05
checking for references to /build in /nix/store/49liwkbackpkin2f3g0xm9iqchwfkk7n-alacritty-unstable-2018-08-05...
strip is /nix/store/rf59n87kcrrnrnw3l3s94q879m8vaspm-binutils-2.30/bin/strip
patching script interpreter paths in /nix/store/xq3rgwcimb9m3w785hljy41nyzhqg8gs-alacritty-unstable-2018-08-05-terminfo
checking for references to /build in /nix/store/xq3rgwcimb9m3w785hljy41nyzhqg8gs-alacritty-unstable-2018-08-05-terminfo...
/nix/store/49liwkbackpkin2f3g0xm9iqchwfkk7n-alacritty-unstable-2018-08-05

@LnL7
Copy link
Member

LnL7 commented Sep 11, 2018

@Mic92 alacritty doesn't build on darwin AFAIK.

@GrahamcOfBorg
Copy link

Timed out, unknown build status on x86_64-darwin (full log)

Attempted: fd

Partial log (click to expand)

cannot build derivation '/nix/store/ajp1dq347yjpiw53i59cizdd0dw43q90-apple-framework-Security.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/mmspxib9ar4d1mld1zn29hiwlswy6l56-docbook2X-0.8.8.drv': 16 dependencies couldn't be built
cannot build derivation '/nix/store/m14n58jg1mcqg3ywiwz98dgdvi2y7acj-git-2.18.0.drv': 29 dependencies couldn't be built
cannot build derivation '/nix/store/dv0znvjk4syz4255jw06k73sfzbjv9i5-libgit2-0.26.6.drv': 12 dependencies couldn't be built
cannot build derivation '/nix/store/q6srb8vb4bdvi0swwxk73dhi8zs2vwpf-rustc-bootstrap-1.26.2.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/l9v5l4fmvzw1d74hax8ysn64cv0cv8ii-cargo-bootstrap-1.26.2.drv': 8 dependencies couldn't be built
cannot build derivation '/nix/store/mi6z331lvzd2iqy8vw88161l3a911r2i-rustc-1.27.0.drv': 15 dependencies couldn't be built
cannot build derivation '/nix/store/g88y3qgqnd0igmmynyj03k4jlbgw8qv1-cargo-1.27.0.drv': 18 dependencies couldn't be built
cannot build derivation '/nix/store/0c5c9wn2809krxcdcjkmaq0rpd9xswlr-fd-7.1.0.drv': 6 dependencies couldn't be built
error: build of '/nix/store/0c5c9wn2809krxcdcjkmaq0rpd9xswlr-fd-7.1.0.drv' failed

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: fd

Partial log (click to expand)

(cd perl/build/lib && tar cf - .) | \
(cd '/nix/store/slqgvaj54rls5sgsvsq6q5040zkn8fma-git-2.18.0/lib/perl5/site_perl/5.28.0' && umask 022 && tar xof -)
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
make: *** [Makefile:2733: install] Error 2
builder for '/nix/store/819b6207zpq9zigp3rii0lrvvngicl84-git-2.18.0.drv' failed with exit code 2
cannot build derivation '/nix/store/7vgqhdlcx5sgic3w1d7a7si4wz8k1m6q-rustc-1.27.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/3y74nvymh7b0n0vbqcdcsjna4h2yd5jx-cargo-1.27.0.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/jwx0h9p1h7biaci6dj3vmb2h9p0rvhiq-fd-7.1.0.drv': 3 dependencies couldn't be built
error: build of '/nix/store/jwx0h9p1h7biaci6dj3vmb2h9p0rvhiq-fd-7.1.0.drv' failed

@GrahamcOfBorg
Copy link

Timed out, unknown build status on x86_64-darwin (full log)

Attempted: alacritty

Partial log (click to expand)

cannot build derivation '/nix/store/0fg2mszl1rmld1avjpxndwkqw0jpff11-rust_ignore-0.2.2.drv': 21 dependencies couldn't be built
cannot build derivation '/nix/store/f8yqibkm8i9sy0qfkddg1ixxylws6c1p-apple-framework-AudioToolbox.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/jc0gc3frjqfxq61syvqk1lvpb6s1frd8-mesa-noglu-18.1.8.drv': 32 dependencies couldn't be built
cannot build derivation '/nix/store/yjxpivc3qr37ba1ysmb6z0c4rjrj2phv-rust_cargo-0.22.0.drv': 86 dependencies couldn't be built
cannot build derivation '/nix/store/p25bnbmhmscxnwhh7r7qrl60jkyx9nwy-apple-framework-AppKit.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/whdi2yfjx5hkhs8i0c911b6x5lcch64d-libGL-1.0.0.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/213n3kij0pm6qam2n7j11m446pzyi2hw-rust_cargo-vendor-0.1.13.drv': 85 dependencies couldn't be built
cannot build derivation '/nix/store/g4fwpg2qyyk2xxfpxcdpnjxjrhccbm0j-alacritty-unstable-2018-08-05-vendor.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/cxbxcizjra3vb1pd53az4l6vlq7xpb6z-alacritty-unstable-2018-08-05.drv': 29 dependencies couldn't be built
error: build of '/nix/store/cxbxcizjra3vb1pd53az4l6vlq7xpb6z-alacritty-unstable-2018-08-05.drv' failed

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: alacritty

Partial log (click to expand)

checking for references to /build in /nix/store/amignn5wl2ljwhl953wdr8ladjwdl6mw-mesa-noglu-18.1.8-drivers...
shrinking RPATHs of ELF executables and libraries in /nix/store/zdagshlqwn5idnjdmq9gfyjbyaldza8j-mesa-noglu-18.1.8-osmesa
shrinking /nix/store/zdagshlqwn5idnjdmq9gfyjbyaldza8j-mesa-noglu-18.1.8-osmesa/lib/libOSMesa.so.8.0.0
strip is /nix/store/lw308kxqcm9frx4vlfjh30da1x4gsmwx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/zdagshlqwn5idnjdmq9gfyjbyaldza8j-mesa-noglu-18.1.8-osmesa/lib
patching script interpreter paths in /nix/store/zdagshlqwn5idnjdmq9gfyjbyaldza8j-mesa-noglu-18.1.8-osmesa
checking for references to /build in /nix/store/zdagshlqwn5idnjdmq9gfyjbyaldza8j-mesa-noglu-18.1.8-osmesa...
building '/nix/store/d1mr1nzmlfwzq8rpmg242hffhyx3141f-libGL-1.0.0.drv'...
cannot build derivation '/nix/store/ls0n3pgsj5pifsq9askwghyd457z52k1-alacritty-unstable-2018-08-05.drv': 3 dependencies couldn't be built
error: build of '/nix/store/ls0n3pgsj5pifsq9askwghyd457z52k1-alacritty-unstable-2018-08-05.drv' failed

@Mic92
Copy link
Member

Mic92 commented Sep 12, 2018

@LnL7 ok, however could you just check if the cargo vendor normalization works for you? ofBorg returned an failure on macOS. Just take any rust package and change the cargoSha256 checksum.

infinisil pushed a commit to infinisil/nixpkgs that referenced this pull request Sep 17, 2018
Thanks to NixOS#46362
We can now support git dependencies!
< $reference $out/bin/cargo-vendor-normalise > test;
cmp test $reference
'';
buildInputs = [ (python3.withPackages(ps: [ ps.toml ])) ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized we cannot use the results python3.withPackages to replace the shebang of the shell script on macOS, instead we must call the wrapped python executable and pass cargo-vendor-normalise.py as the first argument.
On macOS shebangs must be binaries and cannot be scripts with shebangs itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what @infinisil got on his machine: https://hastebin.com/uxihohicax.sql

@infinisil
Copy link
Member

Added a commit that fixes this.

Trying an Alacritty build on Darwin with a slightly changed dependency hash leads to:

To use vendored sources, add this to your .cargo/config for this project:
output path ‘/nix/store/0wqzscwlczmb8s61jc66wwqjpv9milfr-alacritty-unstable-2018-08-05-vendor’ has r:sha256 hash
‘0ms0248bb2lgbzcqks6i0qhn1gaiim3jf1kl17qw52c8an3rc652’ when 
‘1ms0248bb2lgbzcqks6i0qhn1gaiim3jf1kl17qw52c8an3rc652’ was expected
cannot build derivation ‘/nix/store/jkk6kj7vbn2ir9z6rj29liivdzx3zdxy-alacritty-unstable-2018-08-05.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/jkk6kj7vbn2ir9z6rj29liivdzx3zdxy-alacritty-unstable-2018-08-05.drv’ failed

So the hashes are indeed the same :)

I cherry-picked these commits to master so I wouldn't have to build all of stdenv (branch)

@infinisil
Copy link
Member

Alacritty fully builds on the cherry-picked master branch even :)

@Mic92 Mic92 merged commit 8a94866 into NixOS:staging Sep 17, 2018
@Mic92
Copy link
Member

Mic92 commented Sep 17, 2018

@infinisil thanks!

@symphorien
Copy link
Member Author

So this is the "right way" to wrap python scripts...
Thanks!

@akru
Copy link
Contributor

akru commented Dec 14, 2018

@symphorien symphorien deleted the non-broken-fetchcargo branch May 18, 2019 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants