Nixery: Transparently build and serve containers using Nix
github.com
github.com
I don't know where the community will land for a solution, but this is a clever method. I hope it builds traction
If this repository is the upstream nixpkgs[1], or if your private repository follows the same rules about not importing anything without fully-pinned hashes, you can already get those guarantees about the image content with Nixery today!
The one exception is packages that are not in the binary cache, end up rebuilt and aren't reproducible (the binaries might differ) - but NixOS is ~98% reproducible already[2]!
[1]: https://github.com/NixOS/nixpkgs/
[2]: https://r13y.com
The current layering strategy of the public instance is not the one linked to in the README (edit: fixed), it is the one described in this document:
https://storage.googleapis.com/nixdoc/nixery-layers.html
This strategy optimises for reducing the amount of data transferred. I recommend reading both this and the original post on buildLayeredImage!
After digging into the blog post, it sounds like the layers are sorted in a particular order, which suggests that the order in which you specify the packages doesn't matter.
That said, I went ahead and pulled nixery.dev/shell/git/htop, and then pulled nixery.dev/shell/htop/git, and I actually got different results. I ran `docker info` on both images and diffed the results, and the layer lists were slightly different. I filed this as https://github.com/google/nixery/issues/38.
The solution is to sort the packages in the name and return identical manifests. Docker doesn't seem to care about attaching names from registries that weren't in the config layer.
There's a separate issue where Docker will re-download layers it already has because it doesn't just use the content hash for caching, but those layers will be identical. Working on figuring this one out ...
The actual content layers (i.e. those containing Nix store paths) are going to be the same, but metadata layers (those containing the image name and the references to all layers) are currently going to be cache-busted.
I'll look into getting that fixed - as long as Docker doesn't mind seeing a different image name than it requested in the manifest it shouldn't be an issue to return the metadata in a stable order.
Though I'm curious. Can someone explain
> This is not an officially supported Google project.
"20% time" I guess?
On the other hand, if you want to work on open source on company time or use the code at work (which may have been part of the point of writing it), being able to do so is nice.
Do you know if there's an easy way to generate a Docker container from a Nix script? That could be a very nice alternative to a Dockerfile.
{ pkgs ? import <nixpkgs> {} }:
with pkgs; dockerTools.buildLayeredImage {
name = "curl-bash";
contents = [ curl bashInteractive coreutils ];
}
Putting that in a file and calling `nix-build` on that file will give you a tarball that Docker will happily load using `docker load`.Doing this has a lot of advantages over Dockerfiles, see this blog post for some of the others: https://grahamc.com/blog/nix-and-layered-docker-images