Skip to content

Commit 8cd1a75

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 87829eb commit 8cd1a75

File tree

3 files changed

+22
-60
lines changed

3 files changed

+22
-60
lines changed

.github/workflows/nix-build.yml

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

docker/nix/build_nix.sh

100644100755
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +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-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-2
22-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-3
23-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_15
24-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_orioledb_17
25-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_17
26-
27-
if [ "$SYSTEM" = "aarch64-linux" ]; then
28-
nix build .#postgresql_15_debug -o ./postgresql_15_debug
29-
nix build .#postgresql_15_src -o ./postgresql_15_src
30-
nix build .#postgresql_orioledb-17_debug -o ./postgresql_orioledb-17_debug
31-
nix build .#postgresql_orioledb-17_src -o ./postgresql_orioledb-17_src
32-
nix build .#postgresql_17_debug -o ./postgresql_17_debug
33-
nix build .#postgresql_17_src -o ./postgresql_17_src
34-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_15_debug-debug
35-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_15_src
36-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_debug-debug
37-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_orioledb-17_src
38-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_17_debug-debug
39-
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./postgresql_17_src
40-
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)