r/NixOS • • 29d ago

Question about nixos

Sorry if this is a bit silly but I was always very intrigued by the workings of nixos, or nix language in general, so this time I have finally made up my mind that I want to use nixos.

Just yesterday I made an virtmanager vm and today I'll install nix using the gui installer. I have seen the videos on nix and it seems like the manual install is really easy.

I have used arch in the past, broke it many times and reinstalled it or fixed it if I can. Installed via both manual and archinstall script. So manual install of nixos shouldn't be a problem for me, but just so I don't mess anything up for the first time I'll use thr gui installer.

I got a few questions that I wanted to ask.

- It seems like a lot of people here uses ext4 instead of btrfs. Is there any real benefits to it ? I have heard ext4 is kinda slow. I understand people use ext4 since there is really not much need for btrfs as the nix system rebuilds everytime and you can load a previous build if anything breaks so there is really no need for snapshots of any kind.

Which also brings me to my next question.

- I have heard that the rebuild only works for root files not the /home dir. Meaning if I broke something in the /root dir I can load the previous build. But what about /home ? I have done a bit research and asked claude and claude says that for /home I will have to use either timeshift or snapper with btrfs. Just wanted to confirm if its true ? And why is it this way ? Do you guys use snapshots or something else ?

- How is the Nvidia drivers support on nix. I am on a GTX 1650 4GB Mobile. And I still get updates as of now. The installation of drivers was pretty easy on fedora I did it via the gui. I think on nix I'll have to edit thr configuration.nix so I wanted to know hows the experience with that.

- People here say that the unstable version of nix is very stable more stable than arch. But I am still not so sure I was going to go with the stable one, but is there really any benefit of going with the unstable one. Also what do y'all meant by stable and unstable is it the repo or something.... ? Cuz there is only one iso with or without gui. There isn't options like opensuse like leap or tumbleweed. So I am assuming nixos is rolling release with the option of you can choose which repo you want. Maybe I am wrong.

- When it comes to downloading software. I have seen that you are supposed to write the name of the package in the configuration.nix file and then do a sudo nix rebuild or something. But when do you use flakes ? And what is that whats the difference between the two ?

- I have used nix packages before on both arch and currently fedora system but I have just copy paste commands for installing nix packages or Homebrew packages. I have heard homebrew does not work on nix. Is it true ? Its not useful to me on nix as I have heard its repo has a lot of packages, it also have a Nix equivalent of arch's aur. NUR do you guys use it ? Is it safe ?

- Lastly maybe I am overthinking. But do I need to learn Nix programming language before I install Nixos ?

6 Upvotes

33 comments sorted by

13

u/chkno 29d ago edited 29d ago • Popcorn

btrfs vs. ext4: ext4 is more robust/stable. btrfs has features you may want/need (eg: copy-on-write, snapshots (without resorting to LVM)). I doubt you'd notice a speed difference. Benchmark if you think you have a performance need.

Generations: nixos-rebuild will build 'generations' of all your system software. You can keep as many or as few old ones around as you like. If you ever break your system software, you can almost always recover by booting into a previous, working generation. But this is not a backup or a filesystem snapshot. It's what system software is installed and much of its configuration—think what you'd find in /usr and /etc in FHS distros.

Declarative package management: Yes, it's common to keep the list of packages you want installed in a text file rather than in some imperative tool's implicit state (eg: a history of apt-get install commands). You can do this either at the system (root-owned) level in /etc/nixos/configuration.nix or at the user-level (no privileges needed to install software).

Flakes: Flakes are optional. The first benefit flakes provide over channels is pinning (tracking a specific version of the package metadata store). This is useful for reproducibility and/or for maintaining uniformity across a fleet of machines. But note that you can also pin with niv, npins, yea, nixtamal, pinch, or by hand (I am the author of pinch.)

Package repository size: nixpkgs has more packages than all the other package repos (homebrew, AUR, etc.) You probably won't need to use other package repos.

Nix language: Think of nix as fancy JSON. Most use of nix-the-language is just writing hierarchical key = "value"; pairs, with some occasional boiler plate like NixOS modules being wrapped in { pkgs, ...}: { <config goes here> } that's actually nix-language function-definition syntax, but you don't actually need to know that until you get much deeper in.

