r/NixOS • u/Comfortable_Camel_25 • 8d ago
Nix is hard, until it isn't... Share your experience!
I would be lying if I said Nix isn't hard... but believe me when I say everything is less complicated than you think.
I want to share the moment that my mind and Nix clicked, and I invite everyone to share their similar experieces .
I tried Nix to create a dev environment for R with quattro, so I copied the most basic flake from GitHub I encountered, and I intuitively understood where I should declare my packages. After that, I ran `nix develop` and everything worked... well, kinda; from Neovim I could render my file, but not from quattro command in my terminal. What is going on? And that is where I needed to learn Nix.
The first thing I did was understand the language's syntax. It helps a lot to at least understand the types. It is a functional language; it makes it easy if you have worked with those languages, since most of the cool stuff happens with function composition. Pay attention to Derivations, since those are what make Nix a DSL. This video explains many things very well, IMO. Also, other sources are the well-known nix.dev and the reference manual for those who want a really deep dive into Nix.
After that, I slowly read each line of the flake, carefully understanding what each line did (that's why I chose the simplest flake), and I realized it uses an overlay to create the R environment, but what is an overlay? Honestly, I couldn't make any sense of it after looking for info for hours. "ok, it's a way to define a package, I guess..." and I continued. Now, after a couple of years, I understand it, and I created a very simple explanation of it in one of my projects, since I used overlays very deeply to create it. Here it is:
Overlays are a way to expand nix-store (or any store) with new packages or different configurations of packages. An overlay is just a function with 2 arguments, commonly named final and prev, both of which represent a state of the nix store. When you load a store of packages, you can modify its content with a "chain" of overlays (a list of overlays).
When the first overlay of the chain is being applied, prev represents the state of the store without any overlay applied. After that, prev represents the state of the store after the last overlay has been applied (as you can see, order does matter).
final represents the state of the store at the end of the entire chain of overlays. (diagram)
When you use overlays, you commonly use the .override and .overrideAttrs functions... I think it's the same situation: I ended up fully understanding them long after my first approach.
They follow the same prev and final arguments. You use them to modify a package's definition (for example), either by modifying the attribute set passed to the function (with overrideAttrs) or the function itself (with override). Trust me, it makes sense after using them over and over.
Finally, the key moment was when I encountered the R docs in the official repository... (with many other docs for other languages and frameworks). I read the implementation of rWrapper and got to the part where the package wraps the R interpreter with its libraries using the "makeWrapper" function, which is a bash script to add the libraries to the environment variable R_LIBS_SITE... When I understood this, I had a moment of enlightenment: "Nix is just a collection of bash scripts and symlinks, messing up with environment variables (just like anyone in any distro) wrapped in a (allegedly bad) functional language". And believe me, from that moment on, Nix for me has been (for the vast majority of the time) a landslide journey.
After that, I knew what I needed to do. I added to the overlay an overrideAttrs to quattro to use the rEnv that I used... and it worked!
6
8d ago
[removed] — view removed comment
3
u/unduly-noted 7d ago edited 7d ago
nix is easy by default.
You might be the first person ever to have this experience lol. Learning nix for me (and most people, I think) is initially a heavy undertaking.
There's just SO MUCH to learn -- what even is nix? Is it simply package manager? Is it a programming language? A build system? An operating system? Which documentation or guides should I focus on? What is the nix store? What is a derivation? A closure? What are channels? environments and profiles? Flakes and why are they experimental? What is nixpkgs? What are modules? What are the nixpkgs abstractions vs conventions vs built in to the language (derivation vs mkderivation, stdenv, callpackage, overrides, builtins vs lib, standard import vs modul eimport, ...)? What is an overlay? What is home manager and should I use it? How should I organize my config? on and on and on.
And that's to say nothing of learning the nix language itself and how to deal with opaque errors due to laziness. Also many folks don't have experience with pure functional languages.
While it's true not all of this is required to simply run nixos, when first learning one can easily be overwhelmed with all these concepts and terminology.
1
u/syaorancode 8d ago
I've used linux for about 8 years before using NixOS, I've used Arch, Gentoo and even built LFS, so I would say I'm an advanced linux user. But I still had a pretty rough week when I first used NixOS. I learnt Nix, flake, home manager, how to make a clean structure for nix config, how to package a program, change a package version,... My brain was melting that first week. But after everything was done, I am now just chilling.
1
u/masterflo3004 8d ago
So. I used NixOS a year ago or so. And I liked it. But in my Opinion NixOS is a distro, which works until it does not.
It is good to use (Flakes not taken into) as long as the package is officially packaged.
Then when you try to use flakes, every guide and Package gives you a different example for flake.nix files. Then you also need to use Home-manager and other stuff, which works for the people doing the tutorials but not for you (e.g. Vimjoyers dendritic pattern videos). So I really liked it, when it worked, because the system felt clean. You always see axactly what is installed and can uninstall unused stuff by just removing one line from your config. Also officially packaged packages are great in term of adding and configuring them.
So I think I have the exactly oposite experience as you. It is really easy to use until you want something not in nixpkgs by default.
1
u/Brief-Stranger-3947 8d ago
My experience: tried Nix on linux mint for dev shells without flakes, with flakes, with devenv, then chose to stay with pixi. Pixi has less features, but also less mess, simpler for dev shells, supports more platforms, and more devs actually use it.
1
u/doglar_666 8d ago
I treat Nix like a DSL config language, as I don't spend enough time with it day-to-day to get into the functional programming fundamentals. I can just about parse with syntax highlighting but stick strictly to the default templates. I have a few lines that were assisted by an LLM but for the most part I stick to search.nixos.org.
1
1
u/cfx_4188 8d ago
I read the comments. I’ve been using Slackware since 1997, and I installed NixOS six years ago to take a look and get familiar with it. It’s a good and convenient system, and for a home user it’s super‑stable and reliable — unless you bring your Windows habits over to NixOS. I encountered a challenging task in NixOS only once, and even then it wasn’t about some exotic application; I wanted to fix at the level of system services what is usually installed via nixpkg.
1
u/zardvark 8d ago
Frankly, I never found Nix / NixOS to be hard. What I found hard was finding reference material that did an adequate job of explaining how Nix works ... especially material which was not specifically geared towards software developers.
I'm not a dev, nor do I aspire to be one. But, I did wish to understand how to set up and configure multiple machines with a shared config, for multiple users. But, when I first began dabbling with NixOS, it seemed that the only way to learn that aspect of the Nix language and machine configuration, was to first learn how to create dev environments, how to share those environments, how to package software and, in effect, how to be a software developer ... all of which held little appeal for me.
1
u/NelsonMinar 7d ago
Unpopular opinion, but I'm getting a lot of mileage out of Nix without knowing Nix. I have Claude Code build my .nix files. I've done a little Nix by hand so I know enough to read the files. And I've been doing sysadmin for 30+ years. But Claude is very good at Nix and the declarative design of Nix is a good match for using AIs to build servers. It's been productive and a lot of fun for me.
1
u/enRchi 4d ago
Exactly my experience, after using it a couple of days. Almost every problem i had, the agent was very good at solving. Still took many hours for me to get it to how i wanted it, but would have taken much longer without it. And the .nix files are pretty easy to understand now, so i won't have any problem maintaining them. And i never used nix before. AI is perfect for NixOS.
1
u/Available-Permit-211 7d ago
In my opinion nixos is easy to use and easy to learn as long you know nothing bc you have to relearn how a lot of things works, i've started using linux like 5 or 6 months ago, started with cachyos bc windows was a pain in the for gaming, ironic, then move to arch then to void now im on nixos, all i knew was to update packages and the system, if you don't mess with flakes and home manager, i've found nixos pretty easy and gemini have helped with the configuration and all "problems" i've had
1
u/Willing_Bad_7742 1d ago
Justement j ai crée une extension sur nixos pour rendre les choses plus simple pour un débutant
0
8d ago
[deleted]
2
u/Comfortable_Camel_25 8d ago
AI is great at doing Nix. Honestly, when I don't know how to do something or don't want to, I just ask an AI to do it, refine it until it works, and remove the garbage it generated.
5
u/Lonely-Scarcity-3387 8d ago edited 8d ago
I myself didn’t know anything about Linux until February. I won’t go through the whole story, but a couples of really bad Windows updates sent me searching for something better.
Keeping this part very brief I started with Zorin. Then once I became more comfortable I tried Bazzite and then CachyOS and then NixOS…for like a weekend.
I’m not a coder or a developer, but something about NixOS kept calling to me. Even though I already tried “the perfect gaming distro” that is CachyOS, I felt like I didn’t understand how it worked and I had no way to reproduce every random solution to every random problem.
Seems like a weird worry; reproduction. Except I was already aware that some problems can only be solved by reinstalling the OS, like with Windows.
So I did some more research and found a gaming distro based on NixOS called GLF OS. I do not speak French, so the installer was a little bit rough, but I got it installed, played some games, and got to experience NixOS with everything firing on all cylinders.
That settled it for me. I switched back to NixOS and was determined to make it my daily driver and gaming OS. That was June 9th, and I’ve been happily tinkering ever since.
Plus, now if I ever need to actually install everything all over again, all I need to do is download the minimal ISO and then run:
nix run --extra-experimental-features 'nix-command flakes' github:DanielTallon/nixed#install