22 lib ,
33 stdenv ,
44 writeShellApplication ,
5+ writeText ,
56 jq ,
7+ # Slim packages used in Docker images
8+ psql_15_slim ,
9+ psql_17_slim ,
10+ psql_orioledb-17_slim ,
11+ # Groonga is also installed in images
12+ supabase-groonga ,
613} :
714
815let
916 root = ../.. ;
1017
11- # Bundle all files that affect Docker image builds
12- # When any of these change, the derivation hash changes
18+ # Bundle all source files that are copied into Docker images
1319 dockerSources = stdenv . mkDerivation {
1420 name = "docker-image-sources" ;
1521 src = lib . fileset . toSource {
3036
3137 # Database migrations (copied into images)
3238 ( root + "/migrations/db" )
33-
34- # Nix flake (defines the psql packages used in images)
35- ( root + "/flake.nix" )
36- ( root + "/flake.lock" )
37-
38- # Nix package definitions that affect slim images
39- ( root + "/nix/packages" )
40- ( root + "/nix/config.nix" )
41- ( root + "/nix/overlays" )
42-
43- # PostgreSQL and extension definitions
44- ( root + "/nix/ext" )
45- ( root + "/nix/postgresql" )
4639 ] ;
4740 } ;
4841
5548 cp -r . $out/
5649 '' ;
5750 } ;
51+
52+ # Create a manifest of all package store paths
53+ # This ensures the hash changes when any package changes
54+ packageManifest = writeText "docker-image-packages-manifest" ''
55+ # Slim PostgreSQL packages installed in Docker images
56+ psql_15_slim=${ psql_15_slim }
57+ psql_17_slim=${ psql_17_slim }
58+ psql_orioledb-17_slim=${ psql_orioledb-17_slim }
59+
60+ # Groonga (installed in all images)
61+ supabase-groonga=${ supabase-groonga }
62+ '' ;
63+
64+ # Combined derivation that depends on both sources and packages
65+ dockerImageInputs = stdenv . mkDerivation {
66+ name = "docker-image-inputs" ;
67+
68+ # No source needed - we just create a manifest
69+ dontUnpack = true ;
70+
71+ # These are the actual dependencies that affect the hash
72+ buildInputs = [
73+ dockerSources
74+ psql_15_slim
75+ psql_17_slim
76+ psql_orioledb-17_slim
77+ supabase-groonga
78+ ] ;
79+
80+ installPhase = ''
81+ mkdir -p $out
82+
83+ # Include source files reference
84+ echo "sources=${ dockerSources } " > $out/manifest
85+
86+ # Include package manifest
87+ cat ${ packageManifest } >> $out/manifest
88+
89+ # Create a combined hash from all inputs
90+ echo "" >> $out/manifest
91+ echo "# Combined input paths:" >> $out/manifest
92+ echo "${ dockerSources } " >> $out/manifest
93+ echo "${ psql_15_slim } " >> $out/manifest
94+ echo "${ psql_17_slim } " >> $out/manifest
95+ echo "${ psql_orioledb-17_slim } " >> $out/manifest
96+ echo "${ supabase-groonga } " >> $out/manifest
97+ '' ;
98+ } ;
5899in
59100writeShellApplication {
60101 name = "docker-image-inputs-hash" ;
@@ -64,24 +105,42 @@ writeShellApplication {
64105 text = ''
65106 set -euo pipefail
66107
67- DOCKER_SOURCES ="${ dockerSources } "
68- INPUT_HASH=$(basename "$DOCKER_SOURCES " | cut -d- -f1)
108+ DOCKER_INPUTS ="${ dockerImageInputs } "
109+ INPUT_HASH=$(basename "$DOCKER_INPUTS " | cut -d- -f1)
69110
70111 case "'' ${1:-hash}" in
71112 hash)
72113 echo "$INPUT_HASH"
73114 ;;
74115 path)
75- echo "$DOCKER_SOURCES"
116+ echo "$DOCKER_INPUTS"
117+ ;;
118+ manifest)
119+ cat "$DOCKER_INPUTS/manifest"
76120 ;;
77121 json)
78122 jq -n \
79123 --arg hash "$INPUT_HASH" \
80- --arg path "$DOCKER_SOURCES" \
81- '{hash: $hash, path: $path}'
124+ --arg path "$DOCKER_INPUTS" \
125+ --arg sources "${ dockerSources } " \
126+ --arg psql_15_slim "${ psql_15_slim } " \
127+ --arg psql_17_slim "${ psql_17_slim } " \
128+ --arg psql_orioledb_17_slim "${ psql_orioledb-17_slim } " \
129+ --arg supabase_groonga "${ supabase-groonga } " \
130+ '{
131+ hash: $hash,
132+ path: $path,
133+ sources: $sources,
134+ packages: {
135+ psql_15_slim: $psql_15_slim,
136+ psql_17_slim: $psql_17_slim,
137+ "psql_orioledb-17_slim": $psql_orioledb_17_slim,
138+ "supabase-groonga": $supabase_groonga
139+ }
140+ }'
82141 ;;
83142 *)
84- echo "Usage: docker-image-inputs-hash [hash|path|json]" >&2
143+ echo "Usage: docker-image-inputs-hash [hash|path|manifest| json]" >&2
85144 exit 1
86145 ;;
87146 esac
@@ -90,15 +149,18 @@ writeShellApplication {
90149 meta = {
91150 description = "Get the content hash of all Docker image inputs" ;
92151 longDescription = ''
93- This package bundles all source files that affect Docker image builds.
94- The hash is computed from the Nix store path, which changes when any
95- input file changes. Use this to detect when Docker images need to be
96- rebuilt and tested.
152+ This package tracks all inputs that affect Docker image builds:
153+ - Source files: Dockerfiles, configs, migrations
154+ - Nix packages: psql_*_slim, supabase-groonga
155+
156+ The hash changes when ANY of these change, including transitive
157+ dependencies of the Nix packages.
97158
98159 Usage:
99- docker-image-inputs-hash hash # Get just the hash
100- docker-image-inputs-hash path # Get the Nix store path
101- docker-image-inputs-hash json # Get both as JSON
160+ docker-image-inputs-hash hash # Get just the hash
161+ docker-image-inputs-hash path # Get the Nix store path
162+ docker-image-inputs-hash manifest # Show all tracked inputs
163+ docker-image-inputs-hash json # Get detailed JSON output
102164 '' ;
103165 } ;
104166}
0 commit comments