-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
gvisor: init at 2018-11-10 #50218
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
gvisor: init at 2018-11-10 #50218
Conversation
9757edc
to
6e79aab
Compare
6e79aab
to
67c0595
Compare
I tried testing this with Docker, but it looks like the
I can remount the
I don't have time to rebuild my kernel with that cgroup option right now, but I'll try to get it to it soon, unless someone else wants to have a try! |
@orivej - After applying #50225, and setting |
find "$out" -name '*.sh' -exec \ | ||
sed -i 's|#!/bin/bash|#!${bash}/bin/bash|g' {} \; | ||
|
||
find "$out" -name '*.go' -exec \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is only required by tests. Could you try with '*_test.go'
?
Also, it woul be nice to patch this upstream:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into patching this upstream at some point, sure. For now, fixed this, the merge conflict, and force-pushed.
@Profpatsch Do you know if there is a more simple way to prefetch dependencies for Bazel builds in |
I tried a couple ways to do this, but wasn't successful. You can use |
67c0595
to
e92c7ea
Compare
|
This looks good to me. This is not required, but it would be nice to have a NixOS test that uses this container runtime engine. I could help on that. @GrahamcOfBorg build gvisor |
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: gvisor Partial log (click to expand)
|
No attempt on x86_64-darwin (full log) The following builds were skipped because they don't evaluate on x86_64-darwin: gvisor Partial log (click to expand)
|
Unexpected error: command failed with exit code 1 on x86_64-linux (full log) Attempted: gvisor Partial log (click to expand)
|
@nlewo - This should be pretty reliable through Bazel upgrades; the I'll try to get a NixOS test added today or tomorrow; it'll be my first one, so I'll happily take any advice! In the mean time, do you mind kicking off another build? Looks like the Linux build failed due to disk space, which doesn't look related to this PR. |
# NOTE: this is the output of the whole fixed-output derivation, so | ||
# `nix-prefetch-git` won't work to obtain this. The easiest way is to just | ||
# change it and see what breaks :) | ||
sha256 = "1bcnq7kazbf6l5j0g82x2lvg1nbp7z70klk139dxi0jkw0j8dh3r"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the expected hash. Maybe, you forgot to update it when you changed line 63.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhhhhh, I know what this is. The fixed-output derivation has the paths to bash
and coreutils
as part of the derivation, so any change to those results in a new hash here too. That's annoying 😒
I think I can fix that by changing the bash
calls to /bin/sh
, and just dropping the test fixes since we're not running them anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, it would be better to patch shebangs in the patch phase of the bazelDependencies
derivation.
|
||
outputHashMode = "recursive"; | ||
outputHashAlgo = "sha256"; | ||
outputHash = "0430pn3q71r6pyxq32k2n1zhnp9hvs5mizvw3zy6zwrsv3fchdb6"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hash is also not the expected one when I locally build it. But this could be related to the update of the hash of patchedSource
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I force-pushed the fix for the comment above. If this hash still doesn't work, mind running this command for me (with the correct store path) and uploading the results to Gist / Pastebin / something?
(cd /nix/store/35j7izc656kyppz5nqci9c6rivp2zi9s-gvisor-build-dependencies-2018-11-10 && find . -type f | xargs shasum | sort -k 2,2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrew-d Hashes are not corrects:(
Let me know if https://gist.github.com/nlewo/bbd43f6a7c985e6d70402ac55a439116 helps you: there are hashes of the resulting build temporary directory (nix-store -rK ...
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this is going to be substantially more annoying than I'd expected. After a bunch of digging, here's what I've found:
rules_go
uses some helper tools, which theygo install
into a synthetic repository- Bazel creates
.marker
files to track whether repositories are up-to-date (and which is the vast majority of what differs between our two systems); these marker files appear to include the hash of the underlying files in the working tree. - Since these are built using the regular
go
tooling, and inconsistent paths, they don't have a consistent output hash. - Bazel will verify marker as part of the build process, so we can't patch these tools post-hoc (since this means the hashes in the marker files don't match and Bazel tries to re-download everything).
I'm honestly at a bit of a loss; here are my thoughts:
- Try to get these tools building in a reproducible fashion (requires an upstream patch in
rules_go
) - Do something to fix these specific files; the inconsistency comes from a specific debug section in the output binaries (
.note.go.buildid
), so we could try to zero out that section.
Of the two, I'm going to try to do #1, since the second feels fragile to me. But overall, yeah, this is pretty annoying 😒
(also, I thought about trying to build things with Nix itself, but unlike the *tonix utilities that other languages' package managers use, Bazel repository rules allow running arbitrary shell scripts, so I think we'll always have to run Bazel itself to fetch dependencies)
e92c7ea
to
f1a1545
Compare
Current state: I've submitted a patch to Our Go compiler has patches[1][2] that replace the absolute (also, holy hell is this rapidly turning into something more complicated than I'd originally expected 😛) |
Thanks for putting in the work to research bazel builds inside of nix.
I haven’t seen fixed-output hashes for anything but implementing fetchers, since they require absolute determinism. Especially with a semi-hermetic build tool like bazel which uses build rules written by imperative programmers (cough Best strategy I can see right now is using their lock file to parse out all hashes and check those hashes into nixpkgs (plus an update script that can update the hashes). Since the output format is skylark, you should be able to parse it as valid python syntax (or |
f1a1545
to
1564b70
Compare
This was super annoying, but: I've just force-pushed an update that successfully builds gvisor by manually fetching all dependencies with Nix. It's especially annoying since @Profpatsch and @nlewo - thoughts on this new approach? |
1564b70
to
e38bc1c
Compare
Just pushed an alternate version; this is now generated by a very WIP script that will parse the Bazel resolved-dependencies file and attempt to convert it to a Nix file. It's pretty hacky, but I'm heading to bed and figured I'd drop it here for now! |
I really like it. Would be nice to split out the parser to get a generic transformation from bazel lockfile to nixpkgs package. Of course then the generated code must be overridable, I can help with that if you want. See https://github.com/Profpatsch/yarn2nix/tree/master/nix-lib for an example on how that can be done (there might be some code-reuse possible). |
@andrew-d Wondered if you ever continued with this? I really like the idea of running services on my NixOS machine within gVisor KVM containers, especially for things like the Unifi controller I run, a big Java behemoth. |
@benpye - The short answer is "not yet"; I'm currently trying my hand at a slightly more generic "Bazel to Nix" translator, and once I get that working will update this PR with the generated code. This branch does work, though, if you want to apply it to a local fork! |
@andrew-d anything you need help with? This is rad. |
Motivation for this change
Add a package for the
gvisor
container runtime sandbox. This was requested in #39889, but there were some problems with Bazel at the time. I've managed to get this working, but I'd appreciate feedback on how I've done so. In short: there's two derivations here; one that is a fixed-output derivation produced by runningbazel sync
to download all dependencies and making them deterministic, and a second that uses the above derivation along with the source in order to build the actual output binary. At the end of the whole process,gvisor
is runnable:I haven't yet tested this with Docker, so I'll try to do that shortly.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)cc @dtzWill and @q3k (on the original issue)
cc @mboes (Bazel maintainer - feedback appreciated!)