Skip to content

Commit 362fdc9

Browse files
committed
Use nix-fast-build to build all checks
CI build the required nix packages defined in flake checks. We use the `nix-fast-build` tool to speed up the evaluation and build process. We now use the same GitHub action to install nix. We upload the build results to the cache using a post build hook.
1 parent 2bdd0f9 commit 362fdc9

File tree

3 files changed

+31
-65
lines changed

3 files changed

+31
-65
lines changed

.github/workflows/nix-build.yml

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,36 @@ jobs:
4343
python -c "import os; file = open('nix-secret-key', 'w'); file.write(os.environ['NIX_SIGN_SECRET_KEY']); file.close()"
4444
env:
4545
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
46-
- name: Log in to Docker Hub
47-
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13' && github.secret_source == 'Actions'
48-
uses: docker/login-action@v2
46+
- name: Setup cache script
47+
if: ${{ github.secret_source == 'Actions' }}
48+
run: |
49+
mkdir -p /etc/nix
50+
cat << 'EOF' | sudo tee /etc/nix/upload-to-cache.sh > /dev/null
51+
#!/usr/bin/env bash
52+
set -eouf
53+
export IFS=' '
54+
echo /nix/var/nix/profiles/default/bin/nix copy --to 's3://nix-postgres-artifacts?secret-key=nix-secret-key' \$OUT_PATHS
55+
EOF
56+
chmod +x /etc/nix/upload-to-cache.sh
57+
- name: Install nix
58+
uses: DeterminateSystems/nix-installer-action@main
59+
if: ${{ github.secret_source == 'Actions' }}
4960
with:
50-
username: ${{ secrets.DOCKER_USERNAME }}
51-
password: ${{ secrets.DOCKER_PASSWORD }}
52-
- name: Build psql bundle with nix
53-
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13'
54-
run: docker build -t base_nix -f docker/nix/Dockerfile .
55-
- name: Run build psql bundle
56-
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13'
57-
run: |
58-
docker run -e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
59-
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
60-
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
61-
base_nix bash -c "./workspace/docker/nix/build_nix.sh"
62-
- name: Build psql bundle on macos
63-
if: matrix.runner == 'macos-latest' || matrix.runner == 'macos-13'
61+
extra-conf: |
62+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
63+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
64+
post-build-hook = /etc/nix/upload-to-cache.sh
65+
- name: Install nix
66+
uses: DeterminateSystems/nix-installer-action@main
67+
if: ${{ github.secret_source == 'None' }}
68+
with:
69+
extra-conf: |
70+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
71+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
72+
- name: Build psql bundle
6473
run: |
65-
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm \
66-
--extra-conf "substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com" \
67-
--extra-conf "trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
68-
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
69-
cp ./docker/nix/build_nix.sh ./build_nix.sh
70-
sed -i '' '1s|^#!/bin/env bash|#!/usr/bin/env bash|' ./build_nix.sh
71-
chmod +x ./build_nix.sh
72-
./build_nix.sh
74+
./docker/nix/build_nix.sh
7375
env:
7476
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
7577
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
7678
AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
77-
78-
name: build psql bundle on ${{ matrix.arch }}
79-

docker/nix/build_nix.sh

100644100755
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,4 @@ if [ -d "/workspace" ]; then
66
cd /workspace
77
fi
88

9-
SYSTEM=$(nix-instantiate --eval -E builtins.currentSystem | tr -d '"')
10-
11-
nix build .#checks.$SYSTEM.psql_15 -L --no-link
12-
nix build .#checks.$SYSTEM.psql_orioledb-17 -L --no-link
13-
nix build .#checks.$SYSTEM.psql_17 -L --no-link
14-
nix build .#psql_15/bin -o psql_15 -L
15-
nix build .#psql_orioledb-17/bin -o psql_orioledb_17 -L
16-
nix build .#psql_17/bin -o psql_17 -L
17-
nix build .#wal-g-2 -o wal-g-2 -L
18-
nix build .#wal-g-3 -o wal-g-3 -L
19-
20-
# Copy to S3
21-
if [[ -n "${AWS_ACCESS_KEY_ID-}" && -n "${AWS_SECRET_ACCESS_KEY-}" ]]; then
22-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-2
23-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-3
24-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_15
25-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_orioledb_17
26-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_17
27-
fi
28-
29-
if [ "$SYSTEM" = "aarch64-linux" ]; then
30-
nix build .#postgresql_15_debug -o ./postgresql_15_debug
31-
nix build .#postgresql_15_src -o ./postgresql_15_src
32-
nix build .#postgresql_orioledb-17_debug -o ./postgresql_orioledb-17_debug
33-
nix build .#postgresql_orioledb-17_src -o ./postgresql_orioledb-17_src
34-
nix build .#postgresql_17_debug -o ./postgresql_17_debug
35-
nix build .#postgresql_17_src -o ./postgresql_17_src
36-
37-
if [[ -n "${AWS_ACCESS_KEY_ID-}" && -n "${AWS_SECRET_ACCESS_KEY-}" ]]; then
38-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_15_debug-debug
39-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_15_src
40-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_debug-debug
41-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_src
42-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_17_debug-debug
43-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_17_src
44-
fi
45-
fi
9+
nix run "github:Mic92/nix-fast-build?rev=b1dae483ab7d4139a6297e02b6de9e5d30e43d48" -- --skip-cached --no-nom --flake ".#checks"

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,9 @@
13821382
psql_15 = makeCheckHarness basePackages.psql_15.bin;
13831383
psql_17 = makeCheckHarness basePackages.psql_17.bin;
13841384
psql_orioledb-17 = makeCheckHarness basePackages.psql_orioledb-17.bin;
1385+
inherit (basePackages) wal-g-2 wal-g-3;
1386+
} // pkgs.lib.optionalAttrs (system == "aarch64-linux") {
1387+
inherit (basePackages) postgresql_15_debug postgresql_15_src postgresql_orioledb-17_debug postgresql_orioledb-17_src postgresql_17_debug postgresql_17_src;
13851388
};
13861389

13871390
# Apps is a list of names of things that can be executed with 'nix run';

0 commit comments

Comments
 (0)