News for hackers. Stuff that matters.
Re:Enlightenmentware by jchw on Monday May 20, 2024 @05:51PM (#40420860)
Doubt anyone will be surprised by this from me, but, Nix, 1000x. The amount of crazy stuff you can make work with Nix and Nixpkgs is nuts. This weekend someone pinged me wanting a static build of a Rust binary that had some gnarly bindings to C++ libraries. In under 100 lines of Nix, we have everything: static musl-based build, dynamic glibc build. Want an AppImage? `nix bundle` with an AppImage bundler. Want an OCI image? dockerTools.buildImage on top of your derivation. Throw it in GitHub actions using the Determinate Nix Installer action and you get automatic caching of the Nix store using GitHub actions cache; pretty useful since neither musl Rust nor static LLVM are cached in Hydra. Want to share your cache? Pipe a list of Nix store paths to Cachix, then they can pull it down, or add the Cachix GitHub action to automatically pull from and/or push to it for the CI build. So if anyone wanted to re-use your cache from GitHub Actions CI runs, they could, provided they trust you. You can even cross-compile with MinGW, or run it on macOS.

It's a hugely complex time sink, but my God, it's great. Whereas I don't generally recommend people go down the NixOS rabbit hole unless they're convinced it's right for them, I definitely think Nix is worth having in your toolbelt, it's ridiculously versatile.

Re:Enlightenmentware by emporas on Monday May 20, 2024 @07:51PM (#40422132)
Nix is one of the reasons open source wins in the long run. I would have never imagined that package dependencies could be installed and managed across programming language boundaries, kernel boundaries, shell boundaries, dotfile boundaries etc.

Given that computer complexity grows exponentially all the time, then at some point everyone will be forced to use something like Nix.

I agree with the article with Emacs and Unix/Linux.

Re:Enlightenmentware by fire_lake on Tuesday May 21, 2024 @02:06AM (#40424697)
Functional Programming approaches usually win in the long run. This is a common thread in the article too, although not explicit.
Re:Enlightenmentware by trashburger on Tuesday May 21, 2024 @07:04AM (#40426765)
I think you mean declarative. Whether something is FP or OP usually doesn't matter too much (unless you go to the extremes of each end of the sprectrum a la AbstractBeanFactory/IO Functor State). Declarative solutions last longer by virtue of their declarativeness; the underlying implementation can evolve as long as the declarative layer is untouched.
Re:Enlightenmentware by zarathustreal on Tuesday May 21, 2024 @07:42AM (#40427031)
Isn’t a class a declaration (of a class type)? Isn’t a function a declaration (of an algorithm)?

I’d assert that every programming language is declarative. Especially once you get enough written to constitute a DSL.

Re:Enlightenmentware by bubblyworld on Tuesday May 21, 2024 @12:18PM (#40430453)
I think they mean declarative in the sense that you write down want you _want_ in a solution (prolog/datalog/terraform/etc) without specifying exactly how to compute it (day to day programming languages).
Re:Enlightenmentware by zarathustreal on Tuesday May 21, 2024 @06:45PM (#40434967)
The definition of computation depends on the abstraction level. Languages span multiple abstraction levels. The point is that there’s no meaningful definition of “declarative language” as proven by the examples I’ve already given.

For example you can “compute” a roguelike in TypeScript types, but a type system is declarative!

Re:Enlightenmentware by emporas on Tuesday May 21, 2024 @11:49PM (#40437128)
If you are willing to go to extraordinary lengths, then yes any programming language can be written in a declarative style, at least some part of the program. Some parts of a Java or PHP program can be written declaratively.

In the Nix language context however, they mean declarative and functional like Prolog.

There is also Guix which uses Scheme to declare dependencies, and Scheme is not a declarative language. Scheme is a functional language, but it can be easily written in a declarative style.

Re:Enlightenmentware by bubblyworld on Wednesday May 22, 2024 @01:34AM (#40437649)
Everyone knows this, friend. It's still a useful distinction.
Re:Enlightenmentware by chriswarbo on Thursday May 23, 2024 @10:14AM (#40455020)
I'd say the distinction is more at the semantic level, i.e. denotational vs operational.
Re:Enlightenmentware by xyzzy_plugh on Monday May 20, 2024 @06:25PM (#40421199)
This 100%. It's the gift that keeps on giving.
Re:Enlightenmentware by nicce on Monday May 20, 2024 @06:49PM (#40421463)
You need to give the first gift, however. Time. And lot of it.
Re:Enlightenmentware by memothon on Monday May 20, 2024 @07:34PM (#40421955)
What's the right way to learn how to use NixOS?

There are a few different approaches to doing everyday development (oh use Flakes or just make it a default installed package) that it's tedious to do lots of things I've found.

Re:Enlightenmentware by jchw on Monday May 20, 2024 @09:20PM (#40422951)
I don't think there's a right way to do it, you are correct in that learning NixOS is pretty tedious.

Re: flakes, my personal opinion is to use flakes. While Flakes are imperfect, they still provide a lot of functionality that Nix doesn't otherwise have. In my mind, it's like Nix's equivalent of "Go modules" or something like that. I do feel like people who do not like flakes make many valid points (the boilerplate, the fact that the top-level flake expression is a subset of Nix for some reason, etc.) but the argument isn't that those problems shouldn't be solved, it's that flakes are a sub-optimal design. Since they're so proliferated throughout the ecosystem though, it is quite unlikely that Nix or any prominent fork will outright drop flakes support any time in the near future. For better or worse, Flakes are part of the Nix ecosystem for the foreseeable future. In my opinion, one may as well take advantage of that.

If you haven't already, I'd get your feet wet with installing Nix on a non-NixOS machine first, and please feel free to ask questions about Nix in the NixOS Discourse "Help" section.

I have some recommendations:

1. https://github.com/nix-community/nix-direnv - Since Nix derivations usually wrap around other build systems, the entire derivation is recomputed when any file in it changes; using direnv, you can just get your normal dev tools upon cd'ing into your project directories. This gives you a lot of the benefits of Nix during local development, but with your normal stack, and without needing to globally install anything. Importantly, this works around the problem of needing to rebuild your project every time a file changes; Nix caching isn't granular enough (at least when wrapping around other build systems as it normally does.)

2. If you are trying to build something, chances are you can find inspiration in Nixpkgs. Are you curious how you might package a Bevy game? No problem: literally search "bevy" on the Nixpkgs GitHub repo and see what comes up. I found a derivation that does: https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/jump...

3. If you use flakes, you should keep the flake "schema" handy. There are a lot of different kinds of flake outputs and there are different ways to specify the same thing, which is somewhat needlessly confusing; keeping the flake schema handy will make it easier to understand what Nix is looking for in a flake, which might make it easier to see what's going on (especially if it's obfuscated.) The most important takeaway here: A command like `nix run flake#attr` will try multiple different attributes. https://nixos.wiki/wiki/flakes#Flake_schema

4. Likewise, I really recommend reading up on what NixOS modules are. NixOS modules are the basis for configurations on NixOS, and having a clear understanding of what is even going on with them is a good idea. For example, you should understand the difference between the Nix language's `import` directive, and using the NixOS modules `imports` attribute to import other NixOS modules. Understanding how the configuration merge works saves a lot of headache, makes it easier to understand how people's configurations works, and also makes it easier to modularize your own NixOS configurations, too. https://nixos.wiki/wiki/NixOS_modules

Unfortunately though, there's just no way to make it "click", and I can't guarantee that it's worth all of the effort. For me, I felt it was, but yes, there's no one correct way to do it.

But please feel free to ask questions if anything seems confusing.

Re:Enlightenmentware by memothon on Monday May 20, 2024 @10:54PM (#40423549)
Thanks for the inspiration. I actually already have nixOS installed on another laptop, but lapsed back to my Ubuntu machine out of a bit of frustration. I'll try it again and see how far I get with these tips.
Re:Enlightenmentware by SSLy on Tuesday May 21, 2024 @05:19AM (#40425988)
Point 4 is incredibly under-marketed. Almost all of Nix/NixOS documentation focus on the language-y and build-system-y parts of Nix, and the NixOS modules are usually not talked about. Terrible state of docs doesn't help.
Re:Enlightenmentware by pxc on Tuesday May 21, 2024 @11:06AM (#40429425)
Knowing what are the 3 official manuals for the 3 most important projects in the core Nix ecosystem (the manuals for Nix, Nixpkgs, and NixOS, respectively) that together make up the core of the official docs will save newbies a lot of trouble.

> the language-y and build-system-y parts of Nix Language-y manual: https://nixos.org/manual/nix/stable/language/index.html

Build system-y stuff manual: https://nixos.org/manual/nixpkgs/stable/

> the NixOS modules

Using the NixOS module system in the sense of leveraging existing modules is the main topic of the NixOS manual: https://nixos.org/manual/nixos/stable/

Details about the module system mostly live in this section of it: https://nixos.org/manual/nixos/stable/#sec-writing-modules

The piece they don't tell you is that as a NixOS user, you generally want to look for a NixOS module that supports your application first. Only if you don't see one should you then directly/manually install a package into, e.g., environment.systemPackages.

In other words, search here first: https://search.nixos.org/options

And search here second: https://search.nixos.org/packages

The landing page that ties these reference docs together and also contains a lot more example-centric and tutorial content is nix dot dev, here: https://nix.dev/

Imo nix.dev is a great entrypoint and quickly getting better. In addition to providing a bit of a map to help you navigate the official docs, it includes the best official starting docs on flakes, and links to the highest-quality external tutorial and expository material about Nix.

Make a mental note about the 3 big reference manuals, and bookmark nix.dev, and you have everything you need to learn your way around the official docs.

Re:Enlightenmentware by atrus on Monday May 20, 2024 @10:22PM (#40423367)
The No Boilerplate video is what got me started: https://youtu.be/CwfKlX3rA6E?si=hJZ_mm9vaeKI0w8V

It's just super nice having everything in a git backed config, for multiple systems. Working with NixOS seems like I'm simultaneously working 10 years in the future and 10 years in the past.

Re:Enlightenmentware by pxc on Tuesday May 21, 2024 @12:28AM (#40424127)
> What's the right way to learn how to use NixOS?

Just commit. Make it your daily driver, engage the community for help, and learn whatever you need to learn to do things the idiomatic way. Then settle in and get comfy.

That said, I hear you about the paralyzing number of choices. Here are some okay choices you can fall back on when you get dizzy:

  - use flakes with direnv for all your projects
  - when in doubt, just write the damn package
    - need to use some Python library that depends on another Python library that's not in Nixpkgs? Package 'em. Package all the recursive dependencies, then package the library you wanted to use.
    - want some program that's not in Nixpkgs? package it
    - want to reuse a binary built for a traditional distro? package it. Look at examples in Nixpkgs of similar things (e.g., Discord, Steam)
  - seek community engagement on Discourse and Matrix, not elsewhere (not Reddit, not Discord, not Slack, not IRC)
This is the best way to learn NixOS, imo. But if it seems like too much, it's not the only way.
Re:Enlightenmentware by null_point on Tuesday May 21, 2024 @10:38AM (#40429083)
I found using Nix package manager on my current daily-driver OS was a great way to break the ice. After translating my dotfiles to Nix and figuring out my project-specific development workflow I had given myself a strong foundation for NixOS.

Jumping into the deep end and going straight to daily-driving NixOS, is certainly also a good option.

Re:Enlightenmentware by jauntywundrkind on Monday May 20, 2024 @07:24PM (#40421866)
I see tons of people very happily using Nix, but also from what I've seen Nix is one of the most opaque hard to understand inscrutable systems on the planet. The language is impossible to learn, and my limited experience has been that there are extremely few good guides to peering under the covers.

Nix is one of the most powerful & well-used bits of modern computing, hugely adopted and loved, but my limited understanding (and what's kept me broadly uninterested) is that it is on the wrong side of the Age of Reason trying to overthrow the Age of Magic war.

Re:Enlightenmentware by jchw on Monday May 20, 2024 @09:25PM (#40422988)
Honestly, I suspect a lot of what makes it opaque is the fact that it hinges a lot on functional paradigms, this definitely made it a lot harder for me to understand. The trouble is that now that I understand it, I'm not sure how they could architect this in a more scrutable way. This is the problem.

I think most of us who use and love Nix understand that it is too complicated, but it's too complicated because none of us can figure out how to make it simpler.

Re:Enlightenmentware by infogulch on Monday May 20, 2024 @10:51PM (#40423532)
I'm also nix-curious and intimidated by the wall. I feel like things would be a lot easier to grok if Nix actually had a static type system or even something opt-in instead of "the object has whatever fields I happen to put in it, good luck lol"-typed.
Re:Enlightenmentware by colordrops on Tuesday May 21, 2024 @12:40AM (#40424206)
The language is not the hard thing, it's actually straightforward once you get it. It's the crazy amount of convention and the number of layers in the stack that make up the Nix ecosystem that takes so long to grok.
Re:Enlightenmentware by chriswarbo on Thursday May 23, 2024 @09:40AM (#40454604)
> The language is impossible to learn, and my limited experience has been that there are extremely few good guides to peering under the covers.

Maybe my "Nix from the bottom up" page would help? It peers so far "under the covers" that I only introduce the Nix language very briefly near the end (as a saner alternative to everything else on that page!) http://www.chriswarbo.net/projects/nixos/bottom_up.html

Re:Enlightenmentware by renewiltord on Monday May 20, 2024 @06:28PM (#40421229)
Wait, this is a pretty good sell. I'm going to give this Nix thing a shot. All the other times it's posted people talk about things I don't care like replicable builds and stuff.
Re:Enlightenmentware by __MatrixMan__ on Monday May 20, 2024 @06:49PM (#40421462)
My guess is that if you use it long enough for it to start being useful, you'll find that "replicable builds" solves a wider variety of problems than you initially thought it did.

At that point, the hard part becomes getting your co-workers to recognize that all of these little problems that they perceive as separate are actually just facets of the the same huge nondeterminism problem.

Re:Enlightenmentware by renewiltord on Monday May 20, 2024 @07:02PM (#40421606)
I'm sure. It's just not a selling point for me right now.
Re:Enlightenmentware by pxc on Tuesday May 21, 2024 @12:16PM (#40430421)
Perhaps that's exactly the problem: 'reproducibility', 'determinism', 'functional'-- these are unfortunately too much 'insider language' to be great sells to most people who aren't already FP or Nix people.
Re:Enlightenmentware by helpfulclippy on Tuesday May 21, 2024 @12:53AM (#40424291)
I had only a dim awareness that Nix was even a thing before a few weeks ago. Then somehow I decided that I needed to commit to it 100% and make NixOS my daily driver and make myself learn this. It's been a lot of fun. Like, Dwarf Fortress kinds of fun. The kind of fun where when I first looked at it I thought it was insane inscrutable nonsense, and now I kind of wonder what happened to me that it's kind of making sense now. The kind of fun where I keep telling myself I just want to make some tiny little thing work, but actually I find excuses to rabbit hole down a bunch of different pathways and find amazingness under every stone. The kind of fun where I know better than to try to count how many hours I've spent on this now.

Except unlike Dwarf Fortress, I feel like things are actually improving over time instead of shambling ever-onwards towards an inevitable downfall. So I guess maybe it's more like the kind of fun the very first time I installed Linux and didn't know my way around anything.

I'm surprised how much I enjoy customizing things now. I always thought of my desktops sort of like betta fish before -- like, I've taken care of them, but also known better than to get too attached. Eventually the reformat is gonna come, and I'm never gonna set things up QUITE like I had it before. That's definitely not true now. I could start from scratch and be up and running with my entire suite of applications, themes, add-ons and configurations in no time, because it's all just a git repo of nixfiles.

Re:Enlightenmentware by pxc on Tuesday May 21, 2024 @01:44PM (#40431466)
> I had only a dim awareness that Nix was even a thing before a few weeks ago. Then somehow I decided that I needed to commit to it 100% and make NixOS my daily driver and make myself learn this. It's been a lot of fun. Like, Dwarf Fortress kinds of fun. The kind of fun where when I first looked at it I thought it was insane inscrutable nonsense, and now I kind of wonder what happened to me that it's kind of making sense now. The kind of fun where I keep telling myself I just want to make some tiny little thing work, but actually I find excuses to rabbit hole down a bunch of different pathways and find amazingness under every stone. The kind of fun where I know better than to try to count how many hours I've spent on this now.

That's absolutely what diving in with NixOS was like for me. Wonderful description. :)

> I'm surprised how much I enjoy customizing things now. I always thought of my desktops sort of like betta fish before -- like, I've taken care of them, but also known better than to get too attached. Eventually the reformat is gonna come, and I'm never gonna set things up QUITE like I had it before. That's definitely not true now.

Yes. NixOS makes customization feel more worth it than other operating systems can! I first heard it expressed best in this video: https://www.youtube.com/watch?v=17-TRCpDizA