forked from manaflow-ai/cmux
-
Notifications
You must be signed in to change notification settings - Fork 0
ci(nix): use runner nix on self-hosted lanes #243
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| if ! command -v nix >/dev/null 2>&1; then | ||
| echo "::error::Nix is not installed on this self-hosted runner." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "${GITHUB_ENV:-}" ]]; then | ||
| echo "::error::GITHUB_ENV is not set; this script is meant to run inside GitHub Actions." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| ATTIC_PUBLIC_KEY="main:NKRk1XYo/dfd9fcDqgotUJg2DTDHWp5ny+Ba7WzRjgE=" | ||
| DETERMINATE_NIXD_LOG="/tmp/determinate-nixd.log" | ||
|
|
||
| emit_github_env() { | ||
| local key="$1" | ||
| shift | ||
|
|
||
| { | ||
| printf '%s<<EOF\n' "$key" | ||
| printf '%s\n' "$@" | ||
| printf 'EOF\n' | ||
| } >>"$GITHUB_ENV" | ||
| } | ||
|
|
||
| daemon_store_available() { | ||
| nix store info --store daemon >/dev/null 2>&1 | ||
| } | ||
|
|
||
| start_determinate_daemon() { | ||
| local daemon_bin | ||
| daemon_bin="$(command -v determinate-nixd)" | ||
|
|
||
| if [[ "$(id -u)" -eq 0 ]]; then | ||
| nohup "$daemon_bin" daemon >"$DETERMINATE_NIXD_LOG" 2>&1 & | ||
| return 0 | ||
| fi | ||
|
|
||
| if ! command -v sudo >/dev/null 2>&1; then | ||
| echo "::error::determinate-nixd requires root to launch the daemon, but sudo is unavailable on this runner" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| if ! sudo -n true >/dev/null 2>&1; then | ||
| echo "::error::Passwordless sudo is unavailable for launching determinate-nixd on this runner" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| nohup sudo -n "$daemon_bin" daemon >"$DETERMINATE_NIXD_LOG" 2>&1 & | ||
| } | ||
|
|
||
| emit_diagnostics() { | ||
| echo "::notice::Nix daemon socket diagnostics" | ||
| for path in \ | ||
| /nix/var/nix/daemon-socket \ | ||
| /nix/var/nix/daemon-socket/socket \ | ||
| /nix/var/determinate/determinate-nixd.socket \ | ||
| /var/run/nix-daemon.socket \ | ||
| /var/run/determinate-nixd.socket | ||
| do | ||
| if [[ -e "$path" || -L "$path" ]]; then | ||
| ls -ld "$path" >&2 | ||
| else | ||
| echo "missing: $path" >&2 | ||
| fi | ||
| done | ||
|
|
||
| if command -v ps >/dev/null 2>&1; then | ||
| ps -ef | grep '[d]eterminate-nixd' >&2 || true | ||
| fi | ||
| } | ||
|
|
||
| determine_daemon_mode() { | ||
| if daemon_store_available; then | ||
| echo "NIX_REMOTE=daemon" >>"$GITHUB_ENV" | ||
| echo "::notice::Using preinitialized Nix daemon" | ||
| return 0 | ||
| fi | ||
|
|
||
| if command -v determinate-nixd >/dev/null 2>&1; then | ||
| echo "::notice::Starting determinate-nixd for this workflow" | ||
| rm -f "$DETERMINATE_NIXD_LOG" | ||
| start_determinate_daemon | ||
|
|
||
| local attempt | ||
| for attempt in $(seq 1 100); do | ||
| if daemon_store_available; then | ||
| echo "NIX_REMOTE=daemon" >>"$GITHUB_ENV" | ||
| echo "::notice::Determinate Nix daemon is ready" | ||
| return 0 | ||
| fi | ||
| sleep 0.2 | ||
| done | ||
|
|
||
| echo "::error::Determinate Nix daemon did not become ready" >&2 | ||
| if [[ -f "$DETERMINATE_NIXD_LOG" ]]; then | ||
| sed -n '1,120p' "$DETERMINATE_NIXD_LOG" >&2 | ||
| fi | ||
| emit_diagnostics | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "::error::No usable Nix daemon detected on this self-hosted runner" >&2 | ||
| emit_diagnostics | ||
| exit 1 | ||
| } | ||
|
|
||
| determine_daemon_mode | ||
|
|
||
| declare -a nix_config_lines=() | ||
| if [[ -n "${NIX_CONFIG:-}" ]]; then | ||
| nix_config_lines+=("${NIX_CONFIG}") | ||
| fi | ||
|
|
||
| if [[ -n "${ATTIC_SERVER:-}" && -n "${ATTIC_CACHE:-}" ]]; then | ||
| nix_config_lines+=("extra-substituters = ${ATTIC_SERVER%/}/${ATTIC_CACHE}") | ||
| nix_config_lines+=("extra-trusted-public-keys = ${ATTIC_PUBLIC_KEY}") | ||
| echo "::notice::Configured Nix substituter ${ATTIC_SERVER%/}/${ATTIC_CACHE}" | ||
| fi | ||
|
|
||
| if (( ${#nix_config_lines[@]} > 0 )); then | ||
| emit_github_env "NIX_CONFIG" "${nix_config_lines[@]}" | ||
| fi | ||
|
|
||
| echo "::notice::Using Nix from $(command -v nix)" | ||
| nix --version | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
EOFdelimiter may truncateNIX_CONFIGThe GitHub Actions multiline env-file format requires that the chosen delimiter does not appear as a standalone line anywhere in the value. Using the fixed string
EOFmeans any pre-existingNIX_CONFIGthat contains a bareEOFline would silently truncate the exported value, causing downstreamnixinvocations to receive incomplete config with no error. GitHub's own documentation recommends generating a random delimiter (e.g. via$RANDOMor a hash) to eliminate the collision risk entirely.