Hi everyone, someone can explain, in simple words, why considering to switch on NixOs over other distro? And the use case? I think would help a lot of people (including me) to understand it better :D

  • Past Pollution
    link
    211 year ago

    I’m not remotely anything like an expert, and I don’t use NixOS (yet) myself, but I’ve been heavily researching it and I’ll try to explain it to you like I wish someone had explained it to me.

    First, I’d like to point out that most Linux distros are more or less the same. The main differences between most distros are what kind of package manager it uses, how it handles software updates (delaying and testing them like Debian vs releasing them quickly like Arch for example), how many packages they have in their repositories, and what software, configurations, and themes they ship with. There’s a few different ones, like the new immutable distros (like Fedora Silverblue), or something like Gentoo where you compile everything from source code instead of downloading precompiled packages, but it doesn’t get much different than that.

    NixOS is the first Linux distro I’ve seen that radically changes the formula.

    The biggest thing is, everything is installed and configured “declaratively”. In a normal distro if you want to install Firefox, you type “sudo apt install firefox” and it puts Firefox on your computer. On NixOS, you edit a config file for your entire system and add Firefox to a list of packages you want installed on your system. Then, you run a command, and Nix adds it. This is nice because it gives you an easy way to keep track of exactly what’s on your system. If you want to remove something? Delete a line from your config and run it again.

    This also works for other things. Configuration files also get set this way. On Arch, I had to edit a lot of files in /etc to get some virtual machines working properly. When I reinstalled one time, I had to figure out what I changed before and relearn everything to redo those changes. On NixOS, you tell your system what you want changed in that config and it does it all for you, exactly the same way every time. You can even do things like installing software from source code with it if you want a package Nix doesn’t have. You can have it automatically download the source code, and follow instructions to compile it and set it up.

    There’s a lot more though.

    When you run that command to install/uninstall/configure everything in your system’s config file, it doesn’t just take your system as it is and change it. If you do that there’s a chance something got tweaked by you or some piece of software you’re running. That could screw the process up. So instead, Nix just nukes and reinstalls your entire filesystem from scratch, doing it exactly how you ask in the config file. That way, you know it’s exactly how you want it, nothing is different. (And in case you’re concerned like I was, I think it does this really fast somehow. And it also doesn’t touch your Home folder and any of your personal files)

    This has some other bonuses too. It makes your system really hard to break. Since you’re installing your filesystem from scratch every time, it (I think) makes the entire thing unmodifiable. You can’t make changes to it directly. You don’t have to worry about a bad package or a virus breaking something. And yet you can still tweak it to your heart’s content, you just do it from that config file and it sets everything how you ask it to.

    Plus, let’s say you install updates, and a package has a bug that breaks everything and your entire system isn’t even starting. You’re safe, because NixOS saves backups of your filesystem. All you have to do is pick an older one at boot time and it’ll take you to that one instead of the newer, broken version, and then you can fix the problem/broken package and go on with your day. (I think it does eventually start using a bit of disk space to have multiple copies. But you can go back and delete older copies.) Alternatively, just in case that fails for some reason, you still have your config file. If you save backups of that, or use something like Git to save every version of it to Github, all you have to do is run that file again and it’ll install your system exactly as it was before something broke.

    The last big thing is reproduce-ability and package dependencies.

    First, packages. A big problem with software development, and making all the packages for a Linux distro, is dependencies and what people refer to as “dependency hell”. Linux is cool because you can use one dependency for multiple packages. Package Bob can say “hey I need package Joe to run”, and package Fred can say the same thing. And you don’t need two copies of Joe, they can just share Joe. Unfortunately, occasionally you have a problem where Bob is designed to use version 1 of Joe, and Fred is designed to use version 2, and usually it’s hard to install both at the same time. The best you can do is make two packages of Joe for your distro, let’s say “joe-v1” and “joe-v2”, and tell the people that make Bob and Fred to make their packages say which Joe package they need. It gets complicated and messy, and is a big reason why things break on other distros.

    This is also a problem with being a developer. If you make a script that runs Python 6, and then your computer updates to Python 7, your script might suddenly not working. And you better hope your distro has a “python-6” package that you now have to tell your script to use. And hopefully it’s not even more specific, like needing Python 6.13.7 when the “python-6” package is actually Python 6.14.2 and you can’t get the very specific version you need.

    NixOS fixes this by letting you use specific, exact versions of a package, and have multiple of them at once, and have every package say exactly which one it needs. I don’t know if you’re familiar with checksums/hashes, but basically it makes a hash for every package. If you change anything in that package (the version, how it’s installed, build options, config files, anything), it’ll have a different hash. And if another package only works with a very exact version of a dependency package, it can say which one it needs with the hash, and it’ll just work because it’s set up exactly right.

    And finally, because of all of this other stuff, your system is extremely reproducible. If your system breaks and you want to reinstall, throw your config file in and regenerate and it’ll be 100% identical to how it was. Throw it onto your second computer, give it out to people online, you name it. They’ll get the same thing. Do you run servers, and want to set up 30 to be just like each other? Normally you’d have to do that manually and hope you don’t mess something up, or learn a tool like Ansible. With Nix, just make a config file for it, throw it on all 30, and they’ll be the same. Or what if you’re a software developer, and you need to get a coworker to try what you made on their computer? Just give them the config, they can set up an identical test system and test it, tweak it, you name it, and you know it’ll run exactly the same between both computers.

    I think there are some drawbacks to Nix. The biggest one is the learning curve. The configuration files are all written in a (simple but unique) programming language, also called the Nix langauge. You basically have to learn it, and the basics of Nix in general, to use NixOS and do all the first time setup. I’ve heard people say that a Linux user learning NixOS is like a Windows user learning Linux. It’s different, it’s a bit. Plus, the documentation seems like it’s in a rough spot right now. Multiple places that have documentation, none of them are totally complete, some are outdated, and they’re all a bit confusing. And lastly, it seems like because of how the setup is done, installing and configuring some things will be different and potentially a lot harder than on other distros.

    NixOS is probably overkill for what a lot of desktop users actually need. Awesome features that if you have them you probably won’t ever want to live without, but a lot of things that are aimed at software developers and sysadmins, and with the learning curve it might not be worth it. If you run any normal distro and never need to reinstall your distro ever, you’d basically never need the features of NixOS.

    But if you get past the learning curve, NixOS seems to be the most powerful, flexible, unbreakable distro in existence at the moment. At least it is of the ones I know about.

    Sorry for the lengthy reply! And again, I’m absolutely not an expert. It’s been almost my sole obsession the last month or two and I’ve been trying to understand everything as well as I can, but someone with real experience will probably find things I said that are wrong. But I wanted to explain it in a way that makes sense to pre-learning-about-Nix me from a couple weeks ago, because everything I’ve seen from longtime NixOS users seems to be full of confusing jargon, and hopefully it helps you too!