1
0
Fork
You've already forked harmonia-ci-test
1
No description
  • Rust 65.7%
  • Nix 21.9%
  • C++ 10.9%
  • Shell 1.5%
Find a file
test 829e4a41db
Some checks failed
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
test
2024年09月21日 23:14:53 +02:00
.github chore(deps): bump DeterminateSystems/update-flake-lock from 21 to 22 2024年06月03日 17:00:18 +00:00
harmonia chore(deps): bump actix-files from 0.6.5 to 0.6.6 2024年06月11日 06:54:53 +00:00
libnixstore Implemented rewrite to real path in dump_path 2024年04月18日 11:27:30 +00:00
scripts create-release.sh: apply correct prefix 2023年08月07日 11:13:21 +02:00
tests Implemented rewrite to real path in dump_path 2024年04月18日 11:27:30 +00:00
.clang-format init 2022年03月09日 11:06:22 +00:00
.envrc add envrc 2023年01月28日 11:43:42 +01:00
.gitignore Add .direnv to .gitignore 2023年08月16日 17:29:42 +02:00
.mergify.yml fix mergify configuration 2024年04月23日 11:24:23 +02:00
Cargo.lock chore(deps): bump cxx from 1.0.122 to 1.0.123 2024年06月11日 07:02:08 +00:00
Cargo.toml upgrade resolver to 2 2023年11月12日 13:00:02 +00:00
default.nix pin nixpkgs in nix-build/nix-shell 2024年03月21日 14:49:39 +00:00
flake.lock flake.lock: Update 2024年04月25日 01:23:34 +00:00
flake.nix test 2024年09月18日 19:29:54 +02:00
garnix.yaml garnix: disable nixos tests 2023年08月07日 11:10:03 +02:00
LICENSE license: update owner 2022年08月11日 17:10:42 +02:00
module.nix Make nix, package configurable. 2023年08月12日 08:21:13 +00:00
number.nix test 2024年08月13日 20:29:48 +02:00
README.md harmonia: Re-order a bit for clarity 2024年03月13日 08:38:36 +00:00
shell.nix pin nixpkgs in nix-build/nix-shell 2024年03月21日 14:49:39 +00:00

harmonia

Harmonia is a binary cache for nix that serves your /nix/store as a binary cache over http. It's written in Rust for speed.

Features

  • http-ranges support for nar file streaming
  • streaming build logs
  • .ls file streaming
    • Note: doesn't contain narOffset in json response but isn't needed for nix-index
  • Add /serve/<narhash>/ endpoint to allow serving the content of package. Also discovers index.html to allow serving websites directly from the nix store.

Configuration for public binary cache on NixOS

Since NixOS 23.05, there is a module for harmonia in nixpkgs. The following example set's up harmonia as a public binary cache using nginx as a frontend webserver with https encryption and zstd for compression:

{ config, pkgs, ... }: {
 services.harmonia.enable = true;
 # FIXME: generate a public/private key pair like this:
 # $ nix-store --generate-binary-cache-key cache.yourdomain.tld-1 /var/lib/secrets/harmonia.secret /var/lib/secrets/harmonia.pub
 services.harmonia.signKeyPath = "/var/lib/secrets/harmonia.secret";
 # Example using sops-nix to store the signing key
 #services.harmonia.signKeyPath = config.sops.secrets.harmonia-key.path;
 #sops.secrets.harmonia-key = { };
 # optional if you use allowed-users in other places
 #nix.settings.allowed-users = [ "harmonia" ];
 networking.firewall.allowedTCPPorts = [ 443 80 ];
 # FIXME: replace this with your own email
 security.acme.defaults.email = "yourname@youremail.com";
 security.acme.acceptTerms = true;
 services.nginx = {
 enable = true;
 package = pkgs.nginxStable.override {
 modules = [ pkgs.nginxModules.zstd ];
 };
 recommendedTlsSettings = true;
 recommendedZstdSettings = true;
 # FIXME: replace "cache.yourdomain.tld" with your own domain.
 virtualHosts."cache.yourdomain.tld" = {
 enableACME = true;
 forceSSL = true;
 locations."/".extraConfig = ''
 proxy_pass http://127.0.0.1:5000;
 proxy_set_header Host $host;
 proxy_redirect http:// https://;
 proxy_http_version 1.1;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection $connection_upgrade;
 zstd on;
 zstd_types application/x-nix-archive;
 '';
 };
 };
}

You can use the binary cache on a different machine using the following NixOS configuration:

{
 nix.settings = {
 substituters = [ "https://cache.yourdomain.tld" ];
 # FIXME replace the key with the content of /var/lib/secrets/harmonia.pub
 trusted-public-keys = [ "cache.yourdomain.tld-1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" ];
 };
}

Configuration format

Configuration is done via a toml file. Hint: You don't need to interface with the configuration directly in case you are using the NixOS module. The location of the configuration file should be passed as env var CONFIG_FILE. If no config file is passed the following default values will be used:

# default ip:hostname to bind to
bind = "[::]:5000"
# Sets number of workers to start in the webserver
workers = 4
# Sets the per-worker maximum number of concurrent connections.
max_connection_rate = 256
# binary cache priority that is advertised in /nix-cache-info
priority = 30

Per default we wont sign any narinfo because we don't have a secret key, to enable this feature enable it by providing a path to a private key generated by nix-store --generate-binary-cache-key cache.example.com-1 /etc/nix/cache.secret /etc/nix/cache.pub

# nix binary cache signing key
sign_key_path = "/run/secrets/cache.secret"

harmonia will fallback to the SIGN_KEY_PATH environment if sign_key_path is not set in configuration.

Logging can be configured with env_logger. The default value is info,actix_web=debug. To only log errors use the following RUST_LOG=error and to only disable access logging, use RUST_LOG=info,actix_web::middleware=error

Build

Whole application

nix build -L

Get a development environment:

nix develop

Run tests

nix flake check -L

Inspiration