Use FlakeHub and FlakeHub Cache through JFrog Artifactory
Many organizations route third-party packages and other artifacts through JFrog Artifactory, and because it supports Nix, you can use it to fetch flake sources from FlakeHub and cached artifacts from FlakeHub Cache as well.
This guide shows you how to:
- Proxy FlakeHub (including FlakeHub Cache) through an Artifactory Nix remote repository
- Configure Determinate Nix to use FlakeHub via Artifactory
- Handle flake tarballs, private flakes, and token rotation in conjunction with your Artifactory installation
How Artifactory and FlakeHub interact
FlakeHub serves two kinds of traffic, flake sources and binary cache artifacts, and Artifactory proxies each with its own type of repository:
| Traffic | FlakeHub host | What it serves | Artifactory repository type |
|---|---|---|---|
| Flake sources | flakehub.com, api.flakehub.com | Flake tarballs such as https://flakehub.com/f/my-org/my-flake/=0.1.5 | Generic remote repository |
| Binary cache artifacts | cache.flakehub.com | Nix store paths (.narinfo files and Nix archives, or NARs) | Nix remote repository |
The diagram above shows how both types of traffic are handled. In both cases, Artifactory fetches from FlakeHub only once—authenticated with a FlakeHub device token—and serves later requests from its own cache.
Artifactory remote repositories are read-only, so you can’t, for example, publish flakes or push to FlakeHub Cache through Artifactory. Systems that push or publish—usually CI systems—need direct access to FlakeHub and must log in to FlakeHub as usual.
Prerequisites
In order to use Artifactory in conjunction with FlakeHub, you’ll need:
-
A FlakeHub organization on a paid plan. FlakeHub Cache is available only on paid plans.
-
An Artifactory instance with native Nix repository support:
- Self-managed: version 7.146.22 or later
- Artifactory Cloud: 7.160.0 or later
Earlier versions of Artifactory return 404 errors for
.nar.zstfiles, which is a problem given that modern Nix caches like FlakeHub Cache serve zstd-compressed NARs. -
Determinate Nix installed on at least one machine so that you can generate device tokens with Determinate Nixd.
-
Admin access to Artifactory or a project admin who can create repositories.
Set up Artifactory
Create a FlakeHub device token for Artifactory
Artifactory needs to authenticate to FlakeHub using a device token. Device tokens are tied to your FlakeHub organization and are valid for 90 days or until you revoke them, whichever comes first.
You can create a device token in the FlakeHub UI or on the command line:
FLAKEHUB_TOKEN="$(determinate-nixd auth token device create \
--org my-org \
--description "Artifactory upstream (prod)")"This command prints the token to standard output, which this example captures in the FLAKEHUB_TOKEN variable.
We recommend storing this token in your secrets manager right away, as you won’t be able to retrieve it later.
Before you configure Artifactory, confirm that the token works directly against FlakeHub Cache:
curl --fail -u "flakehub:${FLAKEHUB_TOKEN}" \
https://cache.flakehub.com/nix-cache-infoYou should see a brief response that includes StoreDir: /nix/store.
If you get a 401, that means that FlakeHub didn’t accept the token.
The most common cause is an empty FLAKEHUB_TOKEN: only organization admins can create device tokens, and the create command fails for anyone else.
If FLAKEHUB_TOKEN isn’t empty, create a new token and run the check again.
We recommend not going further until this check passes.
Artifactory’s error messages for upstream authentication failures are generally much less helpful than the ones that cURL provides.
FlakeHub Cache enforces read access on a per-flake basis. Whatever this token can read, any Artifactory user with read access to the repository can read as well.
Create a Nix remote repository for FlakeHub Cache
See JFrog’s Nix repository documentation for a full listing of settings. In Artifactory, go to Administration → Repositories → Create a Repository → Remote, choose Nix, and set these values:
| Setting | Value |
|---|---|
| Repository key | flakehub-cache-remote |
| URL | https://cache.flakehub.com |
| Username | flakehub |
| Password / access token | The device token from the previous step |
If you manage Artifactory with Terraform, the equivalent may go something like this:
resource "artifactory_remote_nix_repository" "flakehub_cache" {
key = "flakehub-cache-remote"
url = "https://cache.flakehub.com"
username = "flakehub"
password = var.flakehub_device_token
description = "Proxy for FlakeHub Cache"
}Keep in mind that Artifactory remote repositories are proxies, not mirrors. Artifactory doesn’t prefetch anything. A store path fetched from FlakeHub Cache lands in Artifactory’s cache only when a Nix client successfully pulls it for the first time.
Configure Determinate Nix to use Artifactory
Each system that uses Artifactory instead of reaching FlakeHub directly, such as a developer laptop, CI runner, or server, needs two things: credentials for Artifactory itself and the substituter URL. These systems never need FlakeHub credentials, because Artifactory authenticates to FlakeHub on their behalf with the device token that you gave it.
Authenticate to Artifactory
Your systems authenticate to Artifactory, not to FlakeHub, so the credentials in this step are an Artifactory user and access token with read access to your repositories. Don’t use the FlakeHub device token here. If your Artifactory instance allows anonymous read access to these repositories, you can skip this step.
Determinate Nixd manages its own netrc file at /nix/var/determinate/netrc, and you should never edit it.
Instead, put your Artifactory credentials in a separate netrc file and tell Determinate Nixd to merge it in.
Create /etc/determinate/netrc.artifactory, readable only by root:
machine artifactory.example.com login nix-reader password <artifactory-access-token>The netrc file must not be in the Nix store.
Then list it under additionalNetrcSources in /etc/determinate/config.json:
{
"authentication": {
"additionalNetrcSources": ["/etc/determinate/netrc.artifactory"]
}
}We recommend a netrc file over embedding user:token@ in the substituter URL.
These substituter URLs are likely to end up in logs, error messages, and nix config show output, while netrc files don’t.
Set the substituter
Add the Artifactory repository to /etc/nix/nix.custom.conf:
substituters = https://artifactory.example.com/artifactory/api/nix/flakehub-cache-remote?priority=20A few notes on these settings:
substitutersreplaces Nix’s default list, which removescache.nixos.org. It doesn’t remove FlakeHub Cache, though: Determinate Nix manages/etc/nix/nix.confand adds FlakeHub Cache withextra-substitutersafter it readsnix.custom.conf.priority=20puts Artifactory ahead of FlakeHub Cache, which has a priority of 39, so Nix asks Artifactory first and only tries FlakeHub Cache directly when Artifactory doesn’t have a path.- Don’t set
trusted-public-keys. Artifactory passes FlakeHub Cache’s signatures through, and Determinate Nix already trusts FlakeHub Cache’s signing keys, so Nix verifies every store path without any extra configuration.
Restart Determinate Nixd
Restart the daemon so that it picks up the new configuration and netrc file:
sudo launchctl kickstart -k system/systems.determinate.nix-daemonsudo systemctl restart nix-daemon.serviceThen confirm that Nix sees what you expect:
nix config show substitutersYou should see your Artifactory URL in the list, along with substituters that Determinate Nix adds on its own, such as cache.flakehub.com or install.determinate.systems.
Those have a priority of 39, so with priority=20, Nix always asks Artifactory first.
On machines that should reach FlakeHub only through Artifactory, don’t log in to FlakeHub directly, so that they have no FlakeHub credentials of their own.
Flake sources
Your systems can fetch flake sources, such as https://flakehub.com/f/my-org/my-flake/=0.1.5, through Artifactory as well.
In Artifactory, create a Generic remote repository and set these values:
| Setting | Value |
|---|---|
| Repository key | flakehub-remote |
| URL | https://api.flakehub.com |
| Username | flakehub |
| Password / access token | The same device token as flakehub-cache-remote |
Set the URL to https://api.flakehub.com, not https://flakehub.com.
FlakeHub redirects flake URLs from flakehub.com to api.flakehub.com, and Artifactory doesn’t send the repository’s credentials along when a redirect changes hosts.
If you use https://flakehub.com, FlakeHub sees an unauthenticated request and responds with a 402 error.
One repository serves every flake that its device token can read, private flakes included.
To fetch a flake through it, replace https://flakehub.com in the flake’s URL with the repository’s URL:
| Through | URL |
|---|---|
| FlakeHub directly | https://flakehub.com/f/my-org/my-flake/=0.1.5 |
| Your Artifactory instance | https://artifactory.example.com/artifactory/flakehub-remote/f/my-org/my-flake/=0.1.5 |
Artifactory caches each response by URL, so a version constraint like 0.1, which can resolve to many potential releases, continues to return the release it first matched, even after you publish newer ones.
We recommend pinning to an exact version like =0.1.5 instead, and changing it when you want to upgrade.
To check the repository from a system inside your network, first fetch a flake with cURL, using your Artifactory credentials:
sudo curl --fail --location \
--netrc-file /etc/determinate/netrc.artifactory \
--output /dev/null --write-out '%{http_code}\n' \
"https://artifactory.example.com/artifactory/flakehub-remote/f/my-org/my-flake/=0.1.5"You should see 200.
Opening the same URL in a browser that’s signed in to Artifactory downloads the flake’s source tarball.
Then confirm that Nix can evaluate the flake through Artifactory:
nix flake show "https://artifactory.example.com/artifactory/flakehub-remote/f/my-org/my-flake/=0.1.5"Before you roll it out, run nix flake lock against it and check that the URLs in flake.lock point at Artifactory.
Resolved store paths
For deployments, you can go a step further and skip flake sources entirely with resolved store paths.
Your CI builds the flake and publishes it to FlakeHub, and the machines that you deploy to ask FlakeHub for the exact store path of a given release and then fetch it from the binary cache.
Behind Artifactory, that fetch goes through flakehub-cache-remote like everything else, so your servers never need to evaluate a flake or download its source.
If your resolution step needs to run on machines that can’t reach FlakeHub at all, run it in CI and pass the resolved store path along with the deployment.
Rotate the device token
Device tokens expire after 90 days. If the token in Artifactory expires, every cache miss for FlakeHub paths fails with an upstream 401, while paths already in Artifactory’s cache keep working. That can make the failure look intermittent, so it’s best to automate rotation.
Here’s an example rotation script that you can run at some regular interval from a machine logged in to FlakeHub as an organization admin:
#!/usr/bin/env bash
set -euo pipefail
ORG="my-org"
# Every remote repository that uses the device token
REPO_KEYS=("flakehub-cache-remote" "flakehub-remote")
ARTIFACTORY_URL="https://artifactory.example.com/artifactory"
# 1. Mint a new device token
NEW_TOKEN="$(determinate-nixd auth token device create \
--org "$ORG" \
--description "Artifactory upstream $(date -u +%Y-%m-%d)")"
# 2. Check it before touching Artifactory
curl --fail --silent -u "flakehub:${NEW_TOKEN}" \
https://cache.flakehub.com/nix-cache-info > /dev/null
# 3. Update each remote repository's upstream credentials
for REPO_KEY in "${REPO_KEYS[@]}"; do
curl --fail --silent -X POST \
-H "Authorization: Bearer ${ARTIFACTORY_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
"${ARTIFACTORY_URL}/api/repositories/${REPO_KEY}" \
-d "$(jq -n --arg pw "$NEW_TOKEN" '{username: "flakehub", password: $pw}')"
echo "Rotated upstream token for ${REPO_KEY}"
doneIf you proxy only FlakeHub Cache, list just flakehub-cache-remote in REPO_KEYS.
Once every repository uses the new token, revoke the old one:
determinate-nixd auth token device list --org my-org
determinate-nixd auth token device revoke --org my-org --token-id <old-token-uuid>If you manage Artifactory with Terraform, update the variable in your secrets store and run terraform apply instead of calling the Artifactory API directly.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 from Artifactory itself | The client’s netrc file is missing or not merged | Check additionalNetrcSources and restart Determinate Nixd |
| Upstream 401 in Artifactory logs, with new paths failing and old paths working | The device token expired or was revoked | Rotate the token |
| 402 errors when fetching a flake through Artifactory | The repository’s URL is https://flakehub.com, which redirects to api.flakehub.com without the repository’s credentials | Set the repository’s URL to https://api.flakehub.com |
| Flake inputs resolve to an old release | Artifactory cached the release that a version constraint first resolved to | Pin an exact version in the flake URL, or delete the cached path from the repository in Artifactory |
| Nix never finds a specific store path, even though it was pushed by CI | The device token’s identity can’t read that flake | Grant access in FlakeHub, or use a token with the right scope |
Clients still contact cache.flakehub.com directly | Determinate Nix always lists FlakeHub Cache, and Nix tries it when Artifactory doesn’t return a path | Check that the Artifactory URL has priority=20 and that Artifactory can reach FlakeHub |
| 404 errors when fetching a flake through Artifactory | The path after the repository’s URL isn’t a FlakeHub flake URL | Request /f/<org>/<flake>/<version> under the repository’s URL |
404 errors for .nar.zst files | Your Artifactory version predates zstd support for Nix | Upgrade to 7.146.22 or later (self-managed) or 7.160.0 or later (Artifactory Cloud) |