8 ms·
NixOS for the Impatient
- turboponyy 3y agoNixOS is not for the impatient. Maintaining your system configuration is an exercise in software development like any other - if you lack rigor or discipline, your codebase will become painful to work with. Nothing is ever one shell incantation away - it has to be carefully architected into the existing system. That being said, once you get the hang of things, you reap amazing benefits: - You can clone your system to any machine, and immediately have an identical environment - You can share system configurations as code (declare the means for hosting a website in its repository, for example) - You can use a fully-fledged programming language to configure any part of your system - You can make use of an extensive ecosystem of easily composable, prebuilt NixOS modules - You can seamlessly integrate with Nix, allowing for ephemeral development environments and shells with packages, eliminating much of the need for imperative package management - Everything in a Nix-based system must be derived strictly from (lockfiled) inputs, making the reproducibility guarantees incredibly strong (barring any network errors or resources being taken down) - The declarative nature of anything Nix-based means that every change is documented - your system never shifts from the source of truth, compared to other distros where discipline is required to maintain reproducibility - Nix is so robust that you could even nuke your filesystems on every log out, if you'd like
- smoldesu 3y ago> You can clone your system to any machine, and immediately have an identical environment It's arguably the killer feature of NixOS, if stability and purity means nothing to you. A few weeks ago I bought a little SBC (Quartz64) for my homemade NAS project. Since I'm already a NixOS user, the bootstrap process was easy: - Build ARM image for NixOS and boot off the device - Clone my dotfiles and symlink my config folder into /etc/nixos - Rebuild my system And boom. Everything is there, my shell and coreutils and things I've come to expect all get rolled into the system. Updating it just means git pull and a system rebuild. As you say - it's not for the impatient. You have to maintain your config pretty regularly, and covering multiple devices across multiple architectures requires some deliberate config organization. I'm not sure where I fall on the patience spectrum, but NixOS worked out pretty great for me. It's on my desktop, laptop and homeserver, and I haven't had a single bad update in my 8 months of daily driving it.
- skavi 3y agoHow do people deal with isolating system specific config in Nix? Like stuff for a particular graphics card?
- huijzer 3y agoI use symlinks from configuration.nix and hardware -configuration.nix and point to specific instances for specific systems.
- throwaway22032 3y agoI have "if hostname == xyz" in my config, or I use a little config file with flags like "is_laptop".
- smoldesu 3y agoThere are a few solutions to this, but I keep separate configs for each device and link them into the entrypoint (/etc/nixos/configuration.nix) as-needed when I set things up. Then I have other "module" files for my terminal environment and my desktop environment, as well as an extra file that enables Wine/gaming packages.
- JamesLeonis 3y agoIn addition to the other suggestions, you can create different files for (e.g) each machine and use common includes for your apps and settings.
- evil-olive 3y agopersonally, the way I do it is: /etc/nixos/roles/foo/default.nix has config for the 'foo' role (eg, I have a desktop role that enables all my GUI options) configuration.nix and hardware-configuration.nix in /etc/nixos/ are symlinked to the actual files in /etc/nixos/hosts/<hostname>/ in the imports section of each machine's configuration.nix, I import /etc/nixos/roles/foo for each role the machine should use. for your graphics card example, I have 'nvidia' and 'nvidia470' roles that pull in their respective nvidia driver (due to an old gaming laptop that requires the legacy driver version) I have a 'core' role that all machines import, with the global config I want on every host this allows me to version-control my entire /etc/nixos directory (managed as a private git repo, replicated using syncthing rather than pushed to Github/Gitlab/etc). the symlinks in /etc/nixos are in .gitignore because they're machine-specific, and the actual per-host config files are able to be tracked in their own directories.
- anotherhue 3y agoI mount '/' as a tmpfs so yes, I nuke my OS every reboot. It's reconstructed from the /nix/store and obviously my homedir is on a persistent volume.
- eikenberry 3y agoIf this setup could be combined with an easy way to customize things, like ublue (https://ublue.it/ https://ublue.it/) lets you customzie fedora silverblue using Dockerfile configs, I'd adopt it in a heartbeat.
- bfrog 3y agoI’d think configuration.nix would be enough?
- anotherhue 3y agoI have yet to find a non customisable nixos component. It'd a source system that's excellent at building from source so there's always a way.
- eikenberry 3y agoSorry, I was unclear, by easy I meant simple. Dockerfiles are simple. I've yet to find an equivalently simple way with Nix.
- anotherhue 3y agoI haven't tried it but I would suggest looking here for some inspiration https://nixos.wiki/wiki/NixOS_Containers https://nixos.wiki/wiki/NixOS_Containers
- peoplearepeople 3y agoWhat does the config for doing that look like?
- 3y ago
- thomastjeffery 3y agoPatience isn't necessarily for time: it's for wasted time. That's not to say NixOS won't waste your time: it will just waste it in a different way.
- zetalyrae 3y agoI thought "too complex, too much of a timesink" and that kept me from trying it for a long time. My experience is different. If you are at all idiosyncratic about your setup, using Nix is better than whatever pile of bootstrapping bash scripts you've kludged together over the years.
- n8henrie 3y agoAbsolutely. I'm about a year deep on nix / NixOS and still spend way too much time refactoring things to be more DRY or what I think might be more idiomatic or maintainable going forward (as opposed to a more obvious but uglier approach). Definitely makes it easy to waste time prematurely optimizing, if you're prone to that sort of thing.
- soraminazuki 3y agoThe difference is that with Nix, you'd always have a working configuration. With traditional deploy tools, scripts stop working at the most inconvenient timing because they're not reproducible.
- cosmojg 3y agoI can do (almost) all of these things with a traditional Linux distribution, git, and a few scripts written in my language of choice, and I can do it faster. Nix seems more competitive with something like Conda or Spack than a traditional package manager like Apt or Pacman. Similarly, NixOS seems more suitable for deployment in containerized environments built on woefully outdated deps than personal dev setups with generally higher security requirements. I've experimented with both Nix and NixOS, and while I adore both the beautifully functional language and the endlessly helpful community, I haven't been able to justify the overhead of maintaining a nix.conf, flakes or no flakes, on top of everything else I need to do on my machines. I kept running into issues where some program I needed wasn't already integrated with the Nix way of doing things or something that worked on my Linux setup failed to work on my macOS setup despite multiplatform guarantees. Nevertheless, I wait with baited breath for the day that Nix replaces Conda among a critical mass of practitioners in my field. I've tried getting a few of my teams to switch (with help from Devbox and Devenv), but it's a struggle to get people to learn new things when their (often worse) way of doing things works well enough most of the time. Heck, I count myself lucky for getting some people to switch from the atrociously slow Conda to the significantly faster Mamba as even that was inordinately difficult despite for latter being a drop-in replacement for the former.
- zetalyrae 3y ago>I can do (almost) all of these things with a traditional Linux distribution, git, and a few scripts written in my language of choice, and I can do it faster. As someone who moved from a directory of numbered bash scripts and GNU Stow to Nix, I can't disagree more. The fundamental difference is one is imperative and the other is declarative (and reproducible), and that makes all the difference.
- indemnity 3y agoExactly. I have used Linux since 1994, from Slackware to RedHat to Debian to Gentoo to Ubuntu to Arch. NixOS and nix-darwin both using nixpkgs is the first time I have the exact same shell and programming/CLI environment on all five of my personal and work machines which run Linux and macOS. I upgraded them all to the 23.05 versions from 22.05 by updating my flake.lock and doing a rebuild switch on all machines. No regressions. Some cobbled together shell scripts and a Git home dir management system (yadm) is what I had before and it doesn’t come close. I also dreaded upgrades with the previous approach. And didn’t have nearly the same control pristine replicated environment across machines. It’s even flexible enough that on Linux desktop machines I have X11 and bspwm DE environment, on servers no X11, and on macOS it configures my system preferences, Dock icons and installed App Store apps.
- slabity 3y ago> Everything in a Nix-based system must be derived strictly from (lockfiled) inputs, making the reproducibility guarantees incredibly strong (barring any network errors or resources being taken down) Or multithreaded compilation :P
- jalino23 3y agoalright time to learn nix
- herewulf 3y agoAnd if you don't like it, you might try Guix which is a Guile Scheme based implementation of basically all the same concepts and features.
- UniqueUsername0 3y agoWrong. Guix's ecosystem is very much behind Nix's.
- npub1zenn0 3y agoThis is keeping me from immediately jumping on Nix. I'd rather use guix and scheme, but it's behind. If I learn nix, and then guix some day catches up, I'll already know nix and won't want to make the change anymore. Can't say I like the outlook for guix.
- herewulf 3y agoInteresting. I've been writing Bash scripts for over 20 years and despite my comfort with it, I'm always exploring avenues of replacing it. Despite the time investment already spent, I know there are far better tools out there to do the same jobs.
- herewulf 3y agoPerhaps you could expound upon that?
- xorcist 3y agoSo just like Puppet/Ansible/Salt then? > Nix is so robust that you could even nuke your filesystems on every log out Comments like these makes it hard to understand what is really going on. Persistent storage is kind of the point of using a computer instead of an abacus.
- colordrops 3y agoThere's been plenty of comments describing the difference between those tools and Nix, and various descriptions and docs are a single search away, so the snide comment comes off as ignorant. Most of us who use Nix came from one of those tools. I personally went from bash scripts --> Ansible --> Nix. Nix is lightyears ahead of Ansible. Since I'm familiar with these two, I'll tell you what's wrong with them: * They are imperative instead of declarative, so you have a ton of extra cognitive load figuring out the order of actions. I have thousands of lines of Nix config, change one file and it's not gonna break because something in another file was installed in the wrong order. * They are not suited for managing the entire OS, but rather a layer on top of an existing OS. NixOS manages everything from the bottom up, so there are no loose ends to break you. * They are not truly idempotent. You have to be very disciplined to keep them that way, including Ansible, despite their claims. My ansible deployments broke constantly * They don't have rollback capability. If you mess up on nix, a single command or keystroke on boot will bring you back to the last working deployment. * Their DSLs are not powerful enough of an abstraction. Nix is a fully fleshed out language so you don't have to write a bunch of boilerplate like Bash or need some special module like Ansible to make something happen. * Git support is first class. You can compose your installation from several git repos, so say you want the cutting edge version of a package, you can install the one directly from the maintainer's repo instead of the one in the nixpkgs repo * Speaking of which, Nix has more packages than any other distro. Key word here, DISTRO. Bash and Ansible aren't distros, and there is no central repo where anything you'd ever want to deploy is available and standardized and denormalized. And a Nix deployment has persistent and writable storage, not sure where you get the idea that it doesn't.
- xorcist 3y agoIgnorant, yes, but in no way snide. Each and every point listed here could have be taken verbatim from a ten year old blog post why Puppet, or later Ansible, is the new great thing. Being declarative and idempotent is the basic design idea of these tools. Managing every layer of infrastructure and the entire OS stack is also exactly what they aim for, and ironically also what many people regularly quote as why they haven't taken off more. Git support, and module versioning, is also completely on point. What is it that Nix does differently, and why? Is it a fundamentally different type of tool, such as Puppet is from plain Ruby scripts, or is it a better screwdriver? That Nix is a distribution in itself is an important difference. But how does that affect the use case? I realize the question have been asked before, but that's because not many attempts are ever made to explain where it sits in the problem space. It is not written for anyone who has experience with configuration management and infrastructure as code tooling, but instead for passive observers with the intention of bootstrapping the next hype cycle?
- bryanlarsen 3y agoAFAICT, you can get much of the benefit in a polished package without the pain by using Fedora Silverblue/Kinoite/Sericea for the OS and then creating dev sandboxes using either Fedora's toolbox or by harnessing the incredible Nix ecosystem using JetPack's devbox. I haven't tried that combination. I'm currently using NixOS and loving part of it, but am bleeding on the sharp edges.
- speed_spread 3y agoI'm currently using Fedora Kinoite with a few toolboxes (one for Rust, one for Node, etc). While not as fancy as a full Nix setup, it's an incredibly robust system that's modern and easy to maintain. A+ would recommend.
- bketelsen 3y agoWe built Bluefin - https://ublue.it https://ublue.it for just this case. A custom version of Silverblue, primed for Nix with Devbox + Fleek global profiles.
- 0zemp3c 3y agonixos for the REALLY impatient: its a giant pile of symlinks
- outofpaper 3y agoWell at least it's not a pile of hardlinks like apple's time machine. Actually that might be an interesting option for an OS... constant versioning.
- aidenn0 3y agoFWIW, you can repack the nix-store to be a pile of hardlinks...
- tormeh 3y agoIsn’t it mostly environment variables?
- kaba0 3y agoArguably the most important part of Nix is the fixed hashed output of everything, and these fixed /nix/store/hash-lib entries being used for dynamic linking.
- JamesLeonis 3y ago> There was a time when the idea of spending an afternoon typing cryptsetup incantations into a terminal would have been appealing. Oddly enough, I use NixOS as a network-disabled USB live image for handling my Yubikey, SSH, and GNUPG setup. I'm bashing cryptsetup all the time!
- nektro 3y agogreat writeup
- kertoip_1 3y agoThe fact that such articles appear shows an untold problem of NixOS which is: complexity. I've been a programmer and Linux user for many years, I know a lot of terminology behind it and I think it's a lot less of a problem for me to read technical documentation than for the average user. When I heard about NixOS I thought: "how awesome, it solves some of the problems that I have". But then I started to read official docs and dig into all of it and got quickly discouraged. It might solve "some of my problems" but at a time cost that I just couldn't afford. Well, maybe it's just not for me...
- zetalyrae 3y agoI thought the same thing for a long time. The reality is that I knew nothing about NixOS other than the sales pitch the day I installed it: nothing about the language, nothing about flakes or derivations or whatever. By the afternoon I had most of my setup replicated. By the next day I had both desktop and laptop running identical configurations.
- erikw 3y agoI’ll echo this sentiment. While it may take a while to figure out how to do something initially, the great thing about NixOS is that you only have to figure out how to do it exactly once. As far as my main desktop OS, I figured out a config that I liked several years ago, and haven’t really tweaked much since then. I ran the rolling release for a while, but I’ve moved back to the stable release, which is… well, stable.
- nyanpasu64 3y agoWhen I got my MacBook I thought "hey it would be neat to install gcc and friends using Nix". I struggled through outdated documentation to add packages, mixed up editing the files and `nix-env --install`, struggled with the `nix search` command requiring flakes or something, and never did figure out how to even update my package versions. Earlier I also tried installing NixOS and never actually got any use out of the disk at all.
- rgoulter 3y agoAnalogously, compare Emacs with VSCode. It's much easier for someone to be productive with VSCode without having to go out of their way to learn much. Whereas, Emacs' requires much more effort to learn, even just to get started; but is much more extensible than VSCode is. For the user who doesn't want to spend much time learning, surely VSCode is better. For the user who wants to get the most out of their editor, Emacs is a reasonable choice. I think Nix is comparable. Much of the time, Nix is quite straightforward to use. But, when you do run into something that's hard, Nix can be very difficult to work with. Maybe there'll be a tool that's to Nix/NixOS what VSCode is to Emacs; where you get the benefits of a declarative config.
- bionhoward 3y agoRandom question, and yes, I’ll google it and ask GPT-4 or Bing (lol) but does anyone here know if it would be possible to run NixOS within WSL2 on a Windows 11 machine without having to dual boot and stuff? That would be incredibly useful for dev work. Right now I’m using Ubuntu, and it’s awesome, with the obvious caveats, but I am Nix-curious for quite a while and would love to give it a spin in that way if it were reasonably doable. Especially to help friends who are less technical easily install all of the things, it could be a game changer. Edit: https://github.com/nix-community/NixOS-WSL https://github.com/nix-community/NixOS-WSL https://news.ycombinator.com/item?id=32173111 https://news.ycombinator.com/item?id=32173111
- TheFreim 3y agoI have not used it but this might be what you are looking for: https://github.com/nix-community/NixOS-WSL https://github.com/nix-community/NixOS-WSL You could also install the nix package manager on Ubuntu.
- pxc 3y agoThere are some quirks, and WSL2 is buggy enough that I would advise advanced Linux users to prefer a bare metal install or a normal VM if those will work at all. That said, I've used the linked NixOS image under WSL every day at work for about a year, and I've been very glad to have it. Standalone Nix also works well under WSL2. I semi-regularly use it that way as well, on Ubuntu and openSUSE, for some testing at work.
- deleted 3y ago[deleted]
- al1r4d 3y agogreat *not bot btw
- xedrac 3y ago> I don’t use distros that lack a graphical installer (running fdisk is frankly beneath my dignity) Ironically, I couldn't get the 22.11 graphical installer to work. I had to drop down to an Arch style install (which was fine). My biggest complaint with NixOS is the pain of trying to run things that weren't built in nix (like Minecraft, or some other binary-only tool). I end up creating a podman image to run some of these things. I'm sure I could also create a derivation for them, but haven't bothered running down that rabbit hole yet. If you're a programmer, Nix is awesome. But I don't think it's for the masses.
- jokethrowaway 3y agoThere was a derivation for tlauncher but it was removed. You can look into the nixpkgs repo and copy it in your system. Writing your own derivation is incredibly straightforward and there are tons of useful helpers
- kaba0 3y agosteam-run usually works for random binaries. But there are also nix-alien and similar tools if needed.
- tripdout 3y agoMinecraft works great on Nix, I've had no problems with just installing it like any other package.