Skip to content

Commit 8516c7b

Browse files
committed
feat: we can pull paths from manifest for installed packages
1 parent aac53fa commit 8516c7b

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

.github/workflows/ami-release-nix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ jobs:
242242
run: |
243243
VERSION="${{ steps.process_release_version.outputs.version }}"
244244
245-
# Check if comprehensive SBOM exists (generated during AMI build)
246245
if [ -f "nix-sbom.spdx.json" ]; then
247246
aws s3 cp nix-sbom.spdx.json \
248247
"s3://${{ secrets.SHARED_AWS_ARTIFACTS_BUCKET }}/sbom/${VERSION}/sbom.spdx.json" \
249248
--content-type "application/json"
250249
echo "::notice title=SBOM Uploaded::Comprehensive SBOM for ${VERSION} uploaded to shared artifacts"
251250
else
252-
echo "::warning title=SBOM Missing::Comprehensive SBOM file not found, skipping upload"
251+
echo "::error title=SBOM Missing::SBOM file not found - build cannot proceed without SBOM"
252+
exit 1
253253
fi
254254
255255
- name: Create release

nix/packages/sbom/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,32 @@ let
4343
fi
4444
done | sort -u | grep -v '^$'
4545
'';
46+
47+
# Combined wrapper that collects paths from profiles and generates SBOM
48+
sbom-from-profiles = pkgs.writeShellScriptBin "sbom-from-profiles" ''
49+
set -euo pipefail
50+
OUTPUT="''${1:-/tmp/nix-sbom.spdx.json}"
51+
52+
# Collect store paths from user profiles
53+
PATHS=$(${collect-nix-paths}/bin/collect-nix-paths)
54+
55+
# Build --nix-target arguments
56+
ARGS=""
57+
while IFS= read -r path; do
58+
[ -n "$path" ] && ARGS="$ARGS --nix-target $path"
59+
done <<< "$PATHS"
60+
61+
# Generate combined SBOM
62+
${sbom-generator}/bin/sbom-generator $ARGS --output "$OUTPUT"
63+
'';
4664
in
4765
{
4866
inherit
4967
sbom
5068
sbom-ubuntu
5169
sbom-nix
5270
sbom-generator
71+
sbom-from-profiles
5372
collect-nix-paths
5473
sbomnix
5574
;

scripts/nix-provision.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,22 @@ function cleanup_packages {
6464
sudo add-apt-repository --yes --remove ppa:ansible/ansible
6565
}
6666

67+
function generate_sbom {
68+
echo "Generating combined SBOM from installed profiles..."
69+
70+
# Generate SBOM using the flake from GitHub at this exact commit
71+
nix run "github:supabase/postgres/${GIT_SHA}#sbom-from-profiles" -- /tmp/nix-sbom.spdx.json
72+
73+
echo "SBOM generated at /tmp/nix-sbom.spdx.json"
74+
75+
# Clean up SBOM tooling and old generations from nix store
76+
nix-collect-garbage -d
77+
78+
echo "Nix garbage collection complete"
79+
}
80+
6781
install_packages
6882
install_nix
6983
execute_stage2_playbook
84+
generate_sbom
7085
cleanup_packages

stage2-nix-psql.pkr.hcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,11 @@ build {
128128
script = "scripts/nix-provision.sh"
129129
}
130130

131+
# Download SBOM from AMI to runner
132+
provisioner "file" {
133+
source = "/tmp/nix-sbom.spdx.json"
134+
destination = "nix-sbom.spdx.json"
135+
direction = "download"
136+
}
137+
131138
}

0 commit comments

Comments
 (0)