News for hackers. Stuff that matters.

Show HN: Compose2nix – NixOS and Docker Compose made easy

https://github.com/aksiksi/compose2nix

Hi!

compose2nix is a CLI tool that automatically converts your Docker Compose project into a NixOS configuration[1].

* Why does this even exist?

Well, NixOS is a Linux distro that is configured using Nix (the language). However, Compose adds a configuration layer on top that is opaque to Nix, which means you lose out on some of the "magic" of NixOS. compose2nix solves this by "lifting" Compose functionality into native Nix/NixOS constructs, which results in a more native integration with NixOS.

In addition, this tool unlocks two primary use-cases:

1. You can run existing non-trivial applications - e.g., Immich - without worrying if they're natively packaged for NixOS.

2. You can bring your existing Compose stack over to NixOS and run it as-is without having to rewrite it in Nix. The auto-generated config can either act as a starting point, or you can keep your Compose file as the source of truth and re-generate it as you go.

* How does it work?

compose2nix maps Compose constructs into systemd services that run native Docker/Podman commands. Under the hood, the tool utilizes the same Compose library[2] used by the Docker CLI, so you also get Compose syntax checking "for free". In a way, it's a thin re-implementation of the Docker Compose CLI. One thing to point out is that compose2nix aims to natively support both Podman and Docker as container runtimes.

The README has a bit more detail. There's also a (somewhat rambly) video that explains what the project is about and includes a short demo of the tool: https://www.youtube.com/watch?v=hCAFyzJ81Pg

Oh, and please feel free to shoot me any questions or feedback (good or bad)!

[1]: In case it's your first time hearing about NixOS, here is a good overview: https://zero-to-nix.com/concepts/nixos

[2]: https://github.com/compose-spec/compose-go

( 2 comments | 2 points | on HN )
Re:Show HN: Compose2nix – NixOS and Docker Compose made easy by olebedev on Saturday October 05, 2024 @01:58AM (#41747996)
Hi, this looks awesome, thank you for exploring Nix capabilities, that is a great piece of software.

I am curious, what drives you using docker if images can be broken down into Nix packages?

Don’t get me wrong, the project looks really cool, and it’s a bit of a hassle to write orchestration using NixOS configuration utilising systemd.

Re:Show HN: Compose2nix – NixOS and Docker Compose made easy by Cyph0n on Saturday October 05, 2024 @07:13AM (#41749082)
The focus here is on Docker Compose projects rather than container images. It’s much trickier to package a multi-container service for Nix. And if Compose works for you, why go through the hassle of packaging natively?