Is NixOS a source distro or a binary distro, or both?

Does NixOS build everything from source or does it pull binaries, or both?

Both. Everything is nominally built from source; for most platforms, and most packages, most of the time, that can be bypassed using cached build output.

There will always be a small number of derivations built locally, but they’re usually small and relate to your specific config (hostnames, local users, running services etc).

If you disable the cache, or change some inputs in a way that everything misses the cache, you’ll build from source - either just the packages affected, or all of them if your change is fundamental (e.g. global compiler cpu-target flags)

2 Likes

Keep in mind how Nix actually works under the hood. The reason there’s a hash in the path names in /nix/store is because that hash encapsulates all the details of how to produce itself. i.e. The “derivation” details that produce the output are hashed and the output’s path includes that hash. So while (nearly) everything in nixpkgs is defined in terms of building it from source, each derivation has a unique hash which you can use to find “cached” archives of the outputs. That’s why you don’t have to build most things from source when you install or update NixOS; nixpkgs is telling Nix how to build the package from source, but Nix is instead just hashing those details that and checking for that unique hash on a binary cache (aka “substituter”) and just downloading the result from someone else who did the exact same build (all the way down to the hashes of its dependencies and their dependencies and so on). It’s a lot like a merkle tree.

If you want to build your whole OS from source yourself, as @uep said, you can disable substituters and Nix won’t be able to find that hash on a cache and it’ll just try to build it itself. On the opposite end of the spectrum, again as @uep said, there are negligible derivations that will be built locally just because they’re highly specific to your machine, like your custom systemd unit files or your initrd or your hostname file.

(As an aside, there are some things that aren’t built from source, but this is pretty rare, and it’s usually only done for non-free packages that don’t distribute sources and require you to enable allowUnfree = true anyway)

2 Likes

NixOS is clearly a source code distribution, but it provides a pre-populated build cache.

The package index is not a mapping from package names to tarballs[1] to download and extract as a Debian or Centos does.

Instead the package index provides build instructions, that can be “evaluated”, and that produces a hash. This hash then can be resolved to a prebuild artifact via the substitution process. If you disable substitution, or the hash is not found, Nix will build the artifact from source transparently.

Not like with apt where you have to “install” a source package manually, and you still can not easily create a usable “installable” from it, if a source package is provided at all…

Personally I do not see any room for calling NixOS a “binary distro”.

[1]: Tarball is used as a generic term for antything that is basically just a packed folder structure with maybe metadata attached one way or the other.

1 Like