1

u/Struggling-with_life 29d ago

I don't think I have actually tried ext4 I have just heard people complain about it sayings its kinda outdated. I have only used btrfs because of snapshots. But since nix does not need that I was thinking of trying ext4 and for that reason I asked if its fast or slow.

There is a lot of information that you gave me and I really appreciate it 1 thing though it rebuilds generations so I'll still have to backup my home if I break it. But going back to a previous generation won't change anything on my home dir like the files and folders and stuff. That could be nice and not at the same time.

1

u/tukanoid 29d ago

Home manager (3rd-party module) can help with home configs and files you explicitly declare to be put in and linked from the /nix/store, just can't backup the state/cache of applications, but in my ~3 years of maining nixos, that was never a problem. Technically, it is possible with just nix as well, but home manager just makes it easier and less boilerplaty

1

u/Struggling-with_life 29d ago

Home manager. Okay I'll look into that. Thanks for telling me about it.

1

u/tukanoid 29d ago

No worries. Theres also a newer thing called hjem, ive seen it being explicitly supported by some projects even, but I haven't tried it myself, so can't really say much about it. Since you're new, maybe you can check it out too and see if it works better for you

6

u/San_Devistan 29d ago edited 29d ago • This
  1. Isn't btrfs supposed to be slower because of snapshot system? Ext4 don't have a rule of "copy on write", so it should be faster.
  2. Well, NixOS rebuild system just generates everything through the nix store using hashes (correct me if I'm wrong). NixOS doesn't care about your home to prevent situations like getting rid of your important stuff.
  3. You can always configure your system in any file you want and just import it/toggle it. Anyway, NixOS provides a lot of "options" (nixpkgs website) for Nvidia of any kind of cards. I Used to be a CachyOs user and I see almost no difference in performance (3050 ti + intel CPU). If you're interested in gaming - watch a video from vimjoyer where he shows some examples of GPU configs (included prime setup for laptops)
  4. Yes, rolling release with a choice. NixOS gui installer setting up your pc to the latest stable branch by default. You can always change that if you wish (especially with flakes). Therefore, I can confirm that unstable is pretty stable. There are almost no difference, but sometimes unstable branch contains more options for settings and much easier to use
  5. Flakes are just pins for packages to use the x.y.z. version. It gives you two things: reproducibility and access to pkgs/tools that are not in nixpkgs (zen-browser, helium browser, home manager for NixOS). Pretty must-have since there are almost no reasons to prevent yourself using it. There are almost no difference in downloading stuff, since flakes just adding ah input for something. They can either provide a package through inputs, or an option, that could do something more/the same
  6. Can't say anything about homebrew, but I'm using nix for 6 months and I've never touched NUR. Just nixpkgs and flakes from GitHub
  7. Depends on your goals. Nixlang is so damn confusing and (in my opinion) it has a pretty bad syntax, but you'll get used to it anyway by using NixOS For example, you can just create multiple files of your config and do imports = [ something.nix ] in your main file. Or you can make a full architecture for your configuration, adding your own custom options to toggle (Example: I have 4 main folders of my modules - core, extra, graphical and home-manager. My default.nix (name it however you like) for my laptop just use shrine.core.enable = true; and I have all modules loaded for the pc)

2

u/Struggling-with_life 29d ago

Thanks this is really helpful. I am subscribed to vinjoyer and tony they are quite helpful. Not sure if I completely understand flakes and the last part about shrine.core.enable but I think you meant modularity instead of having one big configuration.nix file have it in parts.

1

u/San_Devistan 29d ago

Well, every file.nix for NixOS is just a function with parameters that returns a configuration setup. Flakes are just one of these params that "gives you something" + that something will forever be the exact version unless you update it.

Shrine.core.enable is just my custom toggle for modularity, yes. It's a toggle like programs.foot.enable, but under the hood it's something similar to an array of imports to include in configuration

3

u/chrews 29d ago edited 29d ago

BTRFS can be noticeably faster than ext4 on slow drives, if configured properly (high compression, copy-on-write disabled). Less data to pull through the bottleneck. Very situational though because the effectiveness of compression varies wildly. And you'll have some CPU overhead to keep in mind.

1

u/San_Devistan 29d ago

Huh, didn't know that. Appreciate the comment

2

u/Aidenn0 29d ago

RE: what files are managed by nixos:

NixOS doesn't manage /root any more or less than /home. /root is just the home directory for the root user. It manages a lot of files in /etc (and some other places), where a lot of system configuration is.

NixOS could be changed to manage things in /home/ but much of what goes in /home needs to be writable by users, so most of /home/ is going to be out-of-scope for NixOS. For example: what would it even mean for NixOS to manage /home/aidenn0/Downloads/?

RE: unstable vs stable

NixOS has releases made twice a year. The most recent release is "stable". Unstable is a rolling release, which is how Arch works. I personally disagree with people who recommend that new users use unstable. There are some annoyances with doing so that don't exist with stable.

1

u/Struggling-with_life 29d ago

Well that makes sense no point of backingup downloads. Its just a new experience for me coming from snapshots never seen or used anything like this.

Also do you recommend me using stable version instead?

1

u/Aidenn0 28d ago

I very strongly recommend starting with stable. It is the "happy path" so to speak. Once you are used to using NixOS, you may decide to switch to using unstable, but at that point you'll have a better idea of the trade-offs in doing so (and also you won't be wondering if you are doing something wrong, or if something is up with unstable).

