-
-
Notifications
You must be signed in to change notification settings - Fork 226
feat(darwin): add nix-darwin host and linux-builder for NixOS tests #1999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { inputs, ... }: | ||
| { | ||
| flake = { | ||
| darwinConfigurations = { | ||
| darwin-nixostest = inputs.nix-darwin.lib.darwinSystem { | ||
| modules = [ ./hosts/darwin-nixostest/darwin-configuration.nix ]; | ||
| }; | ||
| }; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| { lib, pkgs, ... }: | ||
| let | ||
| start-linux-builder = pkgs.writeShellApplication { | ||
| name = "start-linux-builder"; | ||
| text = '' | ||
| echo "Starting linux-builder..." | ||
|
|
||
| if sudo launchctl list | grep -q org.nixos.linux-builder; then | ||
| echo "linux-builder is already running" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Use load instead of start to re-enable the service | ||
| if sudo launchctl load -w /Library/LaunchDaemons/org.nixos.linux-builder.plist 2>/dev/null; then | ||
| echo "linux-builder started successfully" | ||
| else | ||
| echo "Error: Could not start linux-builder" | ||
| echo "Make sure nix-darwin is configured with linux-builder enabled" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if it's running | ||
| sleep 2 | ||
| if sudo launchctl list | grep -q org.nixos.linux-builder; then | ||
| echo "linux-builder is now running" | ||
| else | ||
| echo "Warning: linux-builder may not have started properly" | ||
| fi | ||
| ''; | ||
| }; | ||
| stop-linux-builder = pkgs.writeShellApplication { | ||
| name = "stop-linux-builder"; | ||
| text = '' | ||
| echo "Stopping linux-builder..." | ||
|
|
||
| # Use unload instead of stop because KeepAlive=true will restart it | ||
| if sudo launchctl unload -w /Library/LaunchDaemons/org.nixos.linux-builder.plist 2>/dev/null; then | ||
| echo "linux-builder stopped successfully" | ||
| else | ||
| echo "Warning: Could not stop linux-builder (it may not be running)" | ||
| fi | ||
|
|
||
| # Check if it's still running | ||
| sleep 1 | ||
| if sudo launchctl list | grep -q org.nixos.linux-builder; then | ||
| echo "Warning: linux-builder is still running" | ||
| STATUS=$(sudo launchctl list | grep org.nixos.linux-builder || true) | ||
| echo "Current status: $STATUS" | ||
| else | ||
| echo "linux-builder is not running" | ||
| fi | ||
| ''; | ||
| }; | ||
| in | ||
| { | ||
| nixpkgs.hostPlatform = "aarch64-darwin"; | ||
|
|
||
| # Install builder control scripts | ||
| environment.systemPackages = [ | ||
| start-linux-builder | ||
| stop-linux-builder | ||
| ]; | ||
|
|
||
| nix.settings = { | ||
| experimental-features = [ | ||
| "nix-command" | ||
| "flakes" | ||
| ]; | ||
| always-allow-substitutes = true; | ||
| max-jobs = "auto"; | ||
| trusted-users = [ "@admin" ]; | ||
| extra-substituters = [ "https://nix-postgres-artifacts.s3.amazonaws.com" ]; | ||
| extra-trusted-substituters = [ "https://nix-postgres-artifacts.s3.amazonaws.com" ]; | ||
| extra-trusted-public-keys = [ | ||
| "nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=" | ||
| ]; | ||
| }; | ||
|
|
||
| nix.extraOptions = '' | ||
| !include nix.custom.conf | ||
| ''; | ||
|
|
||
| # accept existing nix.custom.conf | ||
| system.activationScripts.checks.text = lib.mkForce ""; | ||
| system.activationScripts.nix-daemon.text = lib.mkForce '' | ||
| if ! diff /etc/nix/nix.conf /run/current-system/etc/nix/nix.conf &> /dev/null || ! diff /etc/nix/machines /run/current-system/etc/nix/machines &> /dev/null; then | ||
| echo "reloading nix-daemon..." >&2 | ||
| launchctl kill HUP system/org.nixos.nix-daemon | ||
| fi | ||
| max_wait=30 | ||
| waited=0 | ||
| while ! nix-store --store daemon -q --hash ${pkgs.stdenv.shell} &>/dev/null; do | ||
| if [ $waited -ge $max_wait ]; then | ||
| echo "ERROR: nix-daemon failed to start after $max_wait seconds" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "waiting for nix-daemon" >&2 | ||
| launchctl kickstart system/org.nixos.nix-daemon | ||
| sleep 1 | ||
| waited=$((waited + 1)) | ||
| done | ||
| ''; | ||
|
|
||
| nix.linux-builder = { | ||
| enable = true; | ||
| ephemeral = true; | ||
| maxJobs = 4; | ||
| supportedFeatures = [ | ||
| "kvm" | ||
| "benchmark" | ||
| "big-parallel" | ||
| "nixos-test" | ||
| ]; | ||
| config = { | ||
| virtualisation = { | ||
| darwin-builder = { | ||
| diskSize = 40 * 1024; | ||
| memorySize = 8 * 1024; | ||
| }; | ||
| cores = 6; | ||
| }; | ||
| }; | ||
| }; | ||
|
Comment on lines
+104
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's explore the repository structure
git ls-files | head -20Repository: supabase/postgres Length of output: 796 🏁 Script executed: # Find files related to darwin-builder or linux-builder
fd "darwin" --type fRepository: supabase/postgres Length of output: 156 🏁 Script executed: # Look for documentation or comments about supportedFeatures
rg "supportedFeatures" -A 3 -B 3Repository: supabase/postgres Length of output: 559 🏁 Script executed: # Check for any nix-darwin or linux-builder related files
fd "linux-builder\|darwin" --type fRepository: supabase/postgres Length of output: 43 🏁 Script executed: cat -n nix/packages/setup-darwin-linux-builder.nixRepository: supabase/postgres Length of output: 2361 🏁 Script executed: # Check if there are any comments or documentation about KVM support in the entire darwin-nixostest directory
rg "kvm\|KVM" --type nix -iRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Look at the full darwin-configuration.nix file to understand context
cat -n nix/hosts/darwin-nixostest/darwin-configuration.nixRepository: supabase/postgres Length of output: 4749 🏁 Script executed: # Search for any CI or tests that might use this configuration
rg "darwin-nixostest\|linux-builder" --type yml --type yaml -B 2 -A 2Repository: supabase/postgres Length of output: 88 🏁 Script executed: # Check if there are any issues or documentation about supportedFeatures in nix files
rg "supportedFeatures" -B 5 -A 5Repository: supabase/postgres Length of output: 818 🏁 Script executed: # Look for any references to darwin-builder in comments or documentation
rg "darwin-builder" --type nix -B 3 -A 3Repository: supabase/postgres Length of output: 574 🏁 Script executed: # Search for nixos-test or other features mentioned
rg "benchmark\|big-parallel\|nixos-test" --type nixRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Search for workflow files that might use this configuration
fd "\.ya?ml" nix/hosts .github/workflows | head -20Repository: supabase/postgres Length of output: 789 🏁 Script executed: # Look at the flake.nix to understand how this configuration is defined
cat -n flake.nix | head -100Repository: supabase/postgres Length of output: 2484 🏁 Script executed: # Search for any references to darwin-nixostest in the repo
rg "darwin-nixostest" -B 2 -A 2Repository: supabase/postgres Length of output: 697 🏁 Script executed: # Check if there are any comments in the configuration about feature support
cat -n nix/hosts/darwin-nixostest/darwin-configuration.nix | grep -A 20 -B 5 "supportedFeatures"Repository: supabase/postgres Length of output: 674 🏁 Script executed: # Look for any README or documentation files in the nix directory
find nix -name "README*" -o -name "*.md"Repository: supabase/postgres Length of output: 806 🏁 Script executed: # Check for any comments or documentation in the hosts.nix file
cat -n nix/hosts.nixRepository: supabase/postgres Length of output: 348 🏁 Script executed: # Search for any references to KVM, nested virtualization, or capabilities in the repo
rg "nested\|virtuali\|capab" --type nix -iRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Look for any notes or issues in git history about this configuration
git log --oneline --all -- nix/hosts/darwin-nixostest/darwin-configuration.nix | head -10Repository: supabase/postgres Length of output: 136 🏁 Script executed: # Show the commit that added this configuration
git show --stat 1c61ed9Repository: supabase/postgres Length of output: 45187 🏁 Script executed: # Check the nix documentation about development workflow and darwin
cat nix/docs/development-workflow.mdRepository: supabase/postgres Length of output: 3966 🏁 Script executed: # Check if there's any documentation about darwin or linux-builder setup
cat nix/docs/start-here.mdRepository: supabase/postgres Length of output: 5176 🏁 Script executed: # Search for any comments or context about the features in the actual implementation
git show 1c61ed9 -- nix/hosts/darwin-nixostest/darwin-configuration.nix | head -150Repository: supabase/postgres Length of output: 4880 🏁 Script executed: # Look for any issues or documentation about linux-builder features
rg "supportedFeatures\|linux-builder" --type mdRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Check the PR that added this configuration
git log --all --oneline --grep="darwin\|linux-builder" | head -20Repository: supabase/postgres Length of output: 888 🏁 Script executed: # Search online for nix-darwin linux-builder documentation or issues
# Let's check what the actual feature requirements are
rg "benchmark\|big-parallel\|nixos-test" --type nix -B 2 -A 2Repository: supabase/postgres Length of output: 43 🏁 Script executed: # Look at the nix-darwin source to understand linux-builder better
cat flake.lock | grep -A 5 "nix-darwin"Repository: supabase/postgres Length of output: 747 🏁 Script executed: # Look for any existing issues or documentation in the repo about feature support
rg "kvm\|nested" --type nix --type md -iRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Check if there are any test results or CI logs that might indicate feature success/failure
find . -name "*.log" -o -name "*test*" -type f | grep -i darwin | head -10Repository: supabase/postgres Length of output: 43 🏁 Script executed: # Search for nix-darwin module documentation in the repo
fd "modules\|options" | xargs grep -l "linux-builder" 2>/dev/null | head -5Repository: supabase/postgres Length of output: 43 🏁 Script executed: # Check git history for any issues or fixes related to this configuration
git log --all --oneline -- "nix/hosts/darwin-nixostest/" | head -10Repository: supabase/postgres Length of output: 136 🌐 Web query:
💡 Result: Short answer
Relevant sources
If you want, tell me:
Remove unsupported QEMU on macOS uses the Hypervisor.framework (hvf), not KVM. Advertising 🤖 Prompt for AI Agents |
||
|
|
||
| nix.distributedBuilds = true; | ||
|
|
||
| system.stateVersion = 6; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| { | ||
| inputs, | ||
| stdenv, | ||
| writeShellApplication, | ||
| }: | ||
| writeShellApplication { | ||
| name = "setup-darwin-linux-builder"; | ||
| runtimeInputs = [ | ||
| inputs.nix-darwin.packages.${stdenv.hostPlatform.system}.darwin-rebuild | ||
| ]; | ||
| text = '' | ||
| set -euo pipefail | ||
|
|
||
| echo "Configuring nix-darwin linux-builder..." | ||
| echo "" | ||
|
|
||
| # Backup files that nix-darwin will manage | ||
| echo "Preparing for nix-darwin..." | ||
| for file in /etc/nix/nix.conf /etc/bashrc /etc/zshrc; do | ||
| if [[ -f "$file" && ! -L "$file" ]]; then | ||
| echo " Backing up $file" | ||
| sudo mv "$file" "$file.before-nix-darwin" | ||
| fi | ||
| done | ||
| echo "" | ||
|
|
||
| revert() { | ||
| for file in /etc/nix/nix.conf /etc/bashrc /etc/zshrc; do | ||
| if [[ ! -L "$file" && -f "$file.before-nix-darwin" ]]; then | ||
| echo " Restoring original $file" | ||
| sudo mv "$file.before-nix-darwin" "$file" | ||
| fi | ||
| done | ||
|
Comment on lines
+27
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rollback won’t restore backups after nix-darwin symlinks files.
🔧 Proposed fix- if [[ ! -L "$file" && -f "$file.before-nix-darwin" ]]; then
- echo " Restoring original $file"
- sudo mv "$file.before-nix-darwin" "$file"
+ if [[ -f "$file.before-nix-darwin" ]]; then
+ echo " Restoring original $file"
+ sudo rm -f "$file"
+ sudo mv "$file.before-nix-darwin" "$file"
fi🤖 Prompt for AI Agents |
||
| } | ||
| trap revert ERR SIGINT SIGTERM | ||
|
|
||
| echo "This will configure your system with:" | ||
| echo " - NixOS linux-builder VM (ephemeral)" | ||
| echo " - 6 cores, 8GB RAM, 40GB disk" | ||
| echo " - Support for x86_64-linux and aarch64-linux builds" | ||
| echo "" | ||
| echo "Running darwin-rebuild switch..." | ||
| echo "" | ||
|
|
||
| sudo darwin-rebuild switch --refresh --flake github:supabase/postgres/darwin-linux-builder#darwin-nixostest | ||
|
|
||
| echo "" | ||
| echo "Configuration complete!" | ||
| echo "" | ||
| echo "The linux-builder is now configured. You can test it by:" | ||
| echo " nix build --system x86_64-linux nixpkgs#hello" | ||
| echo " nix build --system aarch64-linux nixpkgs#hello" | ||
| echo "" | ||
| echo "To control the linux builder vm, you can use:" | ||
| echo " stop-linux-builder # to stop the linux builder vm" | ||
| echo " start-linux-builder # to start the linux builder vm" | ||
| echo "" | ||
| echo "If this is the first install, you may need to restart your shell to use these scripts." | ||
| ''; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: supabase/postgres
Length of output: 4788
Remove the hardcoded architecture or clarify intent with a comment.
The
aarch64-darwinplatform is hardcoded, which will fail on Intel Macs. Since the host directory "darwin-nixostest" lacks architecture specificity, this configuration appears generic and should auto-detect the platform instead.🔧 Suggested adjustment
Alternatively, if this configuration is intentionally ARM-only, rename the directory to
darwin-aarch64-nixostestand add a comment explaining the constraint.📝 Committable suggestion
🤖 Prompt for AI Agents