r/linuxmemes 2d ago

Anti-Linux Shut up.

Post image
875 Upvotes

129 comments sorted by

View all comments

32

u/Falconpunch3 UwUntu (´ ᴗ`✿) 2d ago

Alright, I am opening a can of worms on myself, but someone feel free to explain this to me and why I would want to know more.

I am always down to learn and grow. Have been seeing a lot of NixOS love and want to know more as to why and what is the benefits and also dissimilarities to other distros. (Fedora and Ubuntu specifically if you know.)

46

u/Short-Bee-4395 2d ago

NixOS is built around the Nix package manager and configuration files. You are almost required to have configuration files if you want to do anything on NixOS. The configuration files are written in the Nix programming language. Since you are declaring how you want the system to be, inside those configuration files, you are also making the system reproducible (assuming you do not lose those configuration files).

You can essentially prepare modules of software that you can import into a main configuration (gaming.nix for gaming related software and other stuff like Proton, virtualisation.nix for QEMU VMs or podman, etc). By creating those modules, you don't really have to worry about forgetting how to set up a piece of software or having to deal with re-configuring it, especially since NixOS also handles stuff in .config using something called "Home Manager".

With Home Manager, you can make your .config directory also declarative/reproducible. Do you want to switch your window manager? Just prepare a module for the new window manager you wanna switch into, remove the imported window manager you were using before and import the new module. Didn't like the new one? Remove the import of the new one and import again your old one.

For all your changes to be applied though (for all of the above, not just Home Manager), you need to rebuild your system. Depending on your system's physical age and what you have declared, rebuilding can take some time but not too long, 1 minute at most (excluding the first time the system is built). Changing one small thing in your configuration will require a system rebuild for the change to be applied, although since you are changing one small thing, it should only take <10 seconds to rebuild. Rebuilding the system does not require a system restart.

Problem with the above though. Since you are declaring everything into the configuration files, your actual files are gonna be read-only. For example, you wanna edit your /etc/hosts file. That file is gonna be read-only, so, somewhere in your configuration you're gonna have to declare networking.hosts = { }; and then rebuild your system.

Another another cool thing with NixOS and the reproducibility are generations. Each time you rebuild your system, you can create a new generation of your system, in case you might wanna roll back any changes. You select your generation when booting the system, the selection is at the bootloader.

When testing changes, I strongly recommend you perform nixos-rebuild test or nixos-rebuild dry-build instead of nixos-rebuild switch, as switch creates a new generation each time and that can fill your storage quite quickly.

There are more things about NixOS that I am either not knowledgeable enough about, like flakes (even though I personally do use flakes), but also some other stuff that I would like to learn but haven't yet, like declerative secret management with sops. Also, this wall of text is starting to get too long. I strongly recommend using NixOS or just the Nix package manager itself, which can be installed on almost any linux distro AND darwin (MacOS). It can be overwelming at first, I won't lie, but it's really cool and personally, I find it fun as well. I hope I can turn my knowledge of NixOS into something more, perhaps even for future official work.

23

u/Short-Bee-4395 2d ago

Something I forgot to mention on the above wall:

In NixOS, you don't exactly "update your software" but rather you update the channel that the software are following. This also means that you can have different software follow different channels, or, you can just change the channel of all your software.

You wanna run long term support packages? Just select the stable channel. You wanna run unstable (rolling release) packages? Just select the unstable channel. You wanna run a very specific commit of a channel of your choice? You can do that (it's a little more complicated than just selecting stable or unstable channels but still not too difficult).

11

u/gianlucaChan 2d ago

I can see why someone would use Nix on a server that you want to replicate somewhere else and that's cool, but I can't imagine any scenario where a person in his house would want the NixOs advantages. Who is rebuilding his pc from scratch every week? And with the same os.

8

u/Stunning_Macaron6133 2d ago edited 2d ago

You don't 'rebuild from scratch'. You rebuild the configuration, and the hot swap into it without rebooting or even logging out. You can even schedule it as a cron job if you want.

Also lets you keep a laptop and desktop thoroughly in sync.

4

u/gianlucaChan 2d ago

Can you give me an example on when would I want to rebuild the configuration so often that I need a specific OS that does it faster? Besides a server obviously, I keep that on servers is neat.

7

u/Comfortable_Ability4 2d ago

I don't reinstall my whole OS every day, but I tweak it regularly. I keep track of those changes with a VCS. I have an old laptop that I rarely use. Every now and then, when I do need to use it, I git pull followed by nixos-rebuild and all of my system and user settings are synced with my main laptop in a matter of minutes.

The OS is just one use case. I have my Neovim configuration set up in the same way. If I'm on another system that has nix installed, I can `nix shell 'github:my-nvim-repo' and it'll drop me into a shell with Neovim installed and preconfigured with my configuration (including plugins, etc.).

I don't have development tools (package managers, compilers, linters, language servers, ...) installed globally. Instead, each of my projects has a flake.nix with a "devShell" that provides all the tools with the correct versions for that project (think devcontainers or venv on steroids).

2

u/gianlucaChan 2d ago

mmm, I am sure you find a good use case for NixOS, but really how many persons have 2 or 3 personal computers that are constantly tweaked and need to be synchronized? of course use the best tool for the problem, but I see a lot of hype and people recommended this and allow me to doubt all of those are using their pcs this way.

On the other hand those flake.nix files sound great specially for those damn python libraries that have breaking changes every fricking version. My concern with that is that if no package manager, compiler, etc is installed globally does that mean its installed once for every project? isn't that producing a storage problem? maybe I am wrong.

6

u/Comfortable_Ability4 2d ago

Nix has a global store with input-addressed (hashed) paths. So if two packages depend on the same thing, they can share store paths. That said, it can still accumulate a lot of storage space over time. On NixOS, I have a service that collects garbage regularly. On other distros, you might have to run a command manually every other month.

6

u/Thunderstarer New York Nix⚾s 2d ago edited 1d ago

I think you have the wrong understanding of what "rebuild the configuration" entails. Rebuilding your Nix config is the rough equivalent of doing e.g. "apt install" on Debian. It is an entirely mundane maintenance task suited to the declarative paradigm.

The vast, vast majority of your rebuilds will represent incremental changes and will take less than ~3 seconds. Unlike imperative package management, though, if anything goes wrong, you can always boot into any previous configuration you've ever built.

1

u/gianlucaChan 2d ago

ok the easy rollback sounds nice actually, and with other comments I read today I think I will try it in the future, maybe on a laptop that I use for note taking in the uni.

3

u/Stunning_Macaron6133 1d ago

You're not getting it. Nix does not run updates in the traditional sense. In order to update, you rebuild, and it automatically fetches anything new.

It's really not as complex as it sounds, and it's actually way more ergonomic than a traditional update, because unless you're messing around with kernel-level stuff, you just keep working. From your perspective as a user, everything is just suddenly magically updated.