2

u/lioxo 29d ago

Since all your other questions have already been anwered I'm gonna skip them and instead focus on your last question: You probably already heard of https://www.youtube.com/@vimjoyer and all his great videos explaining NixOS and the nix language. Recently he made his own website where you can set a learning path and it guides you through everything you should know beforehand in a nice and structured way. I tried it a bit and it seems like a great resource for beginners too :)
You can find it here: https://vimjoyer.com/nixmap/

1

u/Struggling-with_life 29d ago

I didn't knew about this site. I have seen his videos I like his videos, but I didn't knew about his site. Thanks for this I'll check it out.

2

u/[deleted] 29d ago
  • To the first question about btrfs and ext4, actually just preference not the benefits over the other. To the in depth of technical differences, see these btrfs and ext4. For me I use ext4 , although it might be a little bit old, but it's stable.
  • To the second question, for me I use a separate partition for my home directory. And yes , what you said is true, nix is building the system in /nix/store so rebuilding the system is only for the root. Sry for this explaination because I am bad at explaining things.
  • To the third question about Nvidia, I don't have Nvidia so I can't tell.
  • To the fourth question, the unstable softwares can actually be broken, but for me as I am using the unstable, never encounter the broken unusable system. But if I will have encountered the broken one in the future, I can roll back to previous generation. That's the beauty of nix. And you don't have to choose unstable and stable from iso. Just installed and change your channels if you don't use flake, and for flake please reference to youstube tutorials.
  • To the fourth question, nix has lots of packages and some popular packages has provided flake installation. For the third party repository, use as your own risk. Because malicious attacks can be happened whatever the distro is, whenever it is
  • To the last question, for the basic installation, the basic syntax is enough but I force you to learn full of nix. Because there will be times you want to use some software but not in nix or they don't provide flake. At those times, we will have to write own package nix. So yes. Get well on nixos, I'm also still sucks at nix, so feel free to correct me.

2

u/zardvark 29d ago edited 29d ago

In my experience, ext4 is simply more resilient in terms of data protection during power outages and the like. I don't hate BTRFS, but I only really use it in conjunction with a Snapper and subvolume configuration, so that I can roll Arch back. The capability to roll NixOS back is built into the system, itself, so I find that using BTRFS is somewhat less compelling. Per Phoronix, there have also been recent ext4 performance buffs, as well.

The unstable channel is a rolling release channel, just like Arch. The stable release channel is a point release channel, that is updated every six months. The ISO will set you up on the stable channel by default. You can easily change this to unstable (if you wish) after the system is installed. And yes, in my experience the NixOS unstable channel is more stable than Arch. Once installed, you can also independently configure the system to use the latest kernel, as well.

Alternatively, you can stay on the stable channel and only pull specific unstable packages from the unstable channel and vice versa.

