this hook queues up store paths on a unix domain socket and then spawns a service to actually push the store path to the cache through socket activation
works on MacOS and Linux
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>nix-post-build-hook</string> | |
| <key>KeepAlive</key> | |
| <false/> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| <key>Program></key> | |
| <string>xargs</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>--verbose</string> | |
| <string>--no-run-if-empty</string> | |
| <string>nix</string> | |
| <string>copy</string> | |
| <string>--to</string> | |
| <string>s3://my-bucket</string> | |
| </array> | |
| <key>StandardErrorPath</key> | |
| <string>/var/log/nix-post-build-hook.log</string> | |
| <key>Sockets</key> | |
| <dict> | |
| <key>Listeners</key> | |
| <dict> | |
| <key>SocketType</key> | |
| <string>stream</string> | |
| <key>SockPathName</key> | |
| <string>/var/run/nix-post-build-hook.sock</string> | |
| <key>inetdCompatibility</key> | |
| <dict> | |
| <key>Wait</key> | |
| <false/> | |
| </dict> | |
| </dict> | |
| </dict> | |
| </dict> | |
| </plist> |
| [Socket] | |
| ListenStream=%t/%N.sock | |
| SocketMode=0600 | |
| Accept=yes |
| [Service] | |
| LoadCredential=signing-key | |
| Environment=NIX_STORE_URI=s3://my-bucket?secret-key=%d/signing-key&compression=zstd¶llel-compression=true | |
| StandardInput=socket | |
| ExecSearchPath=/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin | |
| ExecStart=xargs --no-run-if-empty --verbose nix copy --to $NIX_STORE_URI | |
| DynamicUser=yes |
| post-build-hook = socat EXEC:'printenv OUT_PATHS' UNIX-CONNECT:/var/run/nix-copy.sock |