Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d120ca9
Update MAINTENANCE.md
isegall-da Jun 11, 2025
64e35f7
[static] prelim test
isegall-da Jul 23, 2025
7eac6fa
[static] prelim test
isegall-da Jul 23, 2025
8699c2a
[static] default container
isegall-da Jul 23, 2025
46eacf9
[static] .
isegall-da Jul 23, 2025
c9dcba2
[static] .
isegall-da Jul 23, 2025
17377b2
[static] .
isegall-da Jul 23, 2025
7371d9a
[static] .
isegall-da Jul 23, 2025
4d51d1f
[static] .
isegall-da Jul 23, 2025
074f422
[static] .
isegall-da Jul 23, 2025
8c04471
[static] .
isegall-da Jul 23, 2025
22ab153
[static] .
isegall-da Jul 23, 2025
5a03401
[static] .
isegall-da Jul 23, 2025
66ba974
[static] .
isegall-da Jul 23, 2025
270f716
[static] pull cache from gcp
isegall-da Jul 24, 2025
b93b9ef
[static] does an empty container work?
isegall-da Jul 24, 2025
ff4b48b
[static] wget
isegall-da Jul 24, 2025
e99d55b
[static] .
isegall-da Jul 24, 2025
94bd4a4
[static] .
isegall-da Jul 24, 2025
ccb82e7
[static] argh!
isegall-da Jul 24, 2025
7b4636f
[static] double argh!
isegall-da Jul 24, 2025
b6066b0
[static] oss_only
isegall-da Jul 24, 2025
930c27d
[static] compute cache key
isegall-da Jul 24, 2025
894f427
[static] fix cache key
isegall-da Jul 24, 2025
652a3c7
[static] .
isegall-da Jul 24, 2025
f126552
[static] refactor
isegall-da Jul 24, 2025
b6594c3
[static] whoops
isegall-da Jul 24, 2025
6639bf4
[static] .
isegall-da Jul 24, 2025
8044cad
[static] .
isegall-da Jul 25, 2025
a6fa6b9
[static] cleanup
isegall-da Jul 25, 2025
38980e5
[static] .
isegall-da Jul 25, 2025
054f7db
test upload
isegall-da Jul 25, 2025
bf229c6
container
isegall-da Jul 25, 2025
2615f49
[static]
isegall-da Jul 25, 2025
67ffbe5
[static] .
isegall-da Jul 25, 2025
4b86017
[static] another test, and some more comments
isegall-da Jul 25, 2025
8af6a82
[static] cleanups
isegall-da Jul 25, 2025
393871a
[static] Merge remote-tracking branch 'origin/main' into isegall/fork…
isegall-da Aug 5, 2025
7a8575c
[static] can we infer self-hosted?
isegall-da Aug 5, 2025
08710b0
[static] can we infer self-hosted?
isegall-da Aug 5, 2025
a15e96d
[static] can we infer self-hosted?
isegall-da Aug 5, 2025
2635cad
[static] infer self-hosted
isegall-da Aug 5, 2025
ad131b6
[static] test finding latest
isegall-da Aug 5, 2025
7e55f69
[static] test not finding latest by name
isegall-da Aug 5, 2025
b86a506
[static] enable cross-os caching
isegall-da Aug 11, 2025
d438138
[static] bump cache version, to force save
isegall-da Aug 11, 2025
5c535a4
Merge remote-tracking branch 'origin/main' into isegall/fork-runners
isegall-da Aug 19, 2025
e626cbb
[static] revert enableCrossOsArchive
isegall-da Aug 19, 2025
368ec79
[ci] cleanup
isegall-da Aug 19, 2025
199d2b9
test on fork
isegall-da Aug 19, 2025
078674f
Merge branch 'main' into isegall/fork-runners
isegall-da Aug 19, 2025
1d0ee7b
[static] also on fork base
isegall-da Aug 19, 2025
197aed4
[static] fix damlDarLock checks
isegall-da Aug 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 235 additions & 0 deletions .github/actions/nix/setup_nix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
name: "Setup Nix"
description: "Setup Nix"
inputs:
artifactory_user:
description: "The Artifactory user"
required: true
artifactory_password:
description: "The Artifactory password"
required: true
oss_only:
description: "Restrict upstream dependencies (e.g. Canton) to OSS versions (the equivalent of OSS_ONLY=1 in local checkouts)"
default: "false"
required: false
cache_version:
description: "The cache version"
required: true
should_save:
description: "If the nix cache should be saved"
# this should be run just from one job to ensure we avoid multi write conflicts, which makes everything worse
default: "false"
should_save_gcp:
description: "If the nix cache should be saved to the public GCP bucket"
default: "false"
upload_workload_identity_provider:
description: "The workload identity provider to use for uploading the cache"
required: false
default: ""
upload_service_account:
description: "The service account to use for uploading the cache"
required: false
default: ""