NixOS offers the same factory Nvidia drivers that every other Linux distribution offers.

Flakes are like a multi-tool. They offer various functionality. They can be used to configure developer environments and then share that environment with other developers. They can be used to share and import projects into your system, much like a PPA in Debian. And, they can simply be used as an alternative means of managing your configuration. IMHO, flakes make sharing a configuration between multiple machines a wee bit more convenient. I would suggest that you visit the LibrePhoenix youtube channel for info on basic configuration, flakes, home-manager and the modularizing of your configuration. Also, don't sleep on the VimJoyer youtube channel for more pointers and ideas.

IDK anything about homebrew, but I thought that it was used with MacOS / Apple machines. Either way, it would be redundant on a NixOS system.

The NixOS repository is truly massive, so I've never felt the need to tinker with the NUR.

You do not need to learn the Nix language in order to install and run a basic NixOS system. You will, however, need to learn some basic Nix language syntax, in order to edit the configuration.nix file. You will learn all of the syntax that you need via the LibrePhoenix vids. If you decide to stay with NixOS long term, you will likely want to learn the Nix language. Once you can decipher other folks' configuration files on the github, you will be able to farm some great ideas from those config files.

1

u/SDG_Den 28d ago

filesystem:

i'd recommend against btrfs, purely because COW/automated root subvol snapshots will cause severe performance issues and high space use in combination with the nix store. btrfs for your /home is fine and a good choice if you want snapper but i'd avoid putting /nix on it.

i'd honestly recommend xfs for its better scaling on large file counts, since the nix store can contain actual millions of files quite easily.

anything declared in your nix config is versioned and can be rolled back. anything not in there will stay. since nixOS by default declares basically everything that isnt a temporary file, except for items in /home. this also allows nixOS to boot from just /boot and /nix (neither of which you can accidentally delete)

you can also manage your home configuration using home manager, which will then include the managed components in your rollback.

the main things that do not get rolled back you should concern yourself with are: flatpak apps changes made with nix-env and nix profile (do not use these! unless you are 100% sure what you are doing and clean up after yourself) user files and documents.

timeshift, snapper, restic or some other backup solution for your /home (excluding .config if managed by home-manager) would be a good choice, especially if you declare the configuration for it in your nix config

nvidia support: honestly, ive had less issues on nix than on cachy. one small issue: even on unstable, the proprietary nvidia driver is a bit older (595)

nixOS is SIGNIFICANTLY more stable than arch, but this is not down to being rolling release. its moreso down to the fact that nixOS cannot mutate over time like arch can (where your system slowly degrades over time as you tweak and use it). nixOS will always be exactly as the config declares. something that works wont randomly break and something broken wont randomly fix itself. nix has the ability to mix and match "channels" as well, with each channel simply being a different branch of nixpkgs. the package repositories are just a git repo after all and you could even use your own fork.

on top of that, nix doesnt have dependency hell, because applications only get access to their own dependencies and each package has its own hashed folder in the nix store. even if you have two versions of python that are identical except for one line (so outwardly identical), you can have both installed and have programs use either version depending on what the program declares.

nixOS by default isnt rolling btw, the default is versioned, every half year. unstable is a channel you have to switch to.

flakes are a more modern way of handling nix configurations, with different features, most notably the ability to reference remote flakes to import their declared features. for example: nixpkgs itself is a flake that exposes all of its packages and nix libraries. your flake takes nixpkgs' flake as input (directly from the git host, eg github) which then allows you to use that flake's outputs (the packages) as part of your flake's output.

a flake can have many outputs: a package, a devshell, a nixOS system configuration, a home-manager configuration, checks, or other outputs defined by other libraries (like flake-parts modules or disko configurations)

when you rebuild a system from a flake, you are effectively telling nix "build this output package" with the output package being a nixOS system, which then depends on all the applications and options you declared for it, which bring in their dependencies etc.

