Skip to Content
GuidesFlakeHub through JFrog Artifactory

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:

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:

TrafficFlakeHub hostWhat it servesArtifactory repository type
Flake sourcesflakehub.com, api.flakehub.comFlake tarballs such as https://flakehub.com/f/my-org/my-flake/=0.1.5Generic remote repository
Binary cache artifactscache.flakehub.comNix store paths (.narinfo files and Nix archives, or NARs)Nix remote repository
FlakeHub and FlakeHub Cache through JFrog ArtifactoryYour systems fetch flake sources through flakehub-remote, an Artifactory remote repository for FlakeHub at api.flakehub.com, and substitute store paths through flakehub-cache-remote, an Artifactory remote repository for FlakeHub Cache at cache.flakehub.com. When a remote repository doesn't have what you asked for yet, it fetches it from FlakeHub once, authenticated with a FlakeHub device token, and keeps it. Later requests for the same thing never leave Artifactory.YOUR SYSTEMSDeveloper laptopsCI runnersServersJFROG ARTIFACTORYflakehub-remoteflakehub-cache-remoteFlakeHubapi.flakehub.comFlakeHub Cachecache.flakehub.com13231Fetch flake sources2Substitute store paths3Fetch anything not yet cached with a FlakeHub device token
FlakeHub and FlakeHub Cache using Artifactory as a proxy
FlakeHub and FlakeHub Cache using Artifactory as a proxy

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.zst files, 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:

Create a device token for Artifactory
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:

Check the token
curl --fail -u "flakehub:${FLAKEHUB_TOKEN}" \ https://cache.flakehub.com/nix-cache-info

You 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:

SettingValue
Repository keyflakehub-cache-remote
URLhttps://cache.flakehub.com
Usernameflakehub
Password / access tokenThe device token from the previous step

If you manage Artifactory with Terraform, the equivalent may go something like this:

artifactory.tf
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:

/etc/determinate/netrc.artifactory
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:

/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:

/etc/nix/nix.custom.conf
substituters = https://artifactory.example.com/artifactory/api/nix/flakehub-cache-remote?priority=20

A few notes on these settings:

  • substituters replaces Nix’s default list, which removes cache.nixos.org. It doesn’t remove FlakeHub Cache, though: Determinate Nix manages /etc/nix/nix.conf and adds FlakeHub Cache with extra-substituters after it reads nix.custom.conf.
  • priority=20 puts 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:

macOS
sudo launchctl kickstart -k system/systems.determinate.nix-daemon
Linux with systemd
sudo systemctl restart nix-daemon.service

Then confirm that Nix sees what you expect:

nix config show substituters

You 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:

SettingValue
Repository keyflakehub-remote
URLhttps://api.flakehub.com
Usernameflakehub
Password / access tokenThe 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:

ThroughURL
FlakeHub directlyhttps://flakehub.com/f/my-org/my-flake/=0.1.5
Your Artifactory instancehttps://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:

Fetch a flake through Artifactory
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:

Show a 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:

rotate-flakehub-token.sh
#!/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}" done

If 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

SymptomLikely causeFix
401 from Artifactory itselfThe client’s netrc file is missing or not mergedCheck additionalNetrcSources and restart Determinate Nixd
Upstream 401 in Artifactory logs, with new paths failing and old paths workingThe device token expired or was revokedRotate the token
402 errors when fetching a flake through ArtifactoryThe repository’s URL is https://flakehub.com, which redirects to api.flakehub.com without the repository’s credentialsSet the repository’s URL to https://api.flakehub.com
Flake inputs resolve to an old releaseArtifactory cached the release that a version constraint first resolved toPin 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 CIThe device token’s identity can’t read that flakeGrant access in FlakeHub, or use a token with the right scope
Clients still contact cache.flakehub.com directlyDeterminate Nix always lists FlakeHub Cache, and Nix tries it when Artifactory doesn’t return a pathCheck that the Artifactory URL has priority=20 and that Artifactory can reach FlakeHub
404 errors when fetching a flake through ArtifactoryThe path after the repository’s URL isn’t a FlakeHub flake URLRequest /f/<org>/<flake>/<version> under the repository’s URL
404 errors for .nar.zst filesYour Artifactory version predates zstd support for NixUpgrade to 7.146.22 or later (self-managed) or 7.160.0 or later (Artifactory Cloud)
Last updated on