runs:
using: "composite"
steps:
- name: Compute cache Key
id: cache_key
shell: bash
run: |
set -euxo pipefail
git ls-files nix/ | grep -v '[.]md$' | LC_ALL=C sort | xargs sha256sum -b > /tmp/nix-cache-key
uname -m >> /tmp/nix-cache-key # Add architecture to the cache key
echo "gh_cache_version: ${{ inputs.cache_version }}" >> /tmp/nix-cache-key # Add cache version to the cache key
if [ "${{ inputs.oss_only }}" == true ]; then
echo "Using OSS only dependencies"
echo "oss_only: ${{ inputs.oss_only }}" >> /tmp/nix-cache-key
touch /tmp/oss-only # Create a file to indicate that we are using OSS only dependencies (so we don't need to re-specifify oss_only to run_bash_command_in_nix)
fi
cat /tmp/nix-cache-key
cache_key=($(md5sum "/tmp/nix-cache-key"))
echo "cache_key=$cache_key" >> $GITHUB_ENV

- name: Download cache (for non-self-hosted)
if: ${{ !startsWith(runner.name, 'self-hosted') }}
shell: bash
run: |
set -euxo pipefail

if [ ${{ inputs.oss_only }} != 'true' ]; then
echo "Must use OSS only dependencies in GitHub-hosted runners"
exit 1
fi

echo "Latest nix cache:"

wget -q "https://storage.googleapis.com/splice-nix-cache-public/${cache_key}.tar.gz" -O cache.tar.gz || true
if [ ! -f "${cache_key}.tar.gz" ]; then
echo "Cache not found, fetching latest instead"
latest=$(curl https://storage.googleapis.com/storage/v1/b/splice-nix-cache-public/o | jq -r '.items | sort_by(.updated) | .[-1].name')
wget -q "https://storage.googleapis.com/splice-nix-cache-public/${latest}" -O cache.tar.gz

fi

sudo mkdir -p /cache/nix/${cache_key}
sudo tar -xzf cache.tar.gz -C /cache/nix/${cache_key}

- name: Restore nix
id: restore_nix
shell: bash
run: |
set -euxo pipefail
sudo mkdir -p /nix/store
sudo chown -R $(whoami):$(whoami) /nix
if [ -f "/cache/nix/$cache_key/cached" ]; then
echo "Restoring nix cache (key $cache_key)"
# we use rsync here because it's simply faster to install
rsync -avi /cache/nix/$cache_key/.nix-* $HOME/
rsync -avi "/cache/nix/$cache_key/nix" $HOME/.config/
rsync -avi "/cache/nix/$cache_key/nix_store/var/" /nix/var
sudo mount --bind /cache/nix/$cache_key/nix_store/store /nix/store
else
sudo mkdir -p "/cache/nix/$cache_key"
sudo chown $(whoami):$(whoami) "/cache/nix/$cache_key"
sudo chown $(whoami):$(whoami) "/cache/nix"
fi
- name: Setup Nix
shell: bash
run: |
set -exuo pipefail
echo 'source ~/.nix-profile/etc/profile.d/nix.sh' > nix.rc
if [[ -f ~/.config/nix/nix.conf && -f ~/.nix-profile/etc/profile.d/nix.sh ]]; then
echo "nix.conf or nix.sh already exists, skipping Nix setup"
exit 0
else
# Disabling sandbox because:
# 1. It doesn't work on CircleCI (sethostname is not allowed)
# 2. We don't plan to build anything, so the risk is fairly low
mkdir -p ~/.config/nix
if [ true ]; then
cat <<EOF > ~/.config/nix/nix.conf
sandbox = false
netrc-file = /etc/nix/netrc
extra-experimental-features = nix-command flakes
substituters = file:///cache/nix/binary_cache?trusted=1 https://cache.nixos.org/
trusted-substituters = file:///cache/nix/binary_cache?trusted=1
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
cores = 4
max-jobs = 16
EOF
else
cat <<EOF > ~/.config/nix/nix.conf
sandbox = false
netrc-file = /etc/nix/netrc
extra-experimental-features = nix-command flakes
cores = 4
max-jobs = 16
EOF
fi
sh <(curl -fsSL --retry 8 https://releases.nixos.org/nix/nix-2.13.3/install) --no-daemon
sudo mkdir -p /etc/nix
sudo chmod a+rw /etc/nix
if [[ "${{ inputs.oss_only }}" == true ]]; then
echo "Using OSS only dependencies, not setting up Artifactory credentials"
else
cat <<EOF > /etc/nix/netrc
machine digitalasset.jfrog.io
login ${{ inputs.artifactory_user }}
password ${{ inputs.artifactory_password }}
EOF
fi
export USER=$(whoami)
echo "Running nix.sh"
. ~/.nix-profile/etc/profile.d/nix.sh
if [[ "${{ inputs.oss_only }}" == true ]]; then
target="oss"
else
target="default"
fi
nix develop path:nix#${target} -v --profile "$HOME/.nix-shell" --command echo "Done loading packages"
echo "Garbage collecting to reduce cache size"
nix-store --gc
fi

- name: Invoke nix before saving cache
uses: ./.github/actions/nix/run_bash_command_in_nix
with:
cmd: |
echo "Validated nix"
ls -al

# The nix cache does not change in the workflow, so we can save it immediately, rather than splitting it into pre-&post- steps
- name: Save nix cache
shell: bash
if: ${{ inputs.should_save == 'true' }}
run: |
set -euxo pipefail
echo ~
chown -R $(whoami):$(whoami) ~
cat /tmp/nix-cache-key
if [ ! -f "/cache/nix/$cache_key/cached" ]; then
echo "Saving nix"

sudo -v ; curl https://rclone.org/install.sh | sudo bash

echo "sourcing nix profile"
export USER=$(whoami)
. ~/.nix-profile/etc/profile.d/nix.sh

nix copy --all --to 'file:///cache/nix/binary_cache?trusted=1' -v

CLONE_COMMAND="rclone --no-update-dir-modtime --no-update-modtime --size-only --multi-thread-streams=32 --transfers=32 --ignore-existing --links --create-empty-src-dirs --fast-list --metadata --order-by name,mixed --retries 10 copy"
${CLONE_COMMAND} "$HOME/" "/cache/nix/$cache_key/" --include ".nix-*/**" --include ".nix-*"
${CLONE_COMMAND} $HOME/.config/nix "/cache/nix/$cache_key/nix"

mkdir -p "/cache/nix/$cache_key/nix_store/store"
mkdir -p "/cache/nix/$cache_key/nix_store/var"

#requires to preserve read only during clone
sudo ${CLONE_COMMAND} /nix/store/ /cache/nix/$cache_key/nix_store/store
sudo ${CLONE_COMMAND} /nix/var/ "/cache/nix/$cache_key/nix_store/var"

echo "done" > "/cache/nix/$cache_key/cached"
fi

- name: Check if cache already exists in GCP
id: already_exists
if: ${{ inputs.should_save_gcp == 'true' }}
shell: bash
run: |
if curl -Isf https://storage.googleapis.com/splice-nix-cache-public/${cache_key}.tar.gz &> /dev/null; then
echo "Cache with key ${cache_key} already exists in GCP, not uploading again"
echo "already_exists=true" >> $GITHUB_OUTPUT;
fi
- name: Authenticate to GCP
id: auth
if: ${{ inputs.should_save_gcp == 'true' && steps.already_exists.outputs.already_exists != 'true' }}
uses: "google-github-actions/auth@ba79af03959ebeac9769e648f473a284504d9193" #v2.1.10
with:
workload_identity_provider: "${{ inputs.upload_workload_identity_provider }}"
service_account: "${{ inputs.upload_service_account }}"

- name: tar-gz the cache
shell: bash
if: ${{ inputs.should_save_gcp == 'true' && steps.already_exists.outputs.already_exists != 'true' }}
id: prep_cache_upload
run: |
set -euxo pipefail
echo "Compressing nix cache to /cache/nix/${cache_key}.tar.gz"
mkdir -p /tmp/nix-upload

tar -czf "/tmp/nix-upload/${cache_key}.tar.gz" -C "/cache/nix/$cache_key" .

echo "Cache compressed to /tmp/nix-upload/${cache_key}.tar.gz"
ls /tmp/nix-upload
echo "cache_file=/tmp/nix-upload/${cache_key}.tar.gz" >> $GITHUB_OUTPUT

- name: Upload nix cache
if: ${{ inputs.should_save_gcp == 'true' && steps.already_exists.outputs.already_exists != 'true' }}
uses: google-github-actions/upload-cloud-storage@v2
with:
destination: splice-nix-cache-public
path: "${{ steps.prep_cache_upload.outputs.cache_file }}"
parent: false # upload to root of the bucket
process_gcloudignore: false # no gcloud ignore file in this repo, must set this to false
gzip: false # it's already gzipped
Loading
Loading