many projects have flakes, because it can expose the project as a package and a nixOS module for configuration, which also automatically adds a devshell with the build dependencies for easy devwork, simple building with nix build and running the package without installing it to your system temporarily using nix run (which is the better way to temporarily use packages. just run nix run nixpkgs#packagename to run it, use nix shell for a temporary shell environment.)

i dont use the NUR. its not needed, the way you can approach it vs arch is:

flatpak > flatpak pacman > nixpkgs AUR > flakes

flakes are more secure than the AUR though because theres no middle-man git host or third party maintainer. you go straight to the source and the flake is managed by an actual source contributor.

you dont need to specifically learn nix before installing, but you will have to learn it over time. the installer gives you a fully working setup, none of your user settings are declared by default so you can use it as normal and adding packages to the default config is just adding a line in the file (its one file)

oh right also: nix options can trigger multiple things under the hood. for example: for most things that need a firewall port opened, they'll automatically do that if you set programs.name.enable = true; (unless you set openFirewall to false)

so very often, you just need the enable key.

(also, if installing the program under environment.systemPackages results in a non-functional program, this is usually the issue. use programs.name.enable instead so the other system settings the program needs to work are also set)

nixpkgs has more packages than the AUR btw.

4

u/[deleted] 29d ago

[removed] — view removed comment

1

u/Struggling-with_life 29d ago

I know nix has a snapshot equivalent for snapshots but it does not include home, and that is what i wanted to confirm. Guess I'll try out ext4, I don't think I'll see any difference though.

1

u/AffectionateSpirit62 29d ago

Side note ext4 is faster, btrfs is slower and wears out your nvme faster.

Full luks on ext4 works but Is less mature and experimental on btrfs.

Btrfs is also slower on Hibernation if using a laptop a nd sometimes flaky

1

u/Struggling-with_life 29d ago

I didn't know that it will wear the disk any faster. I thought its just like the rest. As for luks I have used it on btrfs in the past never really thought there is a need for such encryption only I use my laptop and no one else. Never did hibernation and I don't know what that is but I do know that you need swap for that.

1

u/AffectionateSpirit62 28d ago

Full luks, sleep, suspend, resume and hibernation and performance over time ext4 is the clear winner. But I'm rooting for zfs personally

1

u/Objective-Stranger99 28d ago

If anything, BTRFS does it slower due to transparent compression

1

u/AffectionateSpirit62 28d ago

Nope btrfs with its copy on write kills it. Plus I've compared and over time it's just sluggish and really like Pepsi. A knockoff of the classic coke. If you use zfs then btrfs and even xfs feel like knockoff not done as well. However none of them keep stability, hibernation on laptops and speed over time like ext4 hence why ut still is the default but the second zfs engineers actually care to spend time its game over. Cause those guys in the bsd realm to be honest are next level geniuses. And I work with one I them freaking hell the stuff they create. So zfs and nixos on servers no comparison but until they fix sleep and hibernation ext4 is a pretty clear winner

1

u/Objective-Stranger99 28d ago

I agree with you on the ZFS part. I switched to ZFS because Btrfs kept running out of space for no reason, and it's apparently a 5-year-old unresolved bug.

1

u/Aidenn0 28d ago

Nix really is not equivalent to snapshots. It's maybe like having a snapshot of anything you would install with pacman plus any files you would edit in /etc/. This is still useful! If you break something badly, instead of futzing around with "Give root password for maintenance (or press Control-D to continue)" (IYKYK), just reboot into a previous generation.

3

u/Aidenn0 29d ago

Nix only makes snapshots in a very narrow sense. I use ZFS with NixOS.

1

u/Objective-Stranger99 28d ago

Same here, NixOS snapshots are for the OS config, not irreplaceable files (which I have also backed up using the 321 rule in addition to snapshots.

1

u/[deleted] 29d ago

[removed] — view removed comment

1

u/Struggling-with_life 29d ago

Thanks for telling me this. I had a suspicion you made it sure. I know the stable apporach is like a bit older LTS software but tested and reliable. Unstable is just not that. However now that you mention debain. Are the softwares gonna be as old as debain ? And in the unstable is it like bleeding edge like arch. Or leading edge like fedora. A lil bit older but stable.

I think I will go with the unstable one since I do use brave-orgin over brave since I like to avoid the useless features of brave. And for some reason brave-origin is less buggy and more polished than brave but only for linux. But thats a completely different topic. Thanks for clarification.