Show HN: MyNixOS – Create and share Nix and NixOS configurations (mynixos.com)
I want to show you MyNixOS.com - a website I've been working on this year to make it easy to create and share Nix and NixOS configurations. Nix is a powerful tool to deploy software in a reproducible way, and with NixOS you can control your whole operating system through a declarative configuration.
Starting out with Nix was exciting, but it definitely had a challenging learning curve. This made me start building a website focused on making it easier to create and share Nix flakes, which are the core unit of software deployment in Nix.
Using the website, you can create flakes without knowing the Nix configuration language, as the necessary Nix files are generated for you. A few examples of what you can do right now:
1: Create and build a Docker image with Redis and OpenSSH running NixOS: https://mynixos.com/mynixos/demo-docker / https://www.youtube.com/watch?v=3fuCGXHw7qM
2: Create a Nix development shell with Neovim and Zig and run it on Windows 11: https://mynixos.com/mynixos/demo-windows-devshell / https://www.youtube.com/watch?v=F4q72mGjYXA
3: Create a reproducible macOS environment using nix-darwin and Home Manager: https://mynixos.com/mynixos/demo-macos / https://www.youtube.com/watch?v=r0Y7s1sRSUY
4: Create a Linode server image using NixOS running Nginx with Let's Encrypt: https://mynixos.com/mynixos/demo-linode-nginx / https://www.youtube.com/watch?v=Cy4X0fjD0-Y
5: Create a Raspberry Pi NixOS image running Transmission and OpenSSH: https://mynixos.com/mynixos/demo-raspberry-transmission / https://www.youtube.com/watch?v=6L0H92-JdHA
The site works directly with the Nix command line tool, and generates pure Nix flakes without any custom formats. The website is currently in alpha and is developed as a closed source project. Some interesting upcoming features include support for language environments such as Python, and the ability to install arbitrary versions of packages.
By posting on HN, I'm especially looking to get in contact with early commercial users of Nix to learn more about the most important use-cases to solve. Hoping that you will find the site useful, and I'll happily try to answer any questions you might have!
29 comments
[ 2.9 ms ] story [ 69.9 ms ] threadThese examples look neat. I'm reminded of https://nix.dev/ (which, sadly, is pre-flake).
> make it easy to create and share Nix and NixOS configurations
I could see a lot of value in the sharing/reading aspect of this. -- I think it'd be helpful to be able to look at different NixOS configurations without having to dig into the code directly.
> The site works directly with the Nix command line tool
I find this part confusing.
One of the neat things about nix flakes, is that it's "like docker without containers". You can just run `nix run github:<owner>/<repo>`, and nix will be able to run the code from that flake. -- So I guess I'd expect the "copy-paste to run this" command to be similar to "nix run https://mynixos.com/<whatever>".
But, the "Download" section in the Meta tab of the demonstrations are about using some tool that isn't nix.
Note that the commands shown in the "Meta" section are just shell scripts to help you install Nix, direnv, and a flake loader, which is just a convenience wrapper that you can keep in your source control if you wish.
[1] https://floxdev.com/
As the potential for the core Nix technology is so great, many different approaches and tools will be necessary to help discover and cover the different use-cases. Flox made a good impression at NixCon in Paris, and they seem to be doing a lot of good things to make the community solid.
> many different approaches and tools will be necessary to help discover and cover the different use-cases
this -- we're very excited to see the many experiments going on in the "Nix UX space". The more the merrier. While we do see significant opportunity to solve problems for enterprise, we designed the core flox CLI for anyone to use. And of course it can work with any flake you provide, from MyNixOS or elsewhere...
Looking forward to making it more public soon :)
Maybe that's fine for your target user, but I would think you could get non-nix folks on board if there was more of a "wizard" type flow that tells you the options and explains them as you go through it.
Composition is already possible, where you can import modules between flakes, such that you can keep e.g. the Docker base config in one flake, then re-use this in other flakes. Soon, indexing of modules will also be added to the site, which will make it easy to import e.g. a base computer configuration from `nixos-hardware`: https://mynixos.com/nixos-hardware
Some other features which will be added is cloning of flakes, and easily copying + moving sets of settings between modules and flakes. This should also make it easier to borrow settings from other configurations to build your own.
That said, I also agree with you that having reusable modules that are documented would help, and being able to clone and copy/paste settings + seeing examples would too. Good luck!
But it’s impossible to discover all the various things you can do.
However, a bunch of packages are defined in some bespoke way with various custom config inputs that generate other bits of config and generally are hard to understand. Thinking it through, I'm not sure it's possible for the OP's tool to solve this particular problem.
I am guessing Nix flake is like Dockerfile. You build it, and then what? How/where do you run it? k8s? Docker? Is it OCI?
Nix is a lazy, functional programming language that was designed to write reproducible packages (in the traditional Linux distro sense).
A Nix package is just a function. It takes in some inputs (the dependencies), and produces an output. But instead of saying “take libssl”, you actually say “take libssl at this exact version” (or more precisely at this exact combination of input files with this exact content). However, because it is a programming language, you can make the package inputs generic over the version. This may seem esoteric and pointless but actually gives rise to a lot of nice properties (reproducibility, caching, recompilation tracking among others).
Nix Packages, are a collection of packages that are written using this language. It’s pretty comprehensive and many packages can be used on both Linux and Mac (like Homebrew), so it’s a cross-platform package manager. Unfortunately, the package manager for this set of packages is also called Nix.
NixOS is an operating system built on top of the language, using the packaging ecosystem (Nix Packages) and also providing some abstractions for writing services, declaring users, crons etc. (kind of like Ansible).
A Nix Flake is a relatively new thing. It is a framework on top of the Nix language for writing these {packages/OS config} that can much more cleanly specify the dependencies and pin them. Kind of like NPM, but for everything (package versions, OS module versions, any Git repo etc.). You could do this before, but it was less nice. Now, you can update all the dependencies of your entire project with one command, including things like shell plugins, Vim plugins, the version do Bash used to run your build scripts, developer tools, LSPs for your editor, your text editor itself (though I usually don’t go this far) etc.
There are many other uses. You can use it to build OCI images (they are just a specific way of combining some dependencies, and this can be expressed pretty easily in Nix). These have better properties than typical Docker images (built via Dockerfile) and can be cached better and tend to be smaller without needing to use something like musl. You can use it manage user dotfiles (similar to OS management, see Home Manager), developer environments (kind of like Python virtualenv, but for everything), project dependencies and whatever else you can build on top of the language really. Basically anything that could benefit from having packages nicely integrated with config could be built with/on top of Nix.
Why would you use it? Well for me:
* I like being able to manage package versions and config together painlessly, which was always a pain with Ansible.
* It’s fully declarative (if you remove the config for a service it stops running; not true for e.g. Ansible)
* Nix language is not the greatest, but it is sooo much better than YAML. Unfortunately the set of language features needed is quite niche, so it couldn’t just be a library for an existing popular language (except maybe Haskell or a Lisp)
* I like being able to update everything (with free rollbacks if something breaks) with 1 command.
* It’s pretty interesting. It’s theoretically quite well built and find ways to make good use of some nice programming constructs (e.g. fixed points, laziness), that appeals to me. What the language lacks is documentation and tooling.
* Reproducibility is nice, but not the selling point for me.
I dipped in my toes with using Nix Shell to have reproducible developer environments and then slowly moved everything over.
Thanks for the writeup by the way, it's appreciated and well done.
I get that NixOS is a Linux distro. What is Nix's answer for containers?
aka the typical Docker flow
Dockerfile -> build OCI image -> run it as a container
Nix package -> ? -> ?
* Use Nix shell for developer environment. Use it to provide a version of Docker, Rust, development Postgres etc. This is just a kind of virtualenv you activate after you cd into the project directory. You can manually manage the versions of the tooling for your project separately (if needed) and you don’t need to install these globally on your developer machine.
* Replace Dockerfile with a Nix package. This may be a bit trickier depending on how complicated the app is. You can build the rust app with Nix and then build a Docker image from the rust app and all other things you want in the container. You can do the same for Postgres (although there’s less point, since the Docker image is officially maintained). There’s no direct benefit to doing this (except maybe smaller images if you aren’t using e.g. alpine and maybe slightly better cacheability).
* Replace your base OS with NixOS. This is whatever you run the Docker containers on. You’d still use Docker containers and Docker compose, but the underlying OS would be NixOS, rather than Ubuntu/Debian/etc.
* Replace Docker containers with systemd services on NixOS. This is the hardest sell, but a lot of people use Docker just for versioning and providing dependencies, and you can just use Nix for that. So if you don’t need to use Docker for other things, you can just run apps on bare NixOS, using systemd configured with Nix (the language). That’s what using services on NixOS will do. You’ll basically be writing systemd services for your app (there is already going to be one provided by NixOS for Postgres) in the Nix language and running them directly on Linux. One thing that’s not easy to do with Docker Compose is cron jobs (for backups monitoring etc.). You can run these just as systemd timers. This also has some nice benefits (e.g. user isolation whereas Docker containers run as root, Unix sockets to avoid needing to bind ports and restrict access to certain users, no extra (runtime) layers on top of your OS, less complex networking).
To illustrate as examples on the Docker flow
Start: Docker, Rust etc. installed globally.
Dockerfile -> build OCI image -> run it as a container on Debian/whatever as distro
Stage 1: Docker, Rust etc. installed in a Nix Shell
Dockerfile -> build OCI image -> run it as a container on Debian/whatever as distro
Stage 2: Docker, Rust etc. installed in a Nix Shell
Nix package -> build OCI image with Nix -> run it as a container on Debian/whatever as distro
Stage 3 (can be done independently of 1 and 2): Docker, Rust etc. installed in a Nix Shell
Nix package -> build OCI image with Nix -> run it as a container on NixOS
Stage 4: Docker, Rust etc. installed in a Nix Shell
Nix package running as a systemd service managed by NixOS
Nix solves "distributing software is hard" by ensuring declarations of packages can be built/run in a reproducible way.
Software built with Nix doesn't need to run in a container runtime (which is much nicer for desktop / workstations).
Nix's strength is dealing with packages in a programmatic way. This allows it to also serve as a package manager (like brew or pacman), as a way of declaring an OS configuration (in NixOS), it can also be used to build container images, or VM images.
- https://www.reddit.com/r/NixOS/comments/wzqv2v/mynixos_alpha...
- https://www.reddit.com/r/NixOS/comments/ys0tad/mynixos_alpha...
Trying to not spam in order to keep the signal ratio decent, however this new set of tutorials might make sense to post :)
https://www.reddit.com/r/selfhosted/comments/z66yo9/mynixos_...
You've built a great tool here, seriously nice work!
... but you built it on an experimental feature that isn't enabled by default, that requires understanding the extensibility mechanisms to add experimental features that the Nix project doesn't feel comfortable calling done yet, that may change in future
... except everyone says flakes are totally stable and fine to use cause. Like basically everyone seems 100% fine with flakes... to the point where I've even come across first time Nix user tutorials that assumed you had already jumped through the hoops to enable an experimental feature a.k.a. "flakes" and this was several months ago.
But if flakes are so amazing and so stable everyone is using it and assuming everyone uses it and wants everyone to use it... after an entire year of wide public use ... why aren't they a stable feature yet, or even planned for release as a stable feature?
Once Nix can get this sorted, I'll probably be using it within a week. But I'm not comfortable diving in and making heavy use (I've played with Nix at every layer, from my macOS user as a homebrew alternative, to Docker/Container building, to running entire headless and desktop immutable OS installs on bare metal using NixOS) ... but for now its still an experimental feature so once again I'm putting Nix back in the "check it out again later next time HN gives me a good reason" drawer... I'm not going to rely on experimental features and I'm not going to learn and internalise how to do everything the hard way when flakes is obviously better (I did actually RTFM on all this), I just keep waiting for it to be blessed as stable.
The site is built on the assumption that the flake interface is here to stay. The reason is simply because it is a very powerful, general, and pure interface. To simplify the installation process, the https://mynixos.com/install-nix install script makes sure to enable the necessary config to use flakes.
Hopefully the feature will be declared stable soon, and I totally get your feelings towards depending on experimental features.
By the time you get comfortable with the syntax and tooling, you could’ve just crafted use-case specific shell scripts to compile/configure everything from source…
Feel free to check out one of the MyNixOS demos - hopefully having a working starting point and being able to modify a config without writing Nix can make it easier for beginners.