News for hackers. Stuff that matters.
Re:My First Impressions of Nix by p-e-w on Monday June 19, 2023 @03:09AM (#36388169)
I've occasionally encountered projects using Nix, and I've casually browsed the Nix and NixOS websites, but I still don't have a clear idea of what Nix is.

Is it a package manager? A build system? An operating system? A container platform? A sandbox? An automation tool?

Which widely used, existing software tools is it analogous to?

Re:My First Impressions of Nix by hamandcheese on Monday June 19, 2023 @03:20AM (#36388241)
Most of the above.

- Nix is a tool for building and installing software.

- Nix is a language for expressing how to build a package. Nix-the-tool reads expressions defined in Nix-the-language to know what to do. At the end of the day, this translates into normal commands that run in a sandboxed build environment.

- Nixpkgs is a monolithic repository of 80000+ packages, defined literally as one giant expression in the Nix language (this works fine because Nix is an extremely lazy language). This also includes lots of helpers and abstractions for building packages that can be handy in your own projects. It is possible to use Nix-the-tool without Nixpkgs, but nobody does.

- NixOS is a Linux distribution built on these foundations. Everything under /etc is built from nix expressions. You can not directly edit these. Mostly NixOS is about building systemd unit files from Nix expressions - viewed through that lens it's not really all that exotic of an OS. NixOS has modules that make it very easy to configure and run lots of software.

Re:My First Impressions of Nix by prox on Monday June 19, 2023 @09:50AM (#36391087)
So does this allow for different boot setups for NixOS? Say “webserver” or “office management” , “media streamer” profiles?
Re:My First Impressions of Nix by SAI_Peregrinus on Monday June 19, 2023 @10:38AM (#36391548)
Yes. E.g. some guy's config with 6 different machines[1]: multiple desktops, laptops, servers, a Raspberry Pi, and a VPS. That's a rather advanced use of Nix for configuration, but definitely shows what it's capable of.

[1] https://github.com/Misterio77/nix-config

Re:My First Impressions of Nix by prox on Monday June 19, 2023 @12:25PM (#36392922)
Wow! Really impressive.
Re:My First Impressions of Nix by mindslight on Monday June 19, 2023 @03:17PM (#36395396)
I wouldn't even say that's so advanced. I've got a similar config (not published, sorry). All built from source, with the resulting binaries pushed to less-trusted hosts. My cloud servers, router, wifi APs, Kodi boxes, etc, all running self-hosted self-built software with config kept in git.

Previously I used to run Debian across my setup (with a homemade configuration templating/distribution tool) but it feels like Nix really bundles up the accidental complexity of most software in a contained way, much more than a traditional distro.

I'll be much happier when Nix gains full reproducibility and functionality like Guix's `challenge`. But even now it feels like one of the closest implementations to the Free Software dream.

Re:My First Impressions of Nix by hamandcheese on Monday June 19, 2023 @01:34PM (#36394038)
I'm not exactly sure what you mean. NixOS doesn't have, like, a profile switcher to let you switch between work mode and play mode on the same PC. At least not out of the box.

But if you mean distinct computers, then that's just three distinct configs. And it's easy to factor out common bits and use it in all three configs, since you configure things using Nix-the-language.

And if you mean all three at the same time on one PC, that's exactly what I do with my home server.

Re:My First Impressions of Nix by ElectricalUnion on Monday June 19, 2023 @03:37PM (#36395609)
> NixOS doesn't have, like, a profile switcher to let you switch between work mode and play mode on the same PC.

I thought that `sudo nixos-rebuild switch` was supposed to do exactly that; swap from whatever "state" your PC is on to the result of the nix expresison on "/etc/nixos/configuration.nix"

Re:My First Impressions of Nix by hamandcheese on Wednesday June 21, 2023 @10:55PM (#36427500)
Yes, that is how you update your system.

But it would be very unusual to constantly switch between two long-lived configs. I don't see why it wouldn't work, though.

Re:My First Impressions of Nix by misterio7 on Monday June 19, 2023 @06:13PM (#36397103)
Yeah! There's specializations[1] to make this even simpler.

[1] https://nixos.wiki/wiki/Specialisation

Re:My First Impressions of Nix by bandrami on Monday June 19, 2023 @03:27AM (#36388287)
It's maybe best described as a software ecosystem, which has the unfortunate problem that the programming language it uses and the package/deploy tools written in that programming language share the name "Nix". Nix the language (basically a customized version of Standard ML) is used to write package and OS definitions that Nix the tool uses to actually build and deploy software, containers, and operating systems. The "ecosystem" bit comes from the fact that the language is used to write the package/deploy definitions, and a large community of users have assembled a rather good and up-to-date set of package definitions, and these have been bundled together as an operating system, and these all share the rubric "Nix".
Re:My First Impressions of Nix by mindwok on Monday June 19, 2023 @03:22AM (#36388255)
It's got elements of all of those things. It's basically a toolchain for building an 'environment', which is roughly analogous to a Linux distribution.

It starts with a language that lets you declare the desired state of your environment, including which packages are present and the configuration of those packages. The packages are installed and managed through the Nix package manager. The end result is an 'environment' that reflects the desired state you expressed. That environment can be a Docker image, an ISO, or it could be a running system you're booted into (in the case of NixOS). Or it can even be an ephemeral environment that exists on the filesystem of whatever distribution you're using (in the case of nix-shell). Each of these options offers different levels of isolation and reproducibility, depending on the requirements of your project or system.

There's lots of clever components that make something like this possible, and they're all wrapped up in the Nix umbrella.

Re:My First Impressions of Nix by danieldk on Monday June 19, 2023 @03:28AM (#36388290)
It confuses a lot of people, because Nix breaks down the boundaries of what we traditionally see as separate tools. If you have a sufficiently powerful language to describe how to build things, you can build packages, container images, operating systems, etc. with it. Probably the closest equivalent outside Nix/Guix is Bazel or Buck (not the same, but they have many overlapping goals).
Re:My First Impressions of Nix by nickcox on Monday June 19, 2023 @03:33AM (#36388318)
> Is it a package manager? A build system? An operating system? A container platform? A sandbox? An automation tool?

Yes

Re:My First Impressions of Nix by seqizz on Monday June 19, 2023 @03:18AM (#36388226)
Afaiu it's trying to become all. Nix is on core, you can get packages from nixpkgs / write your own definitions, use it on OS configurations via NixOS, use its built-in helpers to run your containers with it, make a whole CI and cache it with the help of Hydra etc.
Re:My First Impressions of Nix by politelemon on Monday June 19, 2023 @03:20AM (#36388240)
That's confusing because NixOS also seems to be an operating system, looking at the blog post?
Re:My First Impressions of Nix by chpatrick on Monday June 19, 2023 @03:24AM (#36388265)
NixOS is just a super barebones distro where everything is configured with Nix. You can also use Nix on Ubuntu or some other distro.
Re:My First Impressions of Nix by SuperSandro2000 on Monday June 19, 2023 @11:30AM (#36392235)
Bare bones as in by default you don't get much unless you turn it on
Re:My First Impressions of Nix by chpatrick on Tuesday June 20, 2023 @07:17AM (#36402409)
Right, it's just bash, Nix and systemd by default.
Re:My First Impressions of Nix by imagineerschool on Monday June 19, 2023 @03:23AM (#36388260)
"Yes, it is."

AFAIK It's each of those things, each unfortunately named the same.

Re:My First Impressions of Nix by rollcat on Monday June 19, 2023 @04:28AM (#36388639)
We already have names like NixOS and nixpkgs at the top, and individual commands such as nix-env or nix-shell at a lower layer. Perhaps it would be beneficial to adopt official names for other components currently named "nix", such as nixlang (when referring to just the language).
Re:My First Impressions of Nix by SuperSandro2000 on Monday June 19, 2023 @11:31AM (#36392249)
Only the package manager and the language share a name, everything else is named more unique
Re:My First Impressions of Nix by sjamaan on Monday June 19, 2023 @05:27AM (#36389033)
> Is it a package manager? A build system?

Nixpkg is a package manager, which uses the Nix programming language to describe dependencies and build steps. Like all package managers, it has components that could be called a "build system", but that's not its main focus.

> An operating system?

There's NixOS which is a Linux distro built on nixpkg. But you can also use Nix under other distros.

> A container platform? A sandbox?

Because nix is based on an underlying immutable store of installed packages (and doesn't rely on global system state), it is trivial to spin up a shell environment in which specific combinations of package versions are available without affecting any other shell.

This property allows it to be used as a lightweight alternative to containers, what people usually use Docker for: setting up an environment with well-known package versions that are the dependencies of your project.

As a very simple example, I've written a simple setup for running a chosen PostgreSQL version inside a directory: https://code.more-magic.net/ppq/about/. You could easily build this out by adding additional software, for example if you add Python and Django from Nixpkgs to this, you'd have a complete self-contained (or "sandboxed") dev environment.

When you're done developing on the project, you simple remove the repo and the entire environment is dropped too.

At work we use something like the above, with Java and Clojure and a whole bunch of other software, all completely self-contained. I never had to install any of it globally and didn't have to mess around with $JAVA_HOME etc.

Re:My First Impressions of Nix by SuperSandro2000 on Monday June 19, 2023 @09:50AM (#36391084)
> Nixpkg is a package manager

*Nix

Re:My First Impressions of Nix by Cloudef on Monday June 19, 2023 @11:37PM (#36399429)
Technically nixpkgs as just nix would be pretty useless. Nixpkgs is much more than just package derivations, it contains a whole standard library for the language.
Re:My First Impressions of Nix by rgoulter on Monday June 19, 2023 @05:55AM (#36389200)
> Which widely used, existing software tools is it analogous to?

It's kinda like Docker, but without the images/containers.

Docker solves two problems: distributing the same program everywhere, and running those programs using containers.

Nix solves the former problem. But, since it doesn't use containers, you can run the Nix packages without needing to worry about mounting into VMs or containers.

Re:My First Impressions of Nix by SuperSandro2000 on Monday June 19, 2023 @09:50AM (#36391075)
> Is it a package manager?

Yes

> A build system?

No

> An operating system?

Thats NixOS

> A container platform?

nixpkgs has functions to build them

> A sandbox?

No

> An automation tool?

Yes and no

> Which widely used, existing software tools is it analogous to?

Arch Linux plus Haskell plus Ansible plus better

Re:My First Impressions of Nix by superkuh on Monday June 19, 2023 @10:09AM (#36391279)
Nix is a distro that admits defeat against dependency management and entirely gives up on the idea of having system libraries. Instead every application you want to run has to have all of it's dependencies explicitly stated and provided custom in nix style configs for each program. Usually this means someone else has done all this packaging work for you. They hate it when people call it containerization but it's effectively taking containerization to the extreme for every single bit of software on your system with no ability to not use containers.

But if, say, you want to compile a random C program you found on the web then it is up to your to now set up the build environment and provide all the libraries and deps to be able to compile and then run the program. Just running make or ./configure or cmake . isn't going to do it because those configuration setups won't have a system lib environment to check against. It seems like a really weird distro to chose as your desktop but makes fine sense in commercial enterprises we're you're going to re-build the world for all your software anyway.

Re:My First Impressions of Nix by lolinder on Monday June 19, 2023 @10:46AM (#36391657)
I think you're thinking of NixOS, which is a distro based on Nix. Nix itself is not a distro.

Ironically, this further emphasizes how confusing the project is (projects are?).

Re:My First Impressions of Nix by cayley_graph on Monday June 19, 2023 @10:50AM (#36391712)
Well, sure, but setting up the build environment is pretty easy! You just specify the libraries as you normally would, and it works. The only difference is that those libraries are only available to that package, and not globally. The function `stdenv.mkDerivation` will actually build a standard ./configure && make style C project for you if you provide it some package source, you just have to copy out the build artifacts (with something like (cp project bin/project) and specify a list of libraries needed at build/runtime.

Agree that the documentation for all of this could be a lot better and more discoverable. It's good once you get over the initial hump though.

Re:My First Impressions of Nix by juped on Monday June 19, 2023 @01:41PM (#36394170)
This is the opposite of "pretty easy". (Apologies if I'm just failing to detect sarcasm.)
Re:My First Impressions of Nix by duped on Monday June 19, 2023 @10:50AM (#36391720)
> They hate it when people call it containerization but it's effectively taking containerization to the extreme for every single bit of software on your system with no ability to not use containers.

It's not containerization - containerization means something very specific (user namespaces + chroot). It may attack some of the same problems, but it is not a container.

The sandbox that nix builds run within is more or less a container, however.