Skip to content

Commit 441a365

Browse files
CMCDragonkaibrynblack
authored andcommitted
feat: replace container image with install-nix-action
1 parent 3fa01ca commit 441a365

17 files changed

+200
-205
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Install Nix'
2+
description: 'Installs Nix on GitHub Actions for the supported platforms: Linux and macOS.'
3+
author: 'Domen Kožar'
4+
inputs:
5+
extra_nix_config:
6+
description: 'Gets appended to `/etc/nix/nix.conf` if passed.'
7+
github_access_token:
8+
description: 'Configure nix to pull from github using the given github token.'
9+
install_url:
10+
description: 'Installation URL that will contain a script to install Nix.'
11+
install_options:
12+
description: 'Additional installer flags passed to the installer script.'
13+
nix_path:
14+
description: 'Set NIX_PATH environment variable.'
15+
enable_kvm:
16+
description: 'Enable KVM for hardware-accelerated virtualization on Linux, if available.'
17+
required: false
18+
default: true
19+
branding:
20+
color: 'blue'
21+
icon: 'sun'
22+
runs:
23+
using: 'composite'
24+
steps:
25+
- run: |
26+
${GITHUB_ACTION_PATH}/install-nix.sh
27+
nix profile install nixpkgs#cacert nixpkgs#tzdata
28+
TZDATA=$(nix eval --raw nixpkgs#tzdata.outPath)
29+
CACERT=$(nix eval --raw nixpkgs#cacert.outPath)
30+
echo "TZDIR=$TZDATA/share/zoneinfo" >> "$GITHUB_ENV"
31+
echo "GIT_SSL_CAINFO=$CACERT/etc/ssl/certs/ca-bundle.crt" >> "$GITHUB_ENV"
32+
echo "NIX_SSL_CERT_FILE=$CACERT/etc/ssl/certs/ca-bundle.crt" >> "$GITHUB_ENV"
33+
shell: bash
34+
env:
35+
INPUT_EXTRA_NIX_CONFIG: ${{ inputs.extra_nix_config }}
36+
INPUT_GITHUB_ACCESS_TOKEN: ${{ inputs.github_access_token }}
37+
INPUT_INSTALL_OPTIONS: ${{ inputs.install_options }}
38+
INPUT_INSTALL_URL: ${{ inputs.install_url }}
39+
INPUT_NIX_PATH: ${{ inputs.nix_path }}
40+
INPUT_ENABLE_KVM: ${{ inputs.enable_kvm }}
41+
GITHUB_TOKEN: ${{ github.token }}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if nix_path="$(type -p nix)" ; then
5+
echo "Aborting: Nix is already installed at ${nix_path}"
6+
exit
7+
fi
8+
9+
if [[ ($OSTYPE =~ linux) && ($INPUT_ENABLE_KVM == 'true') ]]; then
10+
enable_kvm() {
11+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-install-nix-action-kvm.rules
12+
sudo udevadm control --reload-rules && sudo udevadm trigger --name-match=kvm
13+
}
14+
15+
echo '::group::Enabling KVM support'
16+
enable_kvm && echo 'Enabled KVM' || echo 'KVM is not available'
17+
echo '::endgroup::'
18+
fi
19+
20+
# GitHub command to put the following log messages into a group which is collapsed by default
21+
echo "::group::Installing Nix"
22+
23+
# Create a temporary workdir
24+
workdir=$(mktemp -d)
25+
trap 'rm -rf "$workdir"' EXIT
26+
27+
# Configure Nix
28+
add_config() {
29+
echo "$1" >> "$workdir/nix.conf"
30+
}
31+
add_config "show-trace = true"
32+
# Set jobs to number of cores
33+
add_config "max-jobs = auto"
34+
if [[ $OSTYPE =~ darwin ]]; then
35+
add_config "ssl-cert-file = /etc/ssl/cert.pem"
36+
fi
37+
# Allow binary caches for user
38+
add_config "trusted-users = root ${USER:-}"
39+
# Add a GitHub access token.
40+
# Token-less access is subject to lower rate limits.
41+
if [[ -n "${INPUT_GITHUB_ACCESS_TOKEN:-}" ]]; then
42+
echo "::debug::Using the provided github_access_token for github.com"
43+
add_config "access-tokens = github.com=$INPUT_GITHUB_ACCESS_TOKEN"
44+
# Use the default GitHub token if available.
45+
# Skip this step if running an Enterprise instance. The default token there does not work for github.com.
46+
elif [[ -n "${GITHUB_TOKEN:-}" && $GITHUB_SERVER_URL == "https://github.com" ]]; then
47+
echo "::debug::Using the default GITHUB_TOKEN for github.com"
48+
add_config "access-tokens = github.com=$GITHUB_TOKEN"
49+
else
50+
echo "::debug::Continuing without a GitHub access token"
51+
fi
52+
# Append extra nix configuration if provided
53+
if [[ -n "${INPUT_EXTRA_NIX_CONFIG:-}" ]]; then
54+
add_config "$INPUT_EXTRA_NIX_CONFIG"
55+
fi
56+
if [[ ! $INPUT_EXTRA_NIX_CONFIG =~ "experimental-features" ]]; then
57+
add_config "experimental-features = nix-command flakes"
58+
fi
59+
# Always allow substituting from the cache, even if the derivation has `allowSubstitutes = false`.
60+
# This is a CI optimisation to avoid having to download the inputs for already-cached derivations to rebuild trivial text files.
61+
if [[ ! $INPUT_EXTRA_NIX_CONFIG =~ "always-allow-substitutes" ]]; then
62+
add_config "always-allow-substitutes = true"
63+
fi
64+
65+
# Nix installer flags
66+
installer_options=(
67+
--no-channel-add
68+
--darwin-use-unencrypted-nix-store-volume
69+
--nix-extra-conf-file "$workdir/nix.conf"
70+
)
71+
72+
# only use the nix-daemon settings if on darwin (which get ignored) or systemd is supported
73+
if [[ (! $INPUT_INSTALL_OPTIONS =~ "--no-daemon") && ($OSTYPE =~ darwin || -e /run/systemd/system) ]]; then
74+
installer_options+=(
75+
--daemon
76+
--daemon-user-count "$(python3 -c 'import multiprocessing as mp; print(mp.cpu_count() * 2)')"
77+
)
78+
else
79+
# "fix" the following error when running nix*
80+
# error: the group 'nixbld' specified in 'build-users-group' does not exist
81+
add_config "build-users-group ="
82+
sudo mkdir -p /etc/nix
83+
sudo chmod 0755 /etc/nix
84+
sudo cp "$workdir/nix.conf" /etc/nix/nix.conf
85+
fi
86+
87+
if [[ -n "${INPUT_INSTALL_OPTIONS:-}" ]]; then
88+
IFS=' ' read -r -a extra_installer_options <<< "$INPUT_INSTALL_OPTIONS"
89+
installer_options=("${extra_installer_options[@]}" "${installer_options[@]}")
90+
fi
91+
92+
echo "installer options: ${installer_options[*]}"
93+
94+
# There is --retry-on-errors, but only newer curl versions support that
95+
curl_retries=5
96+
while ! curl -sS -o "$workdir/install" -v --fail -L "${INPUT_INSTALL_URL:-https://releases.nixos.org/nix/nix-2.25.2/install}"
97+
do
98+
sleep 1
99+
((curl_retries--))
100+
if [[ $curl_retries -le 0 ]]; then
101+
echo "curl retries failed" >&2
102+
exit 1
103+
fi
104+
done
105+
106+
sh "$workdir/install" "${installer_options[@]}"
107+
108+
# Set paths
109+
echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH"
110+
# new path for nix 2.14
111+
echo "$HOME/.nix-profile/bin" >> "$GITHUB_PATH"
112+
113+
if [[ -n "${INPUT_NIX_PATH:-}" ]]; then
114+
echo "NIX_PATH=${INPUT_NIX_PATH}" >> "$GITHUB_ENV"
115+
fi
116+
117+
# Set temporary directory (if not already set) to fix https://github.com/cachix/install-nix-action/issues/197
118+
if [[ -z "${TMPDIR:-}" ]]; then
119+
echo "TMPDIR=${RUNNER_TEMP}" >> "$GITHUB_ENV"
120+
fi
121+
122+
# Close the log message group which was opened above
123+
echo "::endgroup::"

.github/workflows/application-js-cloudflare-feature-closed.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,19 @@ jobs:
2626
feature-closed-deployment-stop:
2727
name: "Feature Closed / Deployment Stop"
2828
runs-on: ubuntu-latest
29-
container:
30-
image: ghcr.io/matrixai/github-runner
3129
concurrency:
3230
group: feature-closed-deployment-stop
3331
cancel-in-progress: false
3432
# Only run if the PR head is a feature branch
3533
# This means the feature branch PR is closed
3634
if: startsWith(inputs.featureBranch, 'feature')
3735
permissions:
38-
packages: read
3936
contents: read
4037
steps:
4138
- uses: actions/checkout@v4
4239
with:
4340
lfs: true
41+
- uses: MatrixAI/.github/.github/actions/install-nix@master
4442
- name: Stop Deployment
4543
env:
4644
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}

.github/workflows/application-js-cloudflare-feature.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ on:
1616
DEPLOY_SECRETS:
1717
required: true
1818

19+
env:
20+
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
21+
1922
jobs:
2023
# Lint the code
2124
feature-lint:
2225
name: "Feature / Lint"
2326
runs-on: ubuntu-latest
24-
container:
25-
image: ghcr.io/matrixai/github-runner
2627
permissions:
27-
packages: read
2828
contents: read
2929
steps:
3030
- uses: actions/checkout@v4
3131
with:
3232
lfs: true
33+
- uses: MatrixAI/.github/.github/actions/install-nix@master
3334
- name: Run linting
3435
env:
3536
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
@@ -42,16 +43,14 @@ jobs:
4243
feature-build:
4344
name: "Feature / Build"
4445
runs-on: ubuntu-latest
45-
container:
46-
image: ghcr.io/matrixai/github-runner
4746
permissions:
48-
packages: read
4947
contents: read
5048
actions: write
5149
steps:
5250
- uses: actions/checkout@v4
5351
with:
5452
lfs: true
53+
- uses: MatrixAI/.github/.github/actions/install-nix@master
5554
- name: Run build
5655
env:
5756
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
@@ -70,8 +69,6 @@ jobs:
7069
name: "Feature / Deployment"
7170
runs-on: ubuntu-latest
7271
needs: feature-build
73-
container:
74-
image: ghcr.io/matrixai/github-runner
7572
concurrency:
7673
group: feature-deployment
7774
cancel-in-progress: false
@@ -89,17 +86,26 @@ jobs:
8986
- uses: actions/checkout@v4
9087
with:
9188
lfs: true
89+
- uses: MatrixAI/.github/.github/actions/install-nix@master
9290
- uses: actions/download-artifact@v4
9391
with:
9492
name: public
9593
path: ./public
94+
- name: Setup Deploy Secrets
95+
run: |
96+
echo "${{ inputs.DEPLOY_SECRETS }}" | jq -r 'to_entries | .[] | "\(.key)=\(.value)"' >> $GITHUB_ENV
9697
- name: Run deployment
9798
env:
9899
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
100+
name: "feature/${{ github.ref_name }}"
101+
url: "https://${{ github.ref_name }}.dev.zeta.house"
99102
run: |
100103
echo 'Perform service deployment for feature'
104+
echo "$SECRET1"
105+
echo "$SECRET2"
106+
echo "$SECRET3"
101107
nix develop .#ci --command bash -c $'
102108
npm run deploy -- \
103109
--feature "$GITHUB_REF_NAME" \
104110
--env "$GITHUB_REF_NAME"
105-
'
111+
'

.github/workflows/application-js-cloudflare-master.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ jobs:
2121
master-build:
2222
name: "Master / Build"
2323
runs-on: ubuntu-latest
24-
container:
25-
image: ghcr.io/matrixai/github-runner
2624
permissions:
27-
packages: read
2825
contents: read
2926
actions: write
3027
steps:
3128
- uses: actions/checkout@v4
3229
with:
3330
lfs: true
31+
- uses: MatrixAI/.github/.github/actions/install-nix@master
3432
- name: Run build
3533
env:
3634
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
@@ -49,13 +47,10 @@ jobs:
4947
name: "Master / Deployment"
5048
runs-on: ubuntu-latest
5149
needs: master-build
52-
container:
53-
image: ghcr.io/matrixai/github-runner
5450
concurrency:
5551
group: master-deployment
5652
cancel-in-progress: false
5753
permissions:
58-
packages: read
5954
contents: read
6055
steps:
6156
- name: Checkout Actions
@@ -64,6 +59,7 @@ jobs:
6459
repository: MatrixAI/.github
6560
ref: ${{ inputs.ref }}
6661
path: tmp/.github
62+
- uses: MatrixAI/.github/.github/actions/install-nix@master
6763
- name: Parse Secrets
6864
uses: ./tmp/.github/.github/actions/secrets-parse
6965
with:
@@ -82,4 +78,4 @@ jobs:
8278
echo 'Perform service deployment for master'
8379
nix develop .#ci --command bash -c $'
8480
npm run deploy -- --env master
85-
'
81+
'

.github/workflows/application-js-cloudflare-staging.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ jobs:
3131
staging-lint:
3232
name: "Staging / Lint"
3333
runs-on: ubuntu-latest
34-
container:
35-
image: ghcr.io/matrixai/github-runner
3634
permissions:
37-
packages: read
3835
contents: read
3936
steps:
4037
- uses: actions/checkout@v4
4138
with:
4239
lfs: true
40+
- uses: MatrixAI/.github/.github/actions/install-nix@master
4341
- name: Run linting
4442
env:
4543
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
@@ -53,7 +51,6 @@ jobs:
5351
name: "Staging / Merge Begin"
5452
runs-on: ubuntu-latest
5553
permissions:
56-
packages: read
5754
contents: read
5855
pull-requests: write
5956
steps:
@@ -78,16 +75,14 @@ jobs:
7875
staging-build:
7976
name: "Staging / Build"
8077
runs-on: ubuntu-latest
81-
container:
82-
image: ghcr.io/matrixai/github-runner
8378
permissions:
84-
packages: read
8579
contents: read
8680
actions: write
8781
steps:
8882
- uses: actions/checkout@v4
8983
with:
9084
lfs: true
85+
- uses: MatrixAI/.github/.github/actions/install-nix@master
9186
- name: Run build
9287
env:
9388
NIX_CONFIG: access-tokens = github.com=${{ secrets.NIXPKGS_PRIVATE_PAT }}
@@ -106,13 +101,10 @@ jobs:
106101
name: "Staging / Deployment"
107102
runs-on: ubuntu-latest
108103
needs: staging-build
109-
container:
110-
image: ghcr.io/matrixai/github-runner
111104
concurrency:
112105
group: staging-deployment
113106
cancel-in-progress: false
114107
permissions:
115-
packages: read
116108
contents: read
117109
steps:
118110
- name: Checkout Actions
@@ -121,6 +113,7 @@ jobs:
121113
repository: MatrixAI/.github
122114
ref: ${{ inputs.ref }}
123115
path: tmp/.github
116+
- uses: MatrixAI/.github/.github/actions/install-nix@master
124117
- name: Parse Secrets
125118
uses: ./tmp/.github/.github/actions/secrets-parse
126119
with:
@@ -153,7 +146,6 @@ jobs:
153146
group: staging-merge-finish
154147
cancel-in-progress: true
155148
permissions:
156-
packages: read
157149
contents: write
158150
pull-requests: write
159151
steps:
@@ -176,4 +168,4 @@ jobs:
176168
--repo "$GITHUB_REPOSITORY"
177169
git checkout master
178170
git merge --ff-only "$GITHUB_SHA"
179-
git push origin master
171+
git push origin master

0 commit comments

Comments
 (0)