Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/actions/install-nix/setup-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ cat >"$tmpdir/nix.conf" <<-EOF
max-jobs = 5
EOF

if [[ -d /mnt/nix-store-disk ]]; then
echo 'extra-substituters = local?root=/mnt/nix-store-disk' >>"$tmpdir/nix.conf"
fi

if [[ -e /dev/kvm ]]; then
sudo chown runner /dev/kvm
sudo chmod 666 /dev/kvm
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ workflows:
- 'actions/download-artifact@v8.0.2'
- 'actions/upload-artifact@v7.0.2'
- 'aws-actions/configure-aws-credentials@v6.3.0'
- 'useblacksmith/stickydisk@v1.8.0'
'.github/workflows/nix-dependency-analysis.yml':
- 'actions/checkout@v7.0.1'
- 'aws-actions/configure-aws-credentials@v6.3.0'
- 'peter-evans/create-or-update-comment@v5.0.0'
- 'peter-evans/find-comment@v4.0.0'
'.github/workflows/nix-store-disk.yml':
- 'actions/checkout@v7.0.1'
- 'aws-actions/configure-aws-credentials@v6.3.0'
- 'useblacksmith/stickydisk@v1.8.0'
'.github/workflows/public-integration-doorbell.yml': []
'.github/workflows/publish-migrations-prod.yml':
- 'actions/checkout@v7.0.1'
Expand Down Expand Up @@ -238,3 +243,8 @@ dependencies:
commit: 'sha1-8a0cd651e5b2365bd640854a3fa5dfc70e4875f3'
owner_id: 2242
repo_id: 204253808
'useblacksmith/stickydisk@v1.8.0':
ref: 'v1.8.0'
commit: 'sha1-61dac6a8aa5927f7d3343d9dbdc8153787d08a1c'
owner_id: 156274793
repo_id: 899799214
24 changes: 24 additions & 0 deletions .github/workflows/nix-ci-per-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ jobs:
- name: Checkout Repo
if: ${{ matrix.attr != '' }}
uses: actions/checkout@v7.0.1
- name: Mount nix store disk
if: ${{ matrix.attr != '' && runner.os == 'Linux' }}
continue-on-error: true
uses: useblacksmith/stickydisk@v1.8.0
with:
key: nix-store-${{ runner.arch }}
path: /mnt/nix-store-disk
commit: false
- name: Install nix
if: ${{ matrix.attr != '' }}
uses: $/.github/actions/install-nix
Expand Down Expand Up @@ -140,6 +148,14 @@ jobs:
- name: Checkout Repo
if: ${{ matrix.attr != '' }}
uses: actions/checkout@v7.0.1
- name: Mount nix store disk
if: ${{ matrix.attr != '' && runner.os == 'Linux' }}
continue-on-error: true
uses: useblacksmith/stickydisk@v1.8.0
with:
key: nix-store-${{ runner.arch }}
path: /mnt/nix-store-disk
commit: false
- name: Install nix
if: ${{ matrix.attr != '' }}
uses: $/.github/actions/install-nix
Expand Down Expand Up @@ -167,6 +183,14 @@ jobs:
- name: Checkout Repo
if: ${{ matrix.attr != '' }}
uses: actions/checkout@v7.0.1
- name: Mount nix store disk
if: ${{ matrix.attr != '' && runner.os == 'Linux' }}
continue-on-error: true
uses: useblacksmith/stickydisk@v1.8.0
with:
key: nix-store-${{ runner.arch }}
path: /mnt/nix-store-disk
commit: false
- name: Install nix
if: ${{ matrix.attr != '' }}
uses: $/.github/actions/install-nix
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/nix-store-disk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Nix store disk

# The only workflow that commits the disk. CI jobs mount it with commit: false.

on:
push:
branches:
- develop
workflow_dispatch:

permissions:
contents: read

jobs:
refresh:
strategy:
fail-fast: false
matrix:
runner: [blacksmith-8vcpu-ubuntu-2404, blacksmith-8vcpu-ubuntu-2404-arm]
runs-on: ${{ matrix.runner }}
concurrency: nix-store-disk-${{ matrix.runner }}
steps:
- name: Checkout Repo
uses: actions/checkout@v7.0.1

- name: Install nix
uses: $/.github/actions/install-nix

- name: Mount nix store disk
uses: useblacksmith/stickydisk@v1.8.0
with:
key: nix-store-${{ runner.arch }}
path: /mnt/nix-store-disk

- name: Substitute build inputs onto the disk
run: |
set -euo pipefail
disk=/mnt/nix-store-disk
store="local?root=$disk"
roots=$disk/nix/var/nix/gcroots/ci
paths=$RUNNER_TEMP/paths
sudo chown "$(id -u)" "$disk"

nix eval --json ".#ciBuildInputs.$(nix config show system)" | jq --raw-output '.[]' >"$paths"

xargs --arg-file="$paths" --no-run-if-empty \
nix build --store "$store" --max-jobs 0 --keep-going --no-link \
|| echo "::warning::some build inputs could not be substituted"

rm -rf "$roots"
mkdir -p "$roots"
xargs --arg-file="$paths" ln --symbolic --target-directory="$roots"
nix store gc --store "$store"
df --human-readable "$disk"
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
imports = [
nix/apps.nix
nix/checks.nix
nix/ci-build-inputs.nix
nix/config.nix
nix/devShells.nix
nix/fmt.nix
Expand Down
34 changes: 34 additions & 0 deletions nix/ci-build-inputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
self,
lib,
config,
...
}:
let
# NixOS tests are lazy derivations, which hide drvAttrs.
buildAttrs = drv: drv.drvAttrs or drv.config.rawTestDerivation.drvAttrs or { };

directInputs =
drv:
lib.concatLists (
lib.mapAttrsToList (
path: context:
map (output: builtins.unsafeDiscardStringContext (import path).${output}.outPath) (
context.outputs or [ ]
)
) (builtins.getContext (builtins.toJSON (buildAttrs drv)))
);
in
{
flake.ciBuildInputs = lib.genAttrs config.systems (
system:
lib.unique (
lib.concatMap directInputs (
lib.concatMap (lib.collect lib.isDerivation) [
self.checks.${system}
self.legacyPackages.${system}
]
)
)
);
}
Loading