Live data from Hacker News

What is Nix and why you should try it

yakking.branchable.com

171–180 of 201 posts

Re: What is Nix and why you should try it

#171
post #75

Is there a way to install nix into home folder (suppose I don't have sudo on server). I spend some time recently trying to setup nix in such environment and failed. I ended up compiling recent versions of neovim and tmux myself.

If you can use it, https://github.com/lethalman/nix-user-chroot is the best way.

But, it depends on user namespaces being enabled on your system. That may not be the case.

Re: What is Nix and why you should try it

#172

That article on "What is Nix and .. " does not contain the words "Nix is a..." A quick read gave a vague sense that it was about installs and file paths so maybe something package-related? Nothing definite. If you click through to https://nixos.org/nixos/nix-pills/why-you-should-give-it-a-t... you will see "Nix is a purely functional package manager and deployment system for POSIX"

I get the feel that Nix does something like what virtualenv does for python, but more generalized to make that work for other software. Is that approximately right?

Yes, I also was immediately reminded of Python's conda based environment management. E.g. 'source activate ' may have python3 but when used with will use python2 and different version of other libraries.

Re: What is Nix and why you should try it

#173

I'm a big fan of Nix, but I really with there was a declarative way to define a user's environment similar to what NixOS has with /etc/nixos/configuration.nix. It seems a little strange to me to have a functional package manager, but an imperative package install process. I think there are a few projects like NixUP and home-manager that are looking to address this, but I'm hoping Nix will provide an official way to d…

There's https://github.com/rycee/home-manager I haven't used it yet, but intent to try soon.

Re: What is Nix and why you should try it

#174
post #45

Earlier quoted context omitted.

Although other people have different opinions to me, I don't really see Nix as something for the desktop, but for development, deployment and server software it's a killer solution for me.

None of what he mentioned was desktop-specific. GPUs are useful, and if CUDA is involved then it's being used for acceleration of some kind, which can perfectly well be done on servers. I agree that Nix is hard to deal with when it comes to binary distributions of any kind, which includes CUDA.

> I agree that Nix is hard to deal with when it comes to binary distributions of any kind, which includes CUDA.

That's really interesting to me. Why is a binary package not considered a source package where "compiling" it is a no-op?

Re: What is Nix and why you should try it

#175

Earlier quoted context omitted.

It takes a list of requested packages, does some dependency resolution to arrive at a matching package list, generates environment variable setting/exporting code (in Python, e.g. setting things like PYTHONPATH and MAYA_PLUGIN_PATH), then launches a new shell with that code. So, yes, you can have multiple shells with different packages in use simultaneously. I don't think it operates below the industry software packa…

I believe GP was asking if you could have packages A and B installed simultaneously if - A depended on version X of C - B depended on version Y of C - X != Y

Yes you can because packages are not really installed at the system level. Those dependencies are all solved at runtime.

You can't have A and B in a same runtime environment obviously.

Re: What is Nix and why you should try it

#176

Earlier quoted context omitted.

Those package expressions have Bash snippets embedded in them that run on the build daemon. The daemon doesn't evaluate Nix code.

How is that a problem?

The paper I linked to explains the drawbacks to such a design.

Re: What is Nix and why you should try it

#177
post #19

I can vouch for the immense improvement Nix has made to my software development process. I use NixOS on my desktop and laptop. At the OS-level, it gets a lot of things right: reproducible, immutable system configs; lightweight containers; devops with declarative configs. At a software project level, nix-shell is an indispensible tool. Compilers and interpreters aren't even part of my system-wide config; instead each…

Sounds like this solves a similar problem to Docker. Can you comment on what the differences are, and the relative strengths and weaknesses of each approach?

The main difference between the two is Nix's ideas come from functional programming, and Docker's are imperative. The practical outcome of this is that it's easier to keep your system clean over time with Nix than Docker because of the way it's been designed.

Nix isn't only a package manager, it is also a functional programming language intended for system administration. This means that, while a Nix file is comparative to a Dockerfile, it has several key differences:

1. All Nix files are just functions that take a number of arguments and return a system config (like a JSON object, but with some nice functionality). A Dockerfile is a set of commands you run to build a system to a "starting" state. This is imperative (you're telling the computer to "do this", then "do that", etc.), so once it's done, you can mutate state to deviate from what you specified in your Dockerfile. With Nix, while you can technically do this on some systems, it does provide you with the command line tools so you don't break things (e.g. nix-shell, nix-env). Note, on NixOS, other measures are taken to encourage safety.

2. If things go wrong in Nix(OS), the idea is that you can do a fresh install in your system, copy your old Nix file to it, and with one bash command, be back to where you were before things went haywire. In terms of containers, there's nothing new with this because this is exactly what Docker does. However, Nix also has this concept of generations, so every time you use a Nix command to change your system state either declaratively via a Nix file or imperatively in the command-line using nix-env, you can roll back to a previous version of state. This is especially nice with NixOS, because it creates generations for your entire system too (includes hardware config, drivers, kernel etc.), and makes separate GRUB entries for each generation, so if something breaks after you do a system upgrade, you just chose an old GRUB entry to go back to where you were. AFAIK, Docker doesn't offer anything like this, and this is a good example of how these tools' designs can impact their feature-set so dramatically.

3. A neat feature of Docker is composability. You can inherit from other, pre-existing Dockerfiles, and you can deploy multi-container apps with various tools. Composability at a single-container level is very straightforward with Nix. Since every config is just a function, you simply call the function exposed by a different Nix file with the correct arguments, and... voila! Once you've made your desired Nix file, you can run it either using nix-shell or nixos-container. While I'm no expert, I believe they perform better than Docker as they don't use virtualization. For multi-container deployment, there is NixOps. You write some Nix files describing the VMs you want to deploy, and run a bash command to deploy them to various back-ends (AWS, Azure, etc.). Again, the big difference here is that you can incrementally modify these VMs in a safe way using Nix. If you change your deployment config file, Nix will figure out something has changed, and modify the corresponding VMs to achieve the desired state.

Some may believe that Docker and Nix are very similar, and to their credit, they are in certain scenarios. The thing I like about Nix is that it's one language (and architecture) that was designed well. It's minimal, yet makes it possible to do so much in a safe way.

Nix has been around for a while, but I think the community is growing quickly as functional programming continues to take off. I'm excited to see where it goes, and am super grateful I have a tool like this to use while coding.

Re: What is Nix and why you should try it

#179
post #36
post #13

"To deal with this nix provides the nix-shell utility which constructs an environment on demand and runs a new shell based on that environment." I'm sure nix is cool but this sort of sounds like something we just end up using docker for these days (for better or worse).

Yes, Docker is a competing solution. Hopefully in the future we will see a better one, more nix-like.

Does Docker actually compete with Nix?

It seems that Docker is more concerned with containment and Nix with packages. I would love to be able to use Nix to define my project+dependencies and Docker to run it.

I'd be surprised if someone hasn't already made a baseline NixOS docker image to build off of.

Re: What is Nix and why you should try it

#180

I switched from Arch Linux to NixOS last year and it was a great experience https://ramsdenj.com/2017/06/19/switching-to-nixos-from-arch... . The community is relatively small and easy to get into, with lots of people ready to help out beginners. It took a while to get used to, especially considering the way to learn how something works seems to always be to go and read source code on GitHub. There are good things an…

If you're using Arch Linux now, you may find this project useful: https://github.com/CyberShadow/aconfmgr
Post reply on HN