this post was submitted on 03 Jul 2023
30 points (96.9% liked)

Linux

48413 readers
1305 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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

top 22 comments
sorted by: hot top controversial new old
[–] chayleaf@lemmy.ml 20 points 1 year ago* (last edited 1 year ago) (3 children)

You know why reinstalling Linux is annoying? Because you have to remember (or write down) every piece of config you ever changed. Dark mode in KDE? Change it in settings. Some systemd unit tweak? Change it in /etc/systemd. Want to run some commands at boot? Use systemd (see above), or write an initrd hook (distro-specific). Need a specific version of an app? Need some files in /opt? Need certain packages installed? You better remember to do that!

In NixOS, you "reinstall" your OS every time you change a single setting, because reinstalling NixOS isn't scary at all - everything that needs to be changed is configured in your configuration - just make sure /home and /var/lib are saved (and perhaps some other dirs, I have root on tmpfs and bind mount all persistent files I need to ensure I know what needs to be preserved on clean reinstall and what doesn't).

Want to move it to a different PC? No problem, copy the files in /home and /var/lib and simply install NixOS using the configuration you already have on the new PC. Want to create a boot option with slightly different kernel or kernel options, or maybe even another DE? No problem, specializations got you covered.

And of course, this also means it's easy to share configurations for specific use cases. Want to run on some specific hardware that doesn't work out of the box? Perhaps nixos-hardware got you covered. Want a certain program set up? Maybe there's already a NixOS option for system-level config or a home-manager option for user-level config, worst case you can write it yourself and share for everyone else in the community using flakes, and maybe open a PR to nixpkgs/home-manager. Want to share configuration between systems? That's easy, put them in the same flake and write a common module shared between all of your systems.

Basically, if you're fine with whatever comes out of the box in any Linux distro, you don't need NixOS, but if you need configuration, if you run servers, it is a lifesaver. I switched from Arch, no regrets. I run my personal laptop, my server, which I effortlessly migrated from Oracle Cloud when they quit Russia, and my router on it, here's my NixOS/home-manager config.

The only downsides are the learning curve and the fact that you can't "just" run programs that expect a FHS layout. You can do it with workarounds like steam-run or appimage-run anyway, but overall be prepared to learn to package stuff for NixOS. Also if you have no experience with functional programming, the Nix language may be hard to understand at first.

[–] rah 2 points 1 year ago (3 children)

Want to move it to a different PC? No problem, copy the files in /home and /var/lib and simply install NixOS using the configuration you already have on the new PC.

How/can one separate some changes from others? I don't want my server to be identical to my laptop. How does one install a package which won't be installed on a different machine at a later time?

[–] chayleaf@lemmy.ml 2 points 1 year ago* (last edited 1 year ago)

Simply use two different configurations? The more interesting question is how to share stuff between configs.

Each piece of config is a NixOS module. You can include some NixOS modules in one system's config, but not the other.

[–] dai@lemmy.world 2 points 1 year ago

You are able to have different configurations spun up from the one file by using machine names. My main machine is pretty barebones with minimal applications, but my laptop is even more minimal.

I can't move away from Proxmox right now for my servers but the option is there if I want to spin up some containers using similar Configs and such.

[–] zalphoid@lemmy.studio 1 points 1 year ago

I split certain things, for example desktop related tools/applications are in one configuration and thus my headless systems do not import that config into their base config.

[–] pinchcramp@lemmy.dbzer0.com 1 points 1 year ago

This is probably the most comprehensive, yet easily understandable explanation of NixOS I've ever read.

Thank you very much

[–] socsa@lemmy.ml 0 points 1 year ago (1 children)

So it's basically a more formalized API version of preinstall and postinstall scripts.

[–] chayleaf@lemmy.ml 1 points 1 year ago

kinda, preinstall/postinstall scripts expect to run on a clean system, while NixOS can be changed without a full system wipe, you don't need to redownload/rebuild anything you've already downloaded/built.

[–] past_pollution@lemmy.world 17 points 1 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!

[–] taanegl@lemmy.ml 5 points 1 year ago* (last edited 1 year ago) (2 children)

Do not turn to the Lovecraftian package manager unless you dare. It consumes all, it is all. Your flesh and mind will be ripped in twine across dimensions... if you are a package.

If you're binary your head will be ripped open and it's contents modified to fit a new reality.

There is no package, nor source, nor binary that shall be exempt.

All shall be consumed, digested and brought to a new reality.

It will kill the old gods, as there will be only one package manager.

It will consume you.

[–] flashgnash@lemm.ee 1 points 1 year ago

I'd say it's pretty cool. Have only been driven partially insane by cthulu

[–] 2xsaiko@discuss.tchncs.de 1 points 1 year ago

Can confirm. My mind has been altered by the mere touching of a keyboard that has NixOS living behind it. My soul has been replaced by the concept of a derivation. The cables in my computer and my vęins have swapped places. The f̸l̴e̷s̶h̵ is weak. I have long since lost control of the Flakes that now grow out of my skin. When you install NixOS, you and your computer are henceforth marked by the Great Old Ones. You will no longer be able to use a normal Linux distribution. The mere thought of using a normal Linux distribution will cause your skin to feel like it is being burned alive.

A̸̦̙̎̅̊ṇ̸̯̽̾d̵̨̠͈͐ ̵̧̗͊̇I̸̧̩̜͊̓͂ ̵̞̱͎͗͂w̵͔̓o̷͍͂̈́u̸̥̯͋l̵̠̞̳̅͠d̴̹͛̃͝n̷̛̯̮̭͌͝'̵̜͉͕̚͘͝t̷̡̜̄ ̸͈̥̄̄h̷̺͛͛̍à̴̢̐v̷̪͍̾e̴̢̯̦̒͌̿ ̶̮̽̀̏ḭ̴̝̠̋̾t̶̬̩̾͒ ̵̱̼̥͆͑a̷͚̒ǹ̸̤̊y̶̤̎̾̈́ ̴̱̎ò̶̦̦̂̚t̵͚͙̽̓͜h̵̖̤̍̈́ȇ̶̳͇̈ṟ̴̇ ̴͔̮̱̏̔w̴̺̖̋̌a̸̞̹̤͗y̸̖̣͠.̵̯̾͘

[–] unknowing8343@discuss.tchncs.de 2 points 1 year ago* (last edited 1 year ago)

If you are worried that your computer will screw you with a bad update tomorrow, and the possibility of setting up your system like it's a wishlist.

[–] doomkernel@sopuli.xyz 2 points 1 year ago
  • Rock solid
  • Native rollbacks if you break you system
  • The ability to list every software you want to use/try
  • Every little tweak you do to a program can be written in a file
  • You NixOS config will get you the same OS everywhere
[–] Nuuskis@sopuli.xyz 1 points 1 year ago

Cloud systems invented this concept called 'declarative environments' basically you describe the software in a container or os and the container orchestrator builds it for you. The same every time, you just give it a recipe.

Nixos is that for desktops.

It takes away a lot of the bullshit, experimentation and breaking of a classic os.

That being said, I always considered that the fun part, so ymmv.

It's like docker for server applications, it takes care of everything for you behind the scenes and just works (ish).

[–] Lamy@lemmy.fmhy.ml 1 points 1 year ago

Imho not really a worth while venture. Easier solutions exist for most use cases.

[–] t0m5k1 1 points 1 year ago

It's use case is to make it easy for a server admin to be able to reproduce a given server in an exact way.

You then take the config to a lab, upgrade and/or make a change. Then redeploy the new build in a very controlled manner effecting minimal downtime.

When used on a home desktop the config has the potential to become a chore in itself to administer which is more suited to those who prefer a minimal install.

If you like to tinker and try that latest fad app nixos is not going to be nice for you.

[–] fratermus@lemmy.sdf.org -3 points 1 year ago (1 children)

why considering to switch on NixOs over other distro?

You like linux but really miss the Windows registry :-P

[–] zalphoid@lemmy.studio 1 points 1 year ago (1 children)

Please elaborate because if you actually understood the Windows registry you would realize they aren’t the same 😂 maybe you should read some actual code

[–] fratermus@lemmy.sdf.org 0 points 1 year ago

It was a joke, hence the sticky-out-tongue emoticon

[–] 20gramsWrench@lemmy.dbzer0.com -3 points 1 year ago

NixOS will make you cofee every morning, fix your car, make your waifu real and establish a long lasting commune system in your country of residence.

load more comments
view more: next ›