niche

niche creates and manages Nix caches backed by cloud blob storage. niche wraps nix build
to upload build artifacts as they're produced rather than waiting for a successful build.
Tested with: Azure, B2, S3, Wasabi, Google Storage (see here)
Please don't share this, it's got a bug in it still
features
-
wrapped nix build (upload as you build)
niche build wraps nix build and uploads each build result as they're produced. This allows you to cache successful subsets of builds, even if the full build ends up failing.
-
(local-) configuration-free!
The configuration for a niche cache (including storage credentials and signing key) is stored, encrypted, in the cache itself. Many users will never need to look at it!
-
sops - flexible, secure, shared-access to the signing key
niche uses the mozilla/sops tool, to encrypt and decrypt the configuration on-the-fly. It encrypts the config with multiple keys - (ex: GPG, AGE). It can also encrypt using cloud KMS providers, thereby delegating access control of the signing key to an auditable cloud resource.
-
easy (non-interactive, stateless) usage
The handling of key material and configuration is entirely hidden from the user in most cases. Any user with a valid key can upload without any other configuration.
As an example, consider builds.sr.ht where GPG integration is built in: Listing the fingerprint of a key enrolled with builds.sr.ht in the config file is all it takes to allow your jobs to be able to upload.
-
bring your own storage (Azure, Amazon, Google, Minio, Wasabi)
If stow (or rather, our fork of stow) supports it, so do we!
niche can manage Nix mirrors behind firewalls, in Internet-less virtual networks, leverage free internal bandwidth in cloud provider networks, etc.
install
from nixpkgs
It's available from nixpkgs as niche.
I would prefer this not be submitted to nixpkgs until the CLI is considered stable.
from source, via flake
- Install
nix.
- Activate
flakes.
- Add it to your
devenv.nix, your CI's shell.nix, or install it in your profile:
nix profile install 'github:colemickens/niche'
You can also use this repo as a nixpkgs tarball, with niche on top. I personally use this so that I can have niche and nixUnstable
available in a single nixpkgs that I can then use on arbitrary build machines with stable nix-shell:
nix-shell -I nixpkgs=https://github.com/colemickens/niche/archive/master.tar.gz -p niche -p nixUnstable
usage
create new niche cache
view public key
build and upload
Set NICHE_DEBUG to a non-empty value for the most verbose logging out.
accessing your cache
This step depends on how you choose to have your users acces your storage provider (kind), and depends on if you use a custom domain.
Most of the cloud storage providers allow for a custom domain pointed at a bucket. However, this usually requires falling back to HTTP. Some providers also offer a CDN service that can allow HTTPS with custom domains.
The following are examples of value would be used as <niche_url> in the usage:
- azure:
https://$AZURE_ACCOUNT_NAME.blob.core.windows.net/${CACHE_NAME}
azstrg01.blob.core.windows.net/cache (per the example above, omitting the optional https:// prefix)
http://cache.r10e.dev/cache (where cache.r10e.dev is a CNAME to the same full storage url, note the http)
nixcache.r10e.dev (using Azure CDN for SSL)
- b2:
https://s3.${B2_REGION}.backblazeb2.com/${CACHE_NAME}
google: (see here)
storage.cloud.google.com/${CACHE_NAME}
- s3:
https://${CACHE_NAME}.s3.amazonaws.com
http://s3cache.r10e.dev (using CNAME)
s3cache.r10e.dev (using CloudFront)
- wasabi:
s3.wasabisys.com/${CACHE_NAME}
development
Development of niche is done with nix:
❯ git clone https://github.com/colemickens/niche
❯ nix build '.#'
❯ ./result/bin/niche --version # TODO: add a version command and log it during startups for bug report purposes
dirty
# TODO fix this up
thanks
donate
(left over readme)