-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
184 lines (163 loc) · 7.41 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
rust-overlay,
}:
let
forAllSystems =
fn:
let
systems = [ "x86_64-linux" ];
overlays = [ (import rust-overlay) ];
in
nixpkgs.lib.genAttrs systems (
system:
fn (
import nixpkgs {
inherit system overlays;
}
)
);
in
{
devShells = forAllSystems (
pkgs:
let
cargo-pgrx = import ./nix/pgrx.nix { inherit pkgs; };
in
{
default = pkgs.mkShell {
buildInputs = [
cargo-pgrx
pkgs.bacon
pkgs.rust-analyzer
pkgs.rust-bin.stable.latest.default
];
inputsFrom = with pkgs; [
postgresql_12
postgresql_13
postgresql_14
postgresql_15
postgresql_16
postgresql_17
];
nativeBuildInputs = [
pkgs.rustPlatform.bindgenHook
];
};
}
);
packages = forAllSystems (
pkgs:
let
cargo-pgrx = import ./nix/pgrx.nix { inherit pkgs; };
pname = "pglite-fusion";
version = "0.0.3";
buildPgliteFusionImage =
{
imageDigest,
imageSha256,
postgresDev,
}:
let
postgresMajor = pkgs.lib.versions.major postgresDev.version;
postgresImage = pkgs.dockerTools.pullImage {
imageName = "postgres";
imageDigest = imageDigest;
sha256 = imageSha256;
};
extension = pkgs.stdenv.mkDerivation {
pname = "${pname}-pg${postgresMajor}-extension";
inherit version;
src = import ./nix/build.nix {
inherit pkgs cargo-pgrx;
postgresql = postgresDev;
};
buildPhase = ''
install --directory $out/usr/share/postgresql/${postgresMajor}/extension
cp -r $src/nix/store/*/share/postgresql/extension/* $out/usr/share/postgresql/${postgresMajor}/extension
install --directory $out/usr/lib/postgresql/${postgresMajor}/lib
cp -r $src/nix/store/*/lib/* $out/usr/lib/postgresql/${postgresMajor}/lib
'';
};
in
pkgs.dockerTools.buildLayeredImage {
name = "${pname}-pg${postgresMajor}";
fromImage = postgresImage;
contents = [ extension ];
config = {
Env = [ "POSTGRES_HOST_AUTH_METHOD=trust" ];
Expose = 5432;
Cmd = [ "postgres" ];
Entrypoint = [ "docker-entrypoint.sh" ];
};
};
pg12 = buildPgliteFusionImage {
imageDigest = "sha256:ee9f333b422b396016648289933a8f2d3ffa79703510b2e0641e3a4a125b96b6";
imageSha256 = "sha256-f+OkqB6mW8UP0Z6fCCfAB257ztQAtaPQ2T2SVlu8MmY=";
postgresDev = pkgs.postgresql_12.dev;
};
pg13 = buildPgliteFusionImage {
imageDigest = "sha256:80ff9e2086e68aef09839045df1f07016b869d94cbd12c6462a4b300878cfdac";
imageSha256 = "sha256-iaUdJa/l0rgNkZR/FUoJ4bzmW/2CRWyk+eMHibBqIus=";
postgresDev = pkgs.postgresql_13.dev;
};
pg14 = buildPgliteFusionImage {
imageDigest = "sha256:78b9deeca08fa9749a00e9d30bc879f8f8d021af854c73e2c339b752cb6d708a";
imageSha256 = "sha256-LV2V6kuctIjN4gMxfopZSdivFtz7ks+AGmYQ4ets8b0=";
postgresDev = pkgs.postgresql_14.dev;
};
pg15 = buildPgliteFusionImage {
imageDigest = "sha256:a35b3c0190dac5a82ec1778b34cb4963bdd9d161f80381a6297be6e2c3c13a7c";
imageSha256 = "sha256-ZK6eBPA50mY99uSF3+UdT4eBm/3komc6sfWb1qw1N7k=";
postgresDev = pkgs.postgresql_15.dev;
};
pg16 = buildPgliteFusionImage {
imageDigest = "sha256:5d65b8bdb20369ea902b987aa63cfe4983130bc8cd2c25830d126636b80b608d";
imageSha256 = "sha256-5JhtZaCLj6SnJzjhC5A2yrP6fipuaQKHSxm3jhxSfNg=";
postgresDev = pkgs.postgresql_16.dev;
};
pg17 = buildPgliteFusionImage {
imageDigest = "sha256:994cc3113ce004ae73df11f0dbc5088cbe6bb0da1691dd7e6f55474202a4f211";
imageSha256 = "sha256-OzqtbX89/lBP2mzhSccuad5suUz/uw/gBgeIW3BTbdc=";
postgresDev = pkgs.postgresql_17.dev;
};
in
{
inherit
pg12
pg13
pg14
pg15
pg16
pg17
;
deploy = pkgs.writeShellScriptBin "deploy" ''
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg12} docker://docker.io/frectonz/${pname}:pg12-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg12-${version} docker://docker.io/frectonz/${pname}:pg12 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg13} docker://docker.io/frectonz/${pname}:pg13-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg13-${version} docker://docker.io/frectonz/${pname}:pg13 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg14} docker://docker.io/frectonz/${pname}:pg14-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg14-${version} docker://docker.io/frectonz/${pname}:pg14 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg15} docker://docker.io/frectonz/${pname}:pg15-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg15-${version} docker://docker.io/frectonz/${pname}:pg15 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg16} docker://docker.io/frectonz/${pname}:pg16-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg16-${version} docker://docker.io/frectonz/${pname}:pg16 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker-archive:${pg17} docker://docker.io/frectonz/${pname}:pg17-${version} --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg17-${version} docker://docker.io/frectonz/${pname}:pg17 --dest-creds="frectonz:$ACCESS_TOKEN"
${pkgs.skopeo}/bin/skopeo --insecure-policy copy docker://docker.io/frectonz/${pname}:pg17 docker://docker.io/frectonz/${pname}:latest --dest-creds="frectonz:$ACCESS_TOKEN"
'';
}
);
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}