8 ms·
Flakes aren't real and cannot hurt you: using Nix flakes the non-flake way
- dinofp 3y agoUh huh. Nothing in this article makes me want to go anywhere near Nix again.
- earthling8118 3y agoThat's your loss, and not our problem.
- deleted 3y ago[deleted]
- thomastjeffery 3y agoIt's both. Nix is fantastic. I'm writing this comment on a laptop that has only ever run NixOS. Nix is also painful to learn. It's painful to use. That doesn't mean it's impossible, or even that it isn't worth it. It means that Nix has room to improve.
- esafak 3y agoThis mixed bag makes it hard to decide whether one should learn it. How much value do you get out of it? What are its best use cases?
- thomastjeffery 3y agoMy OS is always a fresh install. Everything I did to alter and configure my OS is self-contained and self-documented in one file. I can try anything without ever risking the stability of my system. If it breaks, I just reboot, and pick the second most recent GRUB entry. If I ever want to change my root filesystem or move to a new disk, I can do the whole reinstall in a few short obvious steps. I can keep my laptop and my desktop configurations identical. If I want a few things to be different, they can go in a separate config file. The trickiest part is running software that isn't already packaged. It's usually not too hard, though: there are a few nix features that construct a more traditional/compatible environment, like steam-run and nix-ld. The biggest problem is that their existence isn't obvious to new users. They should really go near the top of the manual.
- pxc 3y agoI wonder lately whether the pain is really the primary issue. As I've gotten deeper into using Terraform at work, I've found it much, much more painful than Nix— so much so that it has me questioning whether I want to continue to work with cloud infrastructure at all. Yet Terraform is 'industry standard' and widely praised, where Nix is marginal and maligned for its difficulty. Maybe it's because people think of NixOS more than Nix in all its broad uses, and when they do so they compare NixOS to desktop operating systems where those people don't see themselves as very interested in configuration management. But I wish that many industry standard tools had comparable iteration times to Nix, or concise languages like Nix, reliable transitions between configurations like Nix, efficient caching like Nix, minimally destructive replacement of old resources like Nix, etc. Most of the things people call 'immutable infrastructure' today are painfully slow and transparently mutable. I'm much happier when I'm reliably iterating on local Nix stuff than when I'm praying that `terraform plan`'s success isn't a fluke this time, and that the corresponding `terraform apply` will actually succeed. I'd rather spend an hour on the the thorniest Nix issues than spend 30 minutes fucking around trying to 'help' Terraform delete a resource that requires manual intervention to actually delete, for some godforsaken reason.
- jcranmer 3y agoI was thinking the other day that the power of things like docker or systemd is in recognizing that there is utility in "spawn something in a hermetic environment" for different shades of environment, and Nix would absolutely slot in the hierarchy as an environment with specified build configurations... which is something that absolutely should be a killer, widely used tool like, well, docker files are. That it's not indicates that there is a reason why it's not, and I don't think it's because of a lack of demand. Rather, I think there's something about Nix that causes people to bounce off it hard, and if people want Nix to be more widely used, then it absolutely is a problem that aficionados of Nix need to look at and address.
- theossuary 3y agoI agree. Nix is awesome in a way, but it's also a product of it's time (early/mid 2000s). It definitely solved the problem of reproducible build environments, but it didn't solve isolated environments like docker did. It also has an issue where there are soany ways to do things, it's hard to know what the best way is for your situation (especially between flakes and nonflakes). But I'd say the biggest issue with Nix in general is it's lack of discoverability. This is evidenced in the number of third-party tools built around helping figure out what even exists (noogle.dev and search.nixos.org for example). The language is so dynamic, trying to figure out where things are coming from becomes difficult. Simply put, there's too much magic. Nix also has a tendency to drop down into massive bash scripts to actually do stuff. I really like guix as an alternative in theory, but I haven't had much luck using it yet.
- otabdeveloper4 3y ago"Environment with specified build configurations" is a fractal rabbit hole that unpacks into a myriad of recursive problems. There is no turnkey solution for this, but there is a way out and a way to (eventually) tame the complexity.
- psanford 3y agoYes. I switched from Ubuntu to NixOS ~18 months ago. I am so much happier with NixOS than ubuntu. Its the easiest packaging system I've used where you can easily mix and match stable and unstable packages without worrying about a huge mess of dependencies. I also find myself much more empowered to upgrade packages for security patches myself since I know that I can add an overlay to update the package and everything will just build. And yet... there's so much I just don't understand. Doing simple overlays is relatively easy, but anything of moderate complexity really becomes frustrating. It makes it quite difficult to recommend NixOS when the chasm between being able to use it vs being able to understand it is so wide.
- zilti 3y agoSame here. I switched to Guix and never looked back.
- dlyons 3y agoAlthough Guix reads better than Nix (after all, it's Lisp), I found the support and resources available for learning severely lacking. Plus, you have to jump through hoops to install non-free software, which goes against the ethos of Guix anyway. IMHO, Nix is clearly "the winner" here and we'll see more and more adoption as it improves. Lots of folks are doing exciting work (see https://determinate.systems/ https://determinate.systems/, https://devenv.sh/ https://devenv.sh/, https://flakehub.com/ https://flakehub.com/). And the scale and organization around nixpkgs is damn impressive.
- guilhas 3y agoA distro not wanting to maintain closed source software packages seems reasonable Anyone can create their packages channel or import existing Also Interesting that you can now install Guix in Nix, or Nix in Guix, or both in any other distro So you can easily install any package from Nix There is a lot of work but flakes are still too confusing So winning is relative
- zilti 3y agoYou found support and documentation lacking? How so? The #guix and #nonguix channels are full of helpful people, and unlike Nix, it has a centralized, comprehensive handbook that covers about everything. Finding Nix documentation was a horrible experience in comparison. Yes, there are more Nix than Guix packages, but that hardly matters to me due to how easy it is to create packages for Guix. Devenv seems more or less like direnv?
- pxc 3y agoDevenv includes direnv integration, but the main feature is organizing development environment configurations using a NixOS-like module system rather than declaring them as packages (simple functions). Guix (deliberately) doesn't support anything like the NixOS module semantics. 'Services' are its alternative, of course. I don't know if there is a capability for per-project service declaration in Guix atm, but it wouldn't surprise me!
- dlyons 3y agoI tried to make Nix as easy to adopt as possible by creating Nix commands and a step by step guide (600+ stars): https://github.com/dustinlyons/nixos-config https://github.com/dustinlyons/nixos-config I love Nix. I use it every day to manage multiple local dev environments. And I use devenv instead of docker for sharing project-specific environments with others. Who wants to use docker on a Mac anyway?
- pbronez 3y agoCool project! Last time I tried Nix on MacOS it did not end well. Maybe I’ll try this in a VM and see how it goes…
- dlyons 3y agoFeel free to open an issue if you have any questions! I'll be happy to help.
- heywoodlh 3y ago> Who wants to use docker on a Mac anyway? For a long time, before really doubling down on Nix, Docker Desktop was my go-to for getting a Linux runtime whenever MacOS wasn’t sufficient for what I needed. It was slow, but way more portable than having a Linux VM running all the time. Fast forward to now (since I’ve really invested in Nix) and Nix+Nix-Darwin makes my Mac feel just as configurable and extensible as NixOS/any Linux distribution. Nix makes me an extremely content MacOS user. :)
- dlyons 3y agoSame. I initially started with Guix, because I'm a Lisp hacker at heart, but once I learned about nix-darwin I jumped ship and there was no going back ;) Keeping my NixOS machine on my desk and Macbook in sync seamlessly is also super cool.
- tripdout 3y agoYeah, I use a Linux machine at home, but being able to get my work-provided Macbook up and running with an identical Neovim & ZSH setup almost instantly, without having to figure out how that would all work on MacOS (in terms of package installation, changing the shell, etc) it's super awesome.
- Aaronmacaron 3y agoI use nix on my laptop because it's absolutely brilliant when it works. To me it's a fascinating technology. Being able to easily use different versions of some tool in two different projects, declaratively defining my dotfiles using home manager or quickly trying out some software using nix-shell -p is almost magical to me. Eventhough I've used nix for years now, I have no deep understanding of nix and I'm a very curious person who always tries to understand how stuff actually works. Nix makes me feel really dumb. It makes me feel like when I was twelve and I "programmed" by cluelessly stitching together code examples from online tutorials. I don't really understand what's going on outside of the really common use cases for nix. I read the entire nix docs but I think it's the kind of documentation that's only useful if you already kind of get what's going on. It feels like you have to gather the knowledge from various random blogs. Last time I checked there surprisingly was not a single book which covers nix. I feel like a comprehensive book which teaches nix from the ground up and explains all the different ways of using nix would really help me and I would purchase such a book without hesitation if it existed.
- whatwhaaaaat 3y agoWhen you say run it on your laptop do you mean as the base operating system or on something else through a vm?
- thomastjeffery 3y agoI can't speak for them, but I can tell you I'm running NixOS directly on my own laptop (and desktop and server).
- ParetoOptimal 3y agoSame. Also recently added a steam deck to the fleet with https://jovian-experiments.github.io/Jovian-NixOS/ https://jovian-experiments.github.io/Jovian-NixOS/
- Aaronmacaron 3y agoI used to run NixOS on my main computer for a few months until I encountered some situation that I couldn't resolve using my nix skills. I think I needed to run some software that wasn't on nixpkgs. Nowadays, I just use nix (the package manager) on top of PopOS.
- Guvante 3y agoI tried playing around with NixOS. Unfortunately I broke Plasma messing around trying to turn on Wayland. Flakes are why I stopped and likely won't go back. I tried to add a flake that contained PragmataPro (a paid for font). Having a git repo was easy I just wouldn't push it anywhere to avoid copyright issues. Figuring out the syntax to actually get the font files installed was maddening. It probably didn't help that I followed best practices and built some crazy cross compilation mechanism into my flake but it was almost impossible to figure out how to extract a zip file and then copy to the final destination. Well unless I downloaded the zip file then it was trivial... Avoiding flakes except as an isolation point likely would have allowed me to stay engaged with the project. Might have to check this out if I ever feel the need again. Yeah looks like callPackage is what I needed.
- drakerossman 3y agoYou may want to try this: https://drakerossman.com/blog/wayland-on-nixos-confusion-conquest-triumph https://drakerossman.com/blog/wayland-on-nixos-confusion-con...
- bomewish 3y agoI checked your site. It’s great you have the energy to promote and explain nix. I think you could get a lot out of that google course teaching technical writing. There were some other HN posts on technical writing recently too. You’re a technical writer now, if you didn’t know already, so it would be worth learning how to apply that skill well. You’ll get a lot more leverage for every input.
- drakerossman 3y agoThank you for the feedback and kind words, and you're absolutely right. I have also gotten this feedback on improving my written communication skills already in the past. I unfortunately have very little time to edit the posts, and for the stuff not yet posted, I do not like to post the drafts. And I have tons (tons!!!) of such drafts. A promise to myself I made is that I am going to have a good cadence of posting for this year. There are definitely more articles to come, till end of January for sure, and if you've found the stuff useful/intersting, you may would want to subscribe on some medium I use (say Twitter, or Mastodon, links on my website).
- lima 3y agoThe biggest problem with Flakes right now is that they will copy your entire Git repository into the (world-readable) Nix store, rather than just the files that are referenced. Even if you're in a subdirectory - which makes is unusable for monorepos. Flake-less Nix handles this just fine.
- JZL003 3y agoI've been using nix for my personal server and it's a lot of fun. And I don't mind reading 'code as docs' in general but it's pretty much required here. Mostly the option names are pretty understandable, and it's helpful to see in the code exactly what it does, not just a human version. But truly invaluable is sourcegraph (I guess github search is better but I still don't like it) so you can search through other peoples config https://sourcegraph.com/search?q=context:global+file:.*nix+BLAH&patternType=standard&sm=1 https://sourcegraph.com/search?q=context:global+file:.*nix+B... On the other hand, I wanted to have emacs compiled with sqlite (needed for magit) and it took me hours to get working, then had to keep modifying to pin the version so it didn't recompile constantly
- ParetoOptimal 3y agoI have a kagi bang just for this, !sgn.
- tripdout 3y agoHow does Sourcegraph compare to just searching Github? ie file:*.nix BLAH
- drakerossman 3y agoFor the non-initiated, who also have experience with the likes of Ubuntu and Fedora, I made an overview of NixOS in this article, which also provides a guidance on how to bootstrap a functional desktop system: https://drakerossman.com/blog/nixos-for-apt-yum-users-a-gift-that-keeps-on-giving https://drakerossman.com/blog/nixos-for-apt-yum-users-a-gift... Also discussing flakes in some other articles of mine.
- im3w1l 3y agoWhat I've come to realize is that I don't want Nix. But I do want ordinary Linux distros to move in that direction. Like update-alternatives. Like simple ways to reinstall the system while keeping /home. Like a file with all installed packages that you can edit to install/uninstall. Like nicer merging of overriden config when a new default file is available from upstream.
- tripleo1 3y agohttps://repolib.readthedocs.io/ https://repolib.readthedocs.io/
- ParetoOptimal 3y agoYou might like Silverblue?
- dawnofdusk 3y agoThis blog post is one of the best ones I've seen on Nix tbh. Brings a lot of clarity on things people are often confused about ("What is a flake?" "What is a module?"). Hoping it doesn't get drowned in the SEO for people
- 8organicbits 3y agoWhen doing reproducible builds with Nix, how are people dealing with build artifacts that can't be downloaded? I see that I can do a fetchurl with a specific URL and hash, but this obviously fails if the content is missing. On Debian pinning is a little strange. You can try `apt install foo=1.2.3` and it will work until the next versions is released. Debian removes old versions from the mirrors. However they operate a snapshot archive with all the old package versions, so reproducible builds can use that and should continue to work over many years. Does Nix have a way to ensure pinning continues to work over many years?
- tracnar 3y agoFor things in nixpkgs, the files will be mirrored on the nix cache. For your own stuff you could set up your own cache or use a service like cachix. There is also a nix option to set up a generic mirror which looks up files by hash, but I'm not sure if it works with all the ways to fetch things: https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-hashed-mirrors https://nixos.org/manual/nix/stable/command-ref/conf-file#co...
- puetzk 3y ago> this obviously fails if the content is missing. It doesn't, actually - all the fetchers are [fixed-output derivations](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHash https://nixos.org/manual/nix/stable/language/advanced-attrib...) where you specify not only the source, but the hash it is expected to produce. And so the fetched files will be hashed and placed in the nix store under that hash. And therefore subsequent builds using that artifact will use the already-stored artifact and not care if the source is reachable or not. You know that all "external" inputs will be captured by fixed-output derivations, because any derivation that isn't fixed-output is blocked from network access. For anything built by the hydra CI, this will be retained on central cache.nixos.org. Or you can copy from a store of some machine that has it. Now, if it's something not on the official cache.nixos.org, and the source is gone, and you've lost (or pruned) your store, you will need to get the file from somewhere and put it back in your store: https://nixos.org/manual/nix/stable/command-ref/nix-store/add-fixed https://nixos.org/manual/nix/stable/command-ref/nix-store/ad.... Or you just change the source URL (this won't change the derivations depending on it, because the input being transferred is identified by the hash that is to be delivered, not by the URL it comes from).
- thomastjeffery 3y agoNix has a namespace problem. Most package managers exist independently from the packages they manage. Nix integrates them directly into its monolithic source tree. So when you ask nix to install a package, what version does it give you? The original method is channels: each channel follows a branch of the NixOS/nixpkgs GitHub repo. Every package is given a global name in nixpkgs/pkgs/top-level/all-packages.nix This is...a mess. Versions? They go in the name sometimes, like python2. Names aren't consistent everywhere, either. The name of a package in all-packages.nix might need to be different from the name in its own derivation source. Good luck finding it. Not every package gets a global name, either. Some are moved into separate attributes sets. Some get both. Figuring out what magic words need to go into your configuration.nix (or at the end of a command) is a lot more difficult than it should be. Even more difficult is figuring out what needs to go in a new package. Flakes try to dodge this mess by moving it out of the global namespace, out of the nixpkgs source tree, and into the source of the thing you want packaged. I'm not a huge fan.
- pxc 3y ago> Most package managers exist independently from the packages they manage. Nix integrates them directly into its monolithic source tree. A couple of minor points: the Nix package collection lives in the Nixpkgs repo. The package manager's source has its own repo. > So when you ask nix to install a package, what version does it give you? > The original method is channels: each channel follows a branch of the NixOS/nixpkgs GitHub repo. Every package is given a global name in nixpkgs/pkgs/top-level/all-packages.nix > This is...a mess. Versions? The monorepo of package declarations (build recipes) is traditional for source-based package managers like Nix. Anyway, it doesn't preclude versioning in a more traditional way. Gentoo's Portage, for instance, has a tree of build recipes but also supports multiple versions, in-tree, in a first-class way. Maybe Nixpkgs or a similar package set could have something like that some day. Overall, I agree that the namespacing in Nixpkgs is messy and also that replacing Nixpkgs with assorted flakes that refer to one another as inputs doesn't seem great.
- thomastjeffery 3y agoThanks for the clarification. It's also worth mentioning that NixOS itself is in the nixpkgs repo. That sorta makes sense. Sorta. There are two reasons I'm really frustrated with the namespace problem: 1. Discoverability I have spent a very significant amount of time just trying to answer the simple question, "what is the package named?" The worst part is when the package does have an obvious top-level/all-packages.nix name, but that isn't the one you are supposed to use! Sometimes, a package will need to change more of your environment than PATH, like udev rules or systemd units. In that case, it will have a totally different attribute like services.openssh.enable; but there is no clear way to learn this is the case, or what the attribute is! I still don't have a good sense of how nixpkgs is organized, and I've been using NixOS as a daily driver for 5 years. 2. Flexibility Writing a new derivation (package) is way too difficult. Documentation is improving, but it's still not nearly good enough. There are just too many layers, and too much magic. God forbid you need a different version of a library. Of course, that's the problem that flakes solve, but it's still hard to find what you need, even when it's there.
- jljljl 3y agoI think the split between Flakeful and Flakeless Nix that the article mentions is a big challenge for developers coming in new to the ecosystem. There's a video that recently circulated of Geohotz trying Nix from scratch[0], where the mixed messaging on whether to use Flakes caused a lot of initial confusion. We've gone pretty all in on Flakes with our Devbox product[1] -- We think they simplify a lot of confusion on how to package and use Nix once you embrace them. I hope they become a more accepted standard in the future. [0]: https://youtu.be/v7lIGYU0onA?si=3Wpbx82GcZVxwKY6&t=5256 https://youtu.be/v7lIGYU0onA?si=3Wpbx82GcZVxwKY6&t=5256 [1]: https://www.jetpack.io/blog/why-did-nix-adopt-flakes/ https://www.jetpack.io/blog/why-did-nix-adopt-flakes/