10 ms·
Building Container Images with Nix
- xrd 5y agoThis is a really fascinating idea, and he presents clearly the problems with Dockerfiles and determinism. But, none of the links to his repositories are available anymore. It's a pity, I really wanted to see how you can replace Docker with Nix.
- justinsaccount 5y agoLooks like he renamed (or recreated) the repository: https://github.com/wagdav/wagdav.github.com/blob/main/flake.nix https://github.com/wagdav/wagdav.github.com/blob/main/flake....
- xrd 5y agoThere is something ironic about writing about Nix, which touts immutability as one of the incredible benefits, and having all the links broken in that post.
- lilyball 5y agoIt’s reproducibility that’s the benefit, not immutability. The fact that the Nix store is immutable is just an artifact of being a content-addressed store, not actually the point of anything.
- bfrog 5y agoI used this exact idea to do not just containers but cross compiled containers with cached artifacts using cachix, https://github.com/openenergysolutions/openfmb.adapters https://github.com/openenergysolutions/openfmb.adapters for a size-able example perhaps
- codetrotter 5y agoLink 404
- bfrog 5y agoFixed
- jvolkman 5y agoWe're using Bazel + Nix together to build Docker images containing Python apps and it's been working surprisingly well. Bazel builds the final image on top of a base image built by Nix (containing only Python sourced from Nix's repository). All hermetic and no Dockerfiles. I'm not a huge fan of Nix's expression language, but the system works well.
- yjftsjthsd-h 5y agoWait, what's bazel giving you if you already use nix?
- jvolkman 5y agoBazel is where I started. As an ex-Google employee it's familiar, and I prefer its build language. I found Nix when looking for ways to make Python builds reproducible across machines. Also, I get the impression that a Nix artifact is generally an entire library/package, whereas a Bazel artifact is often just one or a few files which fits well with how I prefer to use the build system. But I'm no Nix expert and that may not always be true. If Bazel had a better external dependency story (maybe someday [0]) then I'd probably not use Nix. But currently the pair seems to work well. [0] https://docs.google.com/document/d/1moQfNcEIttsk6vYanNKIy3ZuK53hQUFq1b1r0rmsYVg/edit https://docs.google.com/document/d/1moQfNcEIttsk6vYanNKIy3Zu...
- WraithM 5y agoNix doesn't have incremental builds. It's kinda all or nothing at the package level. This explains clearly why you'd want to combine both: https://www.tweag.io/blog/2018-03-15-bazel-nix/ https://www.tweag.io/blog/2018-03-15-bazel-nix/
- whydoineedthis 5y agoThe problem with Nix still remains it's documention, as this blog illustrates so well. - MAny links points to a bunch of 404's. - The links that don't 404 go to ubiquitous readme's that have so much information it's hardly a good place to start. - The demo he provided is the easiest of use cases with a single package and static files. How do I actually build a binary? How to accomplish the pip installs he shows with the Docker file? Why not show a really 1:1 example if it's so easy? And even if I work through all that for this blog, fat chance I'm going to convince my whole team to do so.
- lilyball 5y agoThe 404s are to the author’s own GitHub repo and are not a reflection on Nix. It looks like they deleted and recreated the repo with the name wagdav.github.com and just didn’t update the links in this post accordingly.
- Proven 5y agoMaybe such folks tend to like Nix.
- whydoineedthis 5y agoBut it is reflective. I've found that sort of thing rampant in it's community, and sometimes it's own docs. It doesn't mean it's bad tech, but will be hard to convince a corporate group to want to use it.
- liveranga 5y agoI'm surprised this post isn't making use of nixery - https://nixery.dev/ https://nixery.dev/
- rgoulter 5y agoNixery is a cool idea. The use case for something like Nixery is a more narrow "I want an image with these packages installed". Whereas, with Dockerfiles you've got more flexibility in the image you build.
- ghuntley 5y agoHmm not really. That's the toy use case. Nixery builds your expression and gives you a docker container. By default you can specify like "git and tmux" as they are the example toy expressions HOWEVER it becomes a different beast when you use it in monorepo situation see https://GitHub.com/ghuntley/ghuntley https://GitHub.com/ghuntley/ghuntley and https://code.tvl.fyi/ https://code.tvl.fyi/
- rgoulter 5y agoMy understanding is that's still "use Nixery to build docker image with packages installed", but it's a different set of packages being served. What use cases / dynamics arise from doing that? & what's the value-add from doing that with Nixery compared to just otherwise building docker images with dockerTools in Nixpkgs?
- neolog 5y agoNixery kinda seems like a toy. Does it have some more serious use?
- ghuntley 5y agoCome hangout with us https://tvl.fyi/ https://tvl.fyi/ — the visualisation has some hints :-)
- zeorin 5y agoMuch more in-depth article about Nix and Docker, covers how they overlap, contrast and complement one another: https://sandervanderburg.blogspot.com/2020/07/on-using-nix-and-docker-as-deployment.html https://sandervanderburg.blogspot.com/2020/07/on-using-nix-a...
- kristjansson 5y agoNix is really cool for demos like this, but seems to get complicated if you need to grab specific versions of a dependency. At last check, that involved digging through the history of the package/channel, grabbing the hash of the package corresponding to the desired version, and then referencing the package by hash, all with basically no tool support? For system that is so proud of allowing multiple versions of dependencies to coexist, it seemed surprisingly difficult to actually find and use specific versions of a dependency in, you know, applications.
- ducktective 5y agoFlakes, which is currently an experimental feature, is gonna solve the issue. It works similar to cargo and npm, in that it pins the dependencies and creates a lockfile.
- trulyrandom 5y agoAs I understand it, flakes don't really solve the problem parent is talking about. The discoverability is still poor. Say I need a python package at version x.x.x. How do I find which nixpkgs commit hash I should use to get that specific version?
- scintill76 5y agoI believe you can override the version property of the derivation that builds the package, if its build script is compatible enough between the two versions.
- nh2 5y ago> How do I find which nixpkgs commit hash I should use to get that specific version This is answered in a sibling comment here: https://news.ycombinator.com/item?id=28243409 https://news.ycombinator.com/item?id=28243409 The tool does exactly that. However: > find and use specific versions of a dependency in, you know, applications. This is not what nixpkgs currently provides, or aims to provide. nixpkgs is like the Debian, Gentoo, etc. package repos: In most cases, it provides one version of a package. If you want to use an older one, you have to use older version of all dependent packages, as they were at that time; this in practice means using software with security vulnerabilities that are only fixed in current nixpkgs. nixpkgs is not currently designed to let you compose your application from libraries taken from different nixpkgs versions. It is insecure (see above) and slow (evaluating more than a few different nixpkgs versions takes a long time). The current correct way is to use a current nixpkgs version as a base, and then use an override to update the sources of the packages you want to have a different version of explicitly. Or use a tool that does this automatically for your programming ecosystem based on that one's package manager, like `stack2nix` for Haskell, `yarn2nix` for Javascript, and so on. Nixpkgs makes such overrides easy.
- yewenjie 5y agoThere is also Guix pack - https://guix.gnu.org/blog/2018/tarballs-the-ultimate-container-image-format/ https://guix.gnu.org/blog/2018/tarballs-the-ultimate-contain...
- ghuntley 5y agoIf you want to take nixos for a spin in your browser head to https://github.com/gitpod-io/template-nixos https://github.com/gitpod-io/template-nixos and mash the button. Also https://nix.dev https://nix.dev is one of the better learning resources. Over at https://GitHub.com/ghuntley/ghuntley https://GitHub.com/ghuntley/ghuntley you'll find a workshop I created on Nix.
- jnsaff2 5y agoI found Burke Libbey’s videos really useful to get a good grasp on Nix https://youtube.com/channel/UCSW5DqTyfOI9sUvnFoCjBlQ https://youtube.com/channel/UCSW5DqTyfOI9sUvnFoCjBlQ
- vmsp 5y agoI wish he'd open-source runix. https://gist.github.com/burke/72ca46c80e57a25907a75611ee5eb66d https://gist.github.com/burke/72ca46c80e57a25907a75611ee5eb6...
- takeda 5y agoI think it is too heavily integrated with Shopify that it probably is difficult to make it a general tool. I created something similar for my needs, although perhaps it is a different, but it was inspired by the configuration file :) Looks like Burke's runix is about starting multiple services, to create dev environment. My tool creates an opinionated dev environment (you enter nix-shell or direnv and everything is already set up) that is already integrated with Nix, that means out of the box you can generate nix package, or build a docker image. Right now it only supports python (poetry) and go which is what I need right now but other languages can be added later. Not sure if others would find it useful, technically you could just create own shell.nix and default.nix, the problem is that it ends up being a lot of boilerplate and a lot of nix code which scares away people not familiar with Nix.
- rkangel 5y agoI use Nix to provide consistent build environments (and then use whatever project tooling). This allows for an even simpler approach. I write a shell.nix that gives my dev environment. Developers can use that while developing to get a consistent build environment. I can then set up CI in Gitlab by just applying that environment as a before_script. Something like this can be a complete CI file: image: nixos/nix:latest before_script: - nix-env -f shell.nix -i -A buildInputs test_build: stage: test script: - elm make elm-src/Main.elm If you've got loads of dependencies and/or they need to be built and take a while then this can obviously slow down your CI and you'll want to build the docker image. For simpler projects, it is incredibly quick, simple and robust to set up.
- ducktective 5y agoIs it possible to cache the already built dependencies in Github or Gitlab CI if one is using a NixOS image?
- tiew9Vii 5y agoI believe so. https://cachix.org/ https://cachix.org/ provides some off the shelf services. There's a few blog posts about using AWS S3 as a binary cache so you can roll your own.
- danieldk 5y agoCachix is really awesome. There's a few blog posts about using AWS S3 as a binary cache so you can roll your own. Unfortunately, this is really slow due to Nix using Brotli compression at a high compression level. There were some PRs to make the compression method configurable, but the last time I checked, none of them were merged. It is not really an issue if your outputs are small. But I had a private S3 cache and have some derivations that have large output paths, and it made CI excruciatingly slow.
- rkangel 5y agoI think of building the docker image as a 'cache' of the dependencies, but actually something like Cachix would provide a more flexible solution (i.e. helping developers as well as CI).
- flyinghamster 5y agoIn the article, here's a dead link in the statement, "Concretely, for the example showed in this section, you can find the complete definition of htmlPages here."
- alex-ant 5y ago"some dependencies are only needed to build the image" - it's true if you don't write proper Dockerfiles. You're always free to build an app in a separate image, mark it with `AS build-env`, and then copy the result into an image containing an entrypoint with `COPY --from=build-env`, all within the same dockerfile.
- goodpoint 5y agoThe big problem with both Docker and Nix is that nobody is there to backport security fixes to older versions of libraries and applications.
- danieldk 5y agoThat's assuming that you start with images. If you start from Nix expressions, you could update your pinned version of the nixpkgs stable branch and rebuild the container image?
- takeda 5y agoActually that's not true. While docker's reproducibility is based on an image snapshot of a state. Nix reproducibility is really just a recipe how to build it. Because of that it's not really an issue. Yes, if you build a docker image through nix you have to regenerate it (which is easy) but that's how docker works.