Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Half-OT: How do Nix regsitries work? Can I host Nix packages via HTTP or do they use another protocol?


Nix is source-based. If you write your own "package definitions" you can distribute those in all the same ways you would use for source code, since they are source code. nixpkgs for example is a monorepo of many of those package definitions, among other things. Flakes are a (still experimental) approach to (among other things) streamline the options you have outside of nixpkgs inclusion.

If you also want to distribute pre-built binaries you would use a cache. https://cache.nixos.org/ is exactly that for nixpkgs. You can host your own via http(s), ssh or s3. There is also cachix, which is basically a hosting provider for nix caches that is pretty widespread in the community, I think.


e.g. I think it's common for users to share their config or sets of packages with something like a "nix user repository" https://github.com/nix-community/nur-packages-template


What about Nix Channels?


Channels are, AFAIU, a reference to some point-in-time/commit/version of nixpkgs. They are exposed in the form of branches in the nixpkgs repository and used in some other places as well. A channel has a set of conditions that need to be met for it to be advanced to a newer version of nixpkgs. For the nixpkgs-unstable channel, which follows the master branch, the packages it contains need to be built by hydra and be present in the global cache before it advances (I don't think this is true for all packages, but this is the general idea). This is to make sure that users who use packages from this channel will mostly find them in the cache (if you use master directly you can often run into packages that you need to compile yourself, because they are not yet present in the cache).

The stable channels are basically "just" branched of from master (or nixpkgs-unstable? not sure) when the given point release is due (there is more to it, for example there is an effort made to make all the packages contained in that release actually buildable, called "Zero Hydra Failures" or ZHF). They will then mostly stay that way apart from the odd backport for security reasons and the likes.

Basically, it is very similar to how a larger software project might be managed with a develop branch and older releases that still receive backports.

(This is my mental model of it anyway, as a user for a few years. There are probably details that might be a bit off or not exactly accurate.)


> Channels are, AFAIU, a reference to some point-in-time/commit/version of nixpkgs

It's not specifically nixpkgs, but any Nix code generally.

Per the Nix manual[0]:

> Channels are a mechanism for referencing remote Nix expressions and conveniently retrieving their latest version.

e.g. home-manager's suggested channel is just the github tarball for the relevant branch[1]:

  nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager

[0] https://nixos.org/manual/nix/stable/command-ref/nix-channel

[1] https://nix-community.github.io/home-manager/index.html#sec-...


Great clarification, and just to relate flakes: a flake input is like a package-local channel instead of being system-wide.


I believe they ultimately end up pointing at git repos.


To accompany the other comment, your Nix cache can be hosted by setting `services.nix-serve.enable = true`: https://nixos.wiki/wiki/Binary_Cache

You do not necessarily need nginx.


You can also configure the consumer to consume it over ssh without special setup on the host. But it opens a connection for every single request so it ends up killing the performance [1]

[1] - https://github.com/NixOS/nix/issues/8794


doesn't openssh controlmaster pretty much solve this?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: