Live data from Hacker News

Nix journey part 0: Learning and reference materials

tinkering.xyz

11–20 of 79 posts

Re: Nix journey part 0: Learning and reference materials

#11

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

You can use as much or as little of it as you want, which I know is not a satisfying answer.

I think the most common use case is as a build system, but in this context you aren't limited to building packages, you can also build "environments". By "environments" I mean a shell with certain packages available in `$PATH`. You would use Nix like other build systems in the sense that you specify the build requirements (which other packages, libraries, etc you need to build _your_ stuff), then you specify how exactly to build your stuff. Here "stuff" could be as little as a shell script or as much a huge monorepo.

There are ways to use Nix like you would use Ansible or Terraform, but I wouldn't say that's the mainstream use case of Nix.

Re: Nix journey part 0: Learning and reference materials

#12
post #4

Author here if anyone has questions

Any good resources on how to use flakes? I'm currently experimenting with having home-manager work via a flake but I haven't come across any good HOWTOs on common operations. For example, I'd like to update the flake dependencies similar to how I used to use "nix-channel --update" to freshen the dependencies used by home-manager.

Here you go:

https://nixos.wiki/wiki/Flakes

https://tonyfinn.com/blog/nix-from-first-principles-flake-ed...

The second link appears to be down at the moment so check back later.

Re: Nix journey part 0: Learning and reference materials

#13
post #8

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

Without having properly tried it either, my general impression is that the pitch goes a bit like this: If you love Haskell and wants to make everything that has to so with packages on your system more like Haskell, Nix's got your back.

Because it's functional? I've been using Nix in production for six months and I have no desire to learn Haskell.

Re: Nix journey part 0: Learning and reference materials

#14

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

Nix is a package manager. But it can weave together multiple package managers so it frees you from being locked in to any one particular language, OS, architecture. The proof of this that we also ended up making a full OS (NixOS). Then there are follow-on things one can do, such as using it to manage the configuration of things and people continue to build more tools for this.

Fundamentally the core technology is for it to be a correct and safe package manager. (eg: think about the engineering tradeoffs for memory-safety vs anything-goes) Once you have that basic primitive, lots of things can be "packages": software, data, configuration, dotfiles,......

Re: Nix journey part 0: Learning and reference materials

#15

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

I'll take a stab and say that I believe that nix's actual power is to efficiently materialize an exact tree of files (raw or generated) on any machine. By "exact", I mean in a fully reproducible way.

That capability turns out to be really powerful because you can materialize a program, a whole Unix tree, or even a script that converges the current host to a desired state.

Re: Nix journey part 0: Learning and reference materials

#16

My current objective is to make an easy and reproducible configuration + live image installer. I want to automate the whole process. As soon as I plug in the USB stick, my preferred defaults should do their work without user input. Although, I really don't like Nix as a language. I really wish it would have used something like GNU Guile. Searching deep for nuggets of information isn't nearly as painful as the languag…

Did you mention Guile because of Guix? If not, you might be interested in GNU Guix.

Re: Nix journey part 0: Learning and reference materials

#17

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

My use case:

I used to use Arch. I would always do a btrfs-snapshot before doing a system upgrade, then create another one after booting the new update (provided everything worked). In NixOS I don't have to because it has generations. The upgrade is entirely atomic and if it doesn't work I just use a previous generation.

Second I used to use pyenv and bunch of other tools to make sure I had the right development dependencies. Instead I just put the requirements in a shell.nix or flake.nix in the project directory, have those called with direnv. Now I can easily have python38 with clang_11 for one project and python311 with gcc48 for another.

Third the system of modules generally makes it easy to have my system setup in one place, and with the services I want. If I want zram, I just set `zramSwap.enable = true;` and that works. If I need ssh access: `services.openssh.enable = true;`, oh, but I have the firewall enabled (networking.firewall.enable = true;), that's okay because services.openssh.openFirewall defaults to true, so it handled automatically. And if I change services.openssh.ports to a better port, the firewall will be updated too.

Re: Nix journey part 0: Learning and reference materials

#18

My current objective is to make an easy and reproducible configuration + live image installer. I want to automate the whole process. As soon as I plug in the USB stick, my preferred defaults should do their work without user input. Although, I really don't like Nix as a language. I really wish it would have used something like GNU Guile. Searching deep for nuggets of information isn't nearly as painful as the languag…

Can you clarify what parts you don't like. I think it's important to distinguish so I know what portions to work on (and figure out how to fix it). Is it: the language syntax itself, the idioms used in Nixpkgs, the module system, the common frameworks used to create package sets, or something else?

Re: Nix journey part 0: Learning and reference materials

#19

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

I'm a consultant and jump around different stacks, or have to grok some new thing pretty quickly. Nix helps me with my personal dev environment. I also generally prefer functional style of doing things, declarative, immutable, etc.

Nix is so easy to share across machines (including Mac) that it ends up being pretty cool when you pair it with something like syncthing. I can jump around, get up to speed with something new, and have it everywhere without much setup now that my machines share some Nix code and data.

Mac support is pretty great with nix-darwin; I'm able to update my flake, run nix-build and my terminal/system level apps, Mac app store apps, homebrew apps, and dock shortcuts all get updated at once. My dock points to apps in the Nix store. Sure I could do that with some scripts, but Nix ends up being way more robust.

I also still use Emacs and the community emacs-overlay is pretty awesome.

But after you're up and running, Nix makes all this stuff generally seamless is my point. There have been times I can't update due to some upstream thing, but 80% of the time it's fixed for me in nixpkgs a few days later.

nixpkgs has like 80,000+ packages the last time I looked, and is growing.

I haven't had a use case to stray outside of Docker + terraform for my work related stuff, but it's amazing for sharing dev environments on a team. Flox is a new thing to check out

My repo if it helps anyone get started: https://github.com/dustinlyons/nixos-config

Re: Nix journey part 0: Learning and reference materials

#20

My current objective is to make an easy and reproducible configuration + live image installer. I want to automate the whole process. As soon as I plug in the USB stick, my preferred defaults should do their work without user input. Although, I really don't like Nix as a language. I really wish it would have used something like GNU Guile. Searching deep for nuggets of information isn't nearly as painful as the languag…

https://github.com/NixOS/rfcs/pull/136 soon, you shouldn't have to care what language it uses!
Post reply on HN