Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Use a pure Nix approach to building containers #31

Closed
wants to merge 2 commits into from

Conversation

adisbladis
Copy link
Member

@adisbladis adisbladis commented Jan 22, 2021

Motivations

  • To showcase that Nix is fully capable of self-hosting
    We don't want to showcase Alpine + Nix, we want to showcase Nix.

  • Optimal layering
    Thanks to dockerTools.buildLayeredImage

  • Baked in nixpkgs
    No need to wait for nixpkgs to download & unpack on your first invocation of Nix.

  • Smaller or similarly sized images despite better tooling
    We're now using standard GNU utils instead of their Busybox equivalents.
    This image is roughly the same size despite the better tooling and a baked in nixpkgs.

  • Auto-built on Dockerhub
    Dockerhub can build images for us on a schedule, no one needs to manually update images.

  • Cross compilation
    Officially we support many architectures, but only push images for x86_64-linux.
    In the future we want to support all arches officially supported by nixpkgs.

In particular this adds ARM support to the support matrix.

  • Declarative support matrix
    There is now a file called matrix.json in the root of the project.
    To add another architecture/channel simply edit this file, a script will take care of the rest.

Semantic changes

  • Tags
    The tags are now based on the Nixpkgs channels, rather than being based on the version of Nix embedded in the image.
    IME this matches much more closely to what people expect these images to behave like.

For example this is now a possibility:
FROM nixos/nix:nixos-20.09

Considerations

I would also consider to relicense this repository under MIT to match what nixpkgs is using.
Ideally we'd be able to port code back and forth from nixpkgs from this repo.

Merge synchronisation

We do need to change some settings on Dockerhub.
I am willing to put in this work if you can give me access @peti

Demo images

https://hub.docker.com/repository/docker/adisbladis/nix-docker

cc @peti

 ### Motivations

    - To showcase that Nix is fully capable of self-hosting
    We don't want to showcase Alpine + Nix, we want to showcase Nix.

    - Optimal layering
    Thanks to `dockerTools.buildLayeredImage`

    - Baked in nixpkgs
    No need to wait for nixpkgs to download & unpack on your first invocation of Nix.

    - Smaller or similarly sized images despite better tooling
    We're now using standard GNU utils instead of their Busybox
    equivalents.
    This image is roughly the same size despite the better tooling and a baked in nixpkgs.

    - Auto-built on Dockerhub
    Dockerhub can build images for us on a schedule, no one needs to manually update images.

    - Cross compilation
    Officially we support many architectures, but only push images for
    x86_64-linux.
    In the future we want to support all arches officially supported by nixpkgs.

    In particular this adds ARM support to the support matrix.

    - Declarative support matrix

    There is now a file called `matrix.json` in the root of the project.
    To add another architecture/channel simply edit this file, a
    script will take care of the rest.

 ### Semantic changes

    - Tags
    The tags are now based on the Nixpkgs channels, rather than being
    based on the version of Nix embedded in the image.
    IME this matches much more closely to what people expect these images to behave like.

    For example this is now a possibility:
    `FROM nixos/nix:nixos-20.09`

 ### Considerations

    I would also consider to relicense this repository under MIT to
    match what nixpkgs is using.

    Ideally we'd be able to port code back and forth from nixpkgs from
    this repo.
@adisbladis
Copy link
Member Author

Ping @peti

@domenkozar
Copy link
Member

domenkozar commented Feb 5, 2021

See also https://github.com/niteoweb/nix-docker-base that builds docker images for commits so that pinning can be more precise.

Also it would be good to have an image also without nixpkgs, when someone is pinning nixpkgs on their own (flakes).

@adisbladis
Copy link
Member Author

adisbladis commented Feb 5, 2021

I'm planning to push this through if no response by wednesday (2020-02-10).

cc @peti

Copy link
Member

@peti peti left a comment

Choose a reason for hiding this comment

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

I have discussed my thoughts about this PR in some detail in today's live stream at https://www.twitch.tv/videos/902198158?t=0h34m43s.

The gist of it all is that I agree that this solution is superior to the docker build that we have right now. At the same time, this code is much more involved than our current solution, which is pretty easy to maintain and to understand. Personally, I would not feel comfortable maintaining this new code because I don't know enough about the Docker infrastructure in Nix.

Therefore I'd suggest the following: If @adisbladis wants to be the maintainer of this project and deal with any bugs, fallout, or suggestions that come out of this change, then I am all for it and I'm happy to leave this project to him. If I'm supposed to maintain this project any longer, then I won't merge this PR and would rather stay with the simple straight-forward solution that we currently use.

@garbas
Copy link
Member

garbas commented Nov 22, 2021

@peti Hey!

The code from this PR was merged into nix repo, and the docker image is now being built by hydra. This was step 1.

Step 2 is to setup a GitHub Action to keep docker image up to date with the latest development in nix repo. For this I would need to permission to push to nixos/nix project on hub.docker.com.
Would you mind sharing this with me? (my username is garbas on hub.docker.com).

Step 3 would be to redirect/update all the links in relevant places:

  • Archive this repo and update the readme
  • Add Docker as an option to downloads page

@domenkozar
Copy link
Member

@garbas sent you invite for docker hub

@garbas
Copy link
Member

garbas commented Dec 15, 2021

This work was upstreamed to nixos/nix repo.

@garbas garbas closed this Dec 15, 2021
@garbas garbas deleted the pure-nix-containers branch December 15, 2021 10:36
This was referenced Dec 15, 2021
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/addgroup-command-not-found-with-docker-image-nixos-nix-latest/16615/4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants