<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.justus.pw/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Attic_on_Nix_Darwin</id>
	<title>Attic on Nix Darwin - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.justus.pw/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Attic_on_Nix_Darwin"/>
	<link rel="alternate" type="text/html" href="https://www.justus.pw/mediawiki/index.php?title=Attic_on_Nix_Darwin&amp;action=history"/>
	<updated>2026-05-25T02:35:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.3</generator>
	<entry>
		<id>https://www.justus.pw/mediawiki/index.php?title=Attic_on_Nix_Darwin&amp;diff=86&amp;oldid=prev</id>
		<title>Justus: Add to Garden</title>
		<link rel="alternate" type="text/html" href="https://www.justus.pw/mediawiki/index.php?title=Attic_on_Nix_Darwin&amp;diff=86&amp;oldid=prev"/>
		<updated>2026-01-30T06:50:58Z</updated>

		<summary type="html">&lt;p&gt;Add to Garden&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 06:50, 30 January 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l262&quot;&gt;Line 262:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 262:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* attic NixOS configuration: https://github.com/zhaofengli/attic/blob/main/nixos/atticd.nix&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* attic NixOS configuration: https://github.com/zhaofengli/attic/blob/main/nixos/atticd.nix&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* How to serve and configure Nix store (not cache) via HTTP: https://nix.dev/manual/nix/2.18/package-management/binary-cache-substituter&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* How to serve and configure Nix store (not cache) via HTTP: https://nix.dev/manual/nix/2.18/package-management/binary-cache-substituter&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Garden]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Justus</name></author>
	</entry>
	<entry>
		<id>https://www.justus.pw/mediawiki/index.php?title=Attic_on_Nix_Darwin&amp;diff=85&amp;oldid=prev</id>
		<title>Justus: Created page with &quot;Here are some snippets of code required to configure and run [https://docs.attic.rs/ attic] on macOS with [https://github.com/LnL7/nix-darwin &lt;code&gt;nix-darwin&lt;/code&gt;], and use it as an optional cache.  &lt;span id=&quot;files-required&quot;&gt;&lt;/span&gt; = Files required =  To make &lt;code&gt;nix-darwin&lt;/code&gt; configure attic correctly, you need a configuration module̵ &lt;code&gt;attic.nix&lt;/code&gt; and a configuration &lt;code&gt;atticd.toml&lt;/code&gt; for attic to use during runtime to use the correct paths f...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.justus.pw/mediawiki/index.php?title=Attic_on_Nix_Darwin&amp;diff=85&amp;oldid=prev"/>
		<updated>2026-01-30T05:01:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Here are some snippets of code required to configure and run [https://docs.attic.rs/ attic] on macOS with [https://github.com/LnL7/nix-darwin &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt;], and use it as an optional cache.  &amp;lt;span id=&amp;quot;files-required&amp;quot;&amp;gt;&amp;lt;/span&amp;gt; = Files required =  To make &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; configure attic correctly, you need a configuration module̵ &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt; and a configuration &amp;lt;code&amp;gt;atticd.toml&amp;lt;/code&amp;gt; for attic to use during runtime to use the correct paths f...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Here are some snippets of code required to configure and run [https://docs.attic.rs/ attic] on macOS with [https://github.com/LnL7/nix-darwin &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt;], and use it as an optional cache.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;files-required&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Files required =&lt;br /&gt;
&lt;br /&gt;
To make &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; configure attic correctly, you need a configuration module̵ &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt; and a configuration &amp;lt;code&amp;gt;atticd.toml&amp;lt;/code&amp;gt; for attic to use during runtime to use the correct paths for storage.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;user-creation&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= User creation =&lt;br /&gt;
&lt;br /&gt;
First, create a user and group called &amp;lt;code&amp;gt;attic&amp;lt;/code&amp;gt; to host the attic server on your machine. In the &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt; file, add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;# attic.nix&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  users.groups.attic = {&lt;br /&gt;
    # Adjust the gid to your liking&lt;br /&gt;
    gid = 603;&lt;br /&gt;
  };&lt;br /&gt;
  users.users.attic = {&lt;br /&gt;
    createHome = false;&lt;br /&gt;
    description = &amp;quot;attic user&amp;quot;;&lt;br /&gt;
    gid = 603;&lt;br /&gt;
    # Adjust the uid to your liking&lt;br /&gt;
    uid = 603;&lt;br /&gt;
    isHidden = true;&lt;br /&gt;
  };&lt;br /&gt;
  users.knownGroups = [ &amp;quot;attic&amp;quot; ];&lt;br /&gt;
  users.knownUsers = [ &amp;quot;attic&amp;quot; ];&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This Nix configuration hides the attic user, and it can’t log in since shell set to &amp;lt;code&amp;gt;sbin/nologin&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;attic-configuration&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Attic configuration =&lt;br /&gt;
&lt;br /&gt;
Create a configuration file &amp;lt;code&amp;gt;atticd.toml&amp;lt;/code&amp;gt; and add the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;toml&amp;quot;&amp;gt;# atticd.toml&lt;br /&gt;
# Socket address to listen on, you might want to adjust the port used.&lt;br /&gt;
listen = &amp;amp;quot;127.0.0.1:18080&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Optionally, configure allowed hosts here&lt;br /&gt;
allowed-hosts = []&lt;br /&gt;
&lt;br /&gt;
[database]&lt;br /&gt;
# Attic&amp;#039;s database is located in /var/attic/db.sqlite&lt;br /&gt;
url = &amp;amp;quot;sqlite:///var/attic/db.sqlite?mode=rwc&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Whether to enable sending on periodic heartbeat queries&lt;br /&gt;
#&lt;br /&gt;
# If enabled, a heartbeat query will be sent every minute&lt;br /&gt;
#heartbeat = false&lt;br /&gt;
&lt;br /&gt;
[storage]&lt;br /&gt;
# Store everything locally in /var/attic/storage&lt;br /&gt;
type = &amp;amp;quot;local&amp;amp;quot;&lt;br /&gt;
path = &amp;amp;quot;/var/attic/storage&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Default values from&lt;br /&gt;
# https://github.com/zhaofengli/attic/blob/main/server/src/config-template.toml&lt;br /&gt;
[chunking]&lt;br /&gt;
nar-size-threshold = 65536 # chunk files that are 64 KiB or larger&lt;br /&gt;
min-size = 16384            # 16 KiB&lt;br /&gt;
avg-size = 65536            # 64 KiB&lt;br /&gt;
max-size = 262144           # 256 KiB&lt;br /&gt;
&lt;br /&gt;
[compression]&lt;br /&gt;
type = &amp;amp;quot;zstd&amp;amp;quot;&lt;br /&gt;
#level = 8&lt;br /&gt;
&lt;br /&gt;
[garbage-collection]&lt;br /&gt;
# The frequency to run garbage collection at&lt;br /&gt;
interval = &amp;amp;quot;12 hours&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Write the attic configuration to &amp;lt;code&amp;gt;/etc/attic/atticd.toml&amp;lt;/code&amp;gt; using the following Nix snippet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;# attic.nix&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  # ...&lt;br /&gt;
  environment.etc = {&lt;br /&gt;
    atticd = {&lt;br /&gt;
      source = ./atticd.toml;&lt;br /&gt;
      target = &amp;quot;attic/atticd.toml&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
  # ...&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;credentials-file&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Credentials file =&lt;br /&gt;
&lt;br /&gt;
Next, feed 32 bytes of random data into &amp;lt;code&amp;gt;base64&amp;lt;/code&amp;gt;. Pipe these 32 bytes into a secret, read-only file that only &amp;lt;code&amp;gt;attic&amp;lt;/code&amp;gt; can open:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;openssl rand 32 |&lt;br /&gt;
  base64 |&lt;br /&gt;
  sudo tee /etc/attic/secret.base64 &amp;gt; /dev/null&lt;br /&gt;
sudo chown attic:attic /etc/attic/secret.base64&lt;br /&gt;
sudo chmod 400 /etc/attic/secret.base64&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;attic-service-file&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Attic service file =&lt;br /&gt;
&lt;br /&gt;
Next, tell &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; to add a launchd service using the following snippet in the same &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;# attic.nix&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
let&lt;br /&gt;
  logPath = &amp;quot;/var/log/atticd&amp;quot;;&lt;br /&gt;
  attic-client = pkgs.attic-client;&lt;br /&gt;
  attic-server = pkgs.attic-server;&lt;br /&gt;
in&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    attic-client&lt;br /&gt;
    attic-server&lt;br /&gt;
  ];&lt;br /&gt;
  launchd.daemons.attic = {&lt;br /&gt;
    script = &amp;#039;&amp;#039;&lt;br /&gt;
      ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64=&amp;quot;$(cat /etc/attic/secret.base64)&amp;quot;&lt;br /&gt;
      export ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64&lt;br /&gt;
      exec ${attic-server}/bin/atticd --config /etc/attic/atticd.toml&lt;br /&gt;
    &amp;#039;&amp;#039;;&lt;br /&gt;
    serviceConfig = {&lt;br /&gt;
      KeepAlive = true;&lt;br /&gt;
      StandardOutPath = &amp;quot;${logPath}/attic.stdout.log&amp;quot;;&lt;br /&gt;
      StandardErrorPath = &amp;quot;${logPath}/attic.stderr.log&amp;quot;;&lt;br /&gt;
      UserName = &amp;quot;attic&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The preceding launchd daemon script reads the attic secret token into an environment variable and starts the attic server using the configuration stored in &amp;lt;code&amp;gt;atticd.toml&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Make sure that you have a attic runtime directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;sudo mkdir -m700 /var/attic&lt;br /&gt;
sudo chown attic:attic /var/attic&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;configuring-the-client&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Configuring the client =&lt;br /&gt;
&lt;br /&gt;
Import &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt; into your main &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;# darwin-configuration.nix&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  imports = [&lt;br /&gt;
    # ...&lt;br /&gt;
    ./attic.nix&lt;br /&gt;
    # ...&lt;br /&gt;
  ];&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then, rebuild your &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; system using &amp;lt;code&amp;gt;darwin-rebuild switch&amp;lt;/code&amp;gt;. On my system, I use the following invocation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;darwin-rebuild switch --flake $DOTFILES/nix/generic&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Next, create a JSON Web Token (JWT) for a cache named after your computer’s name. You can use this JWT with your local Nix builder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;sudo -u attic \&lt;br /&gt;
  ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64=&amp;quot;$(sudo -u attic cat /etc/attic/secret.base64)&amp;quot; \&lt;br /&gt;
  atticadm make-token \&lt;br /&gt;
  --config /etc/attic/atticd.toml \&lt;br /&gt;
  --sub &amp;quot;$(hostname)&amp;quot; \&lt;br /&gt;
  --validity &amp;quot;1 month&amp;quot; \&lt;br /&gt;
  --pull &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --push &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --delete &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --create-cache &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --configure-cache &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --configure-cache-retention &amp;quot;$(hostname)-*&amp;quot; \&lt;br /&gt;
  --destroy-cache &amp;quot;$(hostname)-*&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The JWT created in his preceding &amp;lt;code&amp;gt;make-token&amp;lt;/code&amp;gt; command has broad permissions. Please adjust permissions to your liking. attic outputs the JWT token in your shell session.&lt;br /&gt;
&lt;br /&gt;
Finally, try logging in with the generated token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;# Port configured in atticd.toml&lt;br /&gt;
attic login &amp;quot;$(hostname)&amp;quot; http://127.0.0.1:18080 &amp;quot;$YOUR_TOKEN&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Did it work? Great. To tell the Nix builder to use attic as its cache, it needs to have credentials available in a &amp;lt;code&amp;gt;netrc&amp;lt;/code&amp;gt; file. Furthermore, you need to add the cache’s public key as a trusted key.&lt;br /&gt;
&lt;br /&gt;
First, retrieve the public key and &amp;lt;code&amp;gt;netrc&amp;lt;/code&amp;gt; file. The preceding &amp;lt;code&amp;gt;attic login&amp;lt;/code&amp;gt; invocation created a &amp;lt;code&amp;gt;config.toml&amp;lt;/code&amp;gt; file in &amp;lt;code&amp;gt;$HOME/.config/attic&amp;lt;/code&amp;gt;, which conveniently contains the JWT token for a &amp;lt;code&amp;gt;netrc&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;# This will try to grab the netrc information that attic created after logging&lt;br /&gt;
# in&lt;br /&gt;
sed -n -E -e &amp;#039;s/token = &amp;quot;(.+)&amp;quot;/machine .+\npassword \1/p&amp;#039; \&lt;br /&gt;
  $HOME/.config/attic/config.toml |&lt;br /&gt;
  sudo tee /etc/nix/netrc&lt;br /&gt;
sudo chmod 440 /etc/nix/netrc&lt;br /&gt;
# Let me know if this sed expression worked&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can show the public key using &amp;lt;code&amp;gt;attic cache info&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;attic cache info &amp;quot;$(hostname)-default&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You should see the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;               Public: false&lt;br /&gt;
           Public Key: XXXXXXX-default:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;br /&gt;
Binary Cache Endpoint: https://XXXXXXXXXXXXX:18080/XXXXXXX-default&lt;br /&gt;
         API Endpoint: https://XXXXXXXXXXXXX:18080/&lt;br /&gt;
      Store Directory: /nix/store&lt;br /&gt;
             Priority: 41&lt;br /&gt;
  Upstream Cache Keys: [&amp;amp;quot;cache.nixos.org-1&amp;amp;quot;]&lt;br /&gt;
     Retention Period: Global Default&amp;lt;/pre&amp;gt;&lt;br /&gt;
Store the preceding information in &amp;lt;code&amp;gt;attic.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;# attic.nix&lt;br /&gt;
{ ... } :&lt;br /&gt;
let&lt;br /&gt;
  # make sure to insert the correct hostname here:&lt;br /&gt;
  hostname = &amp;quot;your-hostname&amp;quot;;&lt;br /&gt;
  # Insert the public key that you have created in the previous step&lt;br /&gt;
  public-key = &amp;quot;&amp;quot;;&lt;br /&gt;
  # Make sure the hostname, port, and cache name are correct&lt;br /&gt;
  cache-url = &amp;quot;http://127.0.0.1:18080/${hostname}-default&amp;quot;;&lt;br /&gt;
in&lt;br /&gt;
{&lt;br /&gt;
  nix.settings.substituters = [ cache-url ];&lt;br /&gt;
  nix.settings.trusted-public-keys = [&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;${hostname}-default:${public-key}&amp;quot;&lt;br /&gt;
  ];&lt;br /&gt;
  nix.settings.trusted-substituters = [ cache-url ];&lt;br /&gt;
  # This file was created using the preceding sed script&lt;br /&gt;
  nix.settings.netrc-file = &amp;quot;/etc/nix/netrc&amp;quot;;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;testing-the-cache&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Testing the cache =&lt;br /&gt;
&lt;br /&gt;
Now, rebuild &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt; one more time. Every time you run Nix commands after that, Nix consults the local attic cache first. You can try this with any command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;# This will look up hello in your local cache first&lt;br /&gt;
nix run nixpkgs#hello&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;troubleshooting&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
Does Nix complain that your local cache isn’t a binary cache? Check that you can access the attic cache using curl first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;# Might have copy the netrc file somewhere user-readable&lt;br /&gt;
curl --netrc-file /etc/nix/netrc -v -n \&lt;br /&gt;
  &amp;quot;http://localhost:18080/$(hostname)-default/nix-cache-info&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You should be able to see the following result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[...]&lt;br /&gt;
&amp;amp;lt; content-type: text/x-nix-cache-info&lt;br /&gt;
&amp;amp;lt; date: Sat, 07 Sep 2024 08:15:50 GMT&lt;br /&gt;
&amp;amp;lt; content-length: 51&lt;br /&gt;
&amp;amp;lt;&lt;br /&gt;
WantMassQuery: 1&lt;br /&gt;
StoreDir: /nix/store&lt;br /&gt;
Priority: 41&lt;br /&gt;
[...]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This way, you can see if the credentials are correct or not, and if your computer can reach attic at all.&lt;br /&gt;
&lt;br /&gt;
Furthermore, watch the attic logs under &amp;lt;code&amp;gt;/var/log/atticd&amp;lt;/code&amp;gt; for any error messages. You should be able to observe the following log output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;==&amp;amp;gt; /var/log/atticd/attic.stderr.log &amp;amp;lt;==&lt;br /&gt;
[...]&lt;br /&gt;
Attic Server 0.1.0 (release)&lt;br /&gt;
Running migrations...&lt;br /&gt;
Starting API server...&lt;br /&gt;
Listening on 127.0.0.1:18080...&lt;br /&gt;
&lt;br /&gt;
==&amp;amp;gt; /var/log/atticd/attic.stdout.log &amp;amp;lt;==&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;further-reading&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
= Further reading =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;nix-darwin&amp;lt;/code&amp;gt;: https://github.com/LnL7/nix-darwin&lt;br /&gt;
* attic source code repository: https://github.com/zhaofengli/attic&lt;br /&gt;
* attic NixOS configuration: https://github.com/zhaofengli/attic/blob/main/nixos/atticd.nix&lt;br /&gt;
* How to serve and configure Nix store (not cache) via HTTP: https://nix.dev/manual/nix/2.18/package-management/binary-cache-substituter&lt;/div&gt;</summary>
		<author><name>Justus</name></author>
	</entry>
</feed>