Jump to content

Harmonia: Difference between revisions

From Official NixOS Wiki
Onny (talk | contribs)
Initial page
 
Onny (talk | contribs)
Update harmonia module usage
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[https://github.com/edolstra/nix-serve nix-serve] is a small utility to serve a Nix store as a binary cache, allowing it to be used as a substituter by other Nix installations.
[https://github.com/nix-community/harmonia harmonia] is a small utility to serve a Nix store as a [[Binary Cache|binary cache]], allowing it to be used as a substituter by other Nix installations.


=== Setup ===
=== Setup ===
First generate required public and private store keys.<syntaxhighlight lang="bash">
First generate required public and private store keys, in this example for the domain <code>cache.example.org</code>.<syntaxhighlight lang="bash">
mkdir -p /var/lib/nix-serve
mkdir -p /var/lib/harmonia
nix-store --generate-binary-cache-key cache.project-insanity.org-1 \
nix-store --generate-binary-cache-key cache.example.org-1 \
   /var/lib/nix-serve/cache-priv-key.pem \
   /var/lib/harmonia/cache-priv-key.pem \
   /var/lib/nix-serve/cache-pub-key.pem
   /var/lib/harmonia/cache-pub-key.pem
</syntaxhighlight>Add following snippet to your system configuration and apply it.<syntaxhighlight lang="nix">
services.harmonia = {
  cache.enable = true;
  signKeyPaths = [ "/var/lib/harmonia/cache-priv-key.pem" ];
};
</syntaxhighlight>The cache will be served on http://127.0.0.1:5000. It should be served with a web server such as [[Caddy]].


chown nix-serve:nix-serve /var/lib/nix-serve/cache-priv-key.pem
<syntaxhighlight lang="nix">
chmod 600 /var/lib/nix-serve/cache-priv-key.pem
services.caddy = {
chmod 644 /var/lib/nix-serve/cache-pub-key.pem
</syntaxhighlight>Add following snippet to your system configuration and apply it.<syntaxhighlight lang="nix">
services.nix-serve = {
   enable = true;
   enable = true;
   secretKeyFile = "/var/lib/nix-serve/cache-priv-key.pem";
   openFirewall = true;
  virtualHosts."cache.example.org".extraConfig = ''
    reverse_proxy 127.0.0.1:5000
  '';
};
};
</syntaxhighlight>The cache will be served on http://127.0.0.1:5000.
</syntaxhighlight>Visit https://cache.example.org where you'll also find instructions on how to setup the cache on a client.

Latest revision as of 09:51, 23 October 2026

harmonia is a small utility to serve a Nix store as a binary cache, allowing it to be used as a substituter by other Nix installations.

Setup

First generate required public and private store keys, in this example for the domain cache.example.org.

mkdir -p /var/lib/harmonia
nix-store --generate-binary-cache-key cache.example.org-1 \
  /var/lib/harmonia/cache-priv-key.pem \
  /var/lib/harmonia/cache-pub-key.pem

Add following snippet to your system configuration and apply it.

services.harmonia = {
  cache.enable = true;
  signKeyPaths = [ "/var/lib/harmonia/cache-priv-key.pem" ];
};

The cache will be served on http://127.0.0.1:5000. It should be served with a web server such as Caddy.

services.caddy = {
  enable = true;
  openFirewall = true;
  virtualHosts."cache.example.org".extraConfig = ''
    reverse_proxy 127.0.0.1:5000
  '';
};

Visit https://cache.example.org where you'll also find instructions on how to setup the cache on a client.