Skip to content

Instantly share code, notes, and snippets.

@LnL7
Last active June 9, 2020 20:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LnL7/ba2eac19e77cd6b4bb02c8de03bf5f4e to your computer and use it in GitHub Desktop.
Save LnL7/ba2eac19e77cd6b4bb02c8de03bf5f4e to your computer and use it in GitHub Desktop.
darwin nix-daemon distributed builds
#!/usr/bin/env bash
sudo mkdir -p /run/nix/current-load
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo curl -fsSL -o /Library/LaunchDaemons/org.nixos.nix-daemon.plist https://gist.github.com/LnL7/ba2eac19e77cd6b4bb02c8de03bf5f4e/raw/69722c2b13c4eb022a1312cd6891838b413e1f96/org.nixos.nix-daemon.plist
sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
# Configure /etc/nix/machines
# Make sure root can ssh to the builder (known_hosts etc.)
# Configure known hosts.
mac1 x86_64-darwin /etc/nix/build_rsa 4
mac2 x86_64-darwin /etc/nix/build_rsa 4
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>NIX_BUILD_HOOK</key>
<string>/nix/var/nix/profiles/default/libexec/nix/build-remote.pl</string>
<key>NIX_CURRENT_LOAD</key>
<string>/run/nix/current-load</string>
<key>NIX_REMOTE_SYSTEMS</key>
<string>/etc/nix/machines</string>
<key>NIX_SSL_CERT_FILE</key>
<string>/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.nixos.nix-daemon</string>
<key>LowPriorityIO</key>
<false/>
<key>Nice</key>
<integer>0</integer>
<key>ProcessType</key>
<string>Interactive</string>
<key>Program</key>
<string>/nix/var/nix/profiles/default/bin/nix-daemon</string>
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>4096</integer>
</dict>
</dict>
</plist>
@LnL7
Copy link
Author

LnL7 commented Feb 8, 2018

These are some issues I've run into when setting it up:

  • NIX_CURRENT_LOAD has to exist.
  • make sure nix-store available in PATH (on the builder), this might not be the case for non-interactive ssh sessions on darwin.
  • the machine was not in the know_hosts yet, what's important to know is that when using the nix-daemon this has to be done for root
  • the signing key was not setup properly, I think this is not required when using the nix-daemon

WARNING: don't use nix-build --check to verify if this is working correctly, it always builds locally.

nix-build -E 'with import <nixpkgs> { system = "x86_64-darwin"; }; hello.overrideAttrs (drv: { REBUILD = builtins.currentTime; })'

@wmertens
Copy link

wmertens commented Mar 8, 2018

  • Why not store current load under /nix/var/run? Keeps all Nix files under /nix…
  • Same for machines, this could go under /nix/etc/machines

@LnL7
Copy link
Author

LnL7 commented May 18, 2018

None of the nix-daemon environment variables should be necessary anymore with nix 2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment