Skip to content

Commit 77314d5

Browse files
authored
nix: Provide lib in flakes with buildPgxExtension (#358)
Signed-off-by: Ana Hobden <[email protected]>
1 parent 3aae527 commit 77314d5

File tree

5 files changed

+136
-144
lines changed

5 files changed

+136
-144
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
.idea/
3-
/target
3+
target/
44
*.iml
55
**/*.rs.bk
66
*.o

flake.nix

+22-54
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,33 @@
1515
let
1616
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
1717
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
18-
in
19-
{
20-
defaultPackage = forAllSystems (system: (import nixpkgs {
18+
supportedPostgresVersions = [ 10 11 12 13 14 ];
19+
nixpkgsWithOverlays = { system, nixpkgs, extraOverlays ? [ ] }: (import nixpkgs {
2120
inherit system;
2221
overlays = [
2322
self.overlay
2423
rust-overlay.overlay
25-
(self: super:
26-
{
27-
rustc = self.rust-bin.stable.latest.rustc;
28-
cargo = self.rust-bin.stable.latest.cargo;
29-
rustdoc = self.rust-bin.stable.latest.rustdoc;
30-
}
31-
)
32-
];
33-
}).cargo-pgx);
24+
(self: super: { inherit (self.rust-bin.stable.latest) rustc cargo rustdoc; })
25+
] ++ extraOverlays;
26+
});
27+
releaseAndDebug = attr: call: args: {
28+
"${attr}" = call args;
29+
"${attr}_debug" = call (args // { release = false; });
30+
};
31+
in
32+
{
33+
lib = {
34+
inherit supportedSystems supportedPostgresVersions forAllSystems nixpkgsWithOverlays;
35+
buildPgxExtension = { pkgs, source, pgxPostgresVersion, release ? true }: pkgs.callPackage ./nix/extension.nix {
36+
inherit source pgxPostgresVersion release naersk;
37+
inherit (gitignore.lib) gitignoreSource;
38+
};
39+
};
40+
defaultPackage = forAllSystems (system: (nixpkgsWithOverlays { inherit system nixpkgs; }).cargo-pgx);
3441

3542
packages = forAllSystems (system:
3643
let
37-
pkgs = import nixpkgs {
38-
inherit system;
39-
overlays = [
40-
self.overlay
41-
rust-overlay.overlay
42-
(self: super:
43-
{
44-
rustc = self.rust-bin.stable.latest.rustc;
45-
cargo = self.rust-bin.stable.latest.cargo;
46-
rustdoc = self.rust-bin.stable.latest.rustdoc;
47-
}
48-
)
49-
];
50-
};
44+
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
5145
in
5246
{
5347
inherit (pkgs) cargo-pgx;
@@ -67,20 +61,7 @@
6761

6862
devShell = forAllSystems (system:
6963
let
70-
pkgs = import nixpkgs {
71-
inherit system;
72-
overlays = [
73-
self.overlay
74-
rust-overlay.overlay
75-
(self: super:
76-
{
77-
rustc = self.rust-bin.stable.latest.rustc;
78-
cargo = self.rust-bin.stable.latest.cargo;
79-
rustdoc = self.rust-bin.stable.latest.rustdoc;
80-
}
81-
)
82-
];
83-
};
64+
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
8465
in
8566
pkgs.mkShell {
8667
inputsFrom = with pkgs; [
@@ -112,20 +93,7 @@
11293

11394
checks = forAllSystems (system:
11495
let
115-
pkgs = import nixpkgs {
116-
inherit system;
117-
overlays = [
118-
self.overlay
119-
rust-overlay.overlay
120-
(self: super:
121-
{
122-
rustc = self.rust-bin.stable.latest.rustc;
123-
cargo = self.rust-bin.stable.latest.cargo;
124-
rustdoc = self.rust-bin.stable.latest.rustdoc;
125-
}
126-
)
127-
];
128-
};
96+
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
12997
in
13098
{
13199
format = pkgs.runCommand "check-format"

nix/templates/default/default.nix renamed to nix/extension.nix

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
, gitignoreSource
2323
, pgxPostgresVersion ? 11
2424
, release ? true
25+
, source ? ./.
26+
, runCommand
2527
}:
2628

2729
let
@@ -34,15 +36,15 @@ let
3436
else null;
3537
maybeReleaseFlag = if release == true then "--release" else "";
3638
pgxPostgresVersionString = builtins.toString pgxPostgresVersion;
37-
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
39+
cargoToml = (builtins.fromTOML (builtins.readFile "${source}/Cargo.toml"));
3840
in
3941

4042
naersk.lib."${targetPlatform.system}".buildPackage rec {
4143
inherit release;
4244
name = "${cargoToml.package.name}-pg${pgxPostgresVersionString}";
4345
version = cargoToml.package.version;
4446

45-
src = gitignoreSource ./.;
47+
src = gitignoreSource source;
4648

4749
inputsFrom = [ postgresql_10 postgresql_11 postgresql_12 postgresql_13 cargo-pgx ];
4850

nix/templates/default/flake.lock

+81-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)