Skip to content

Commit

Permalink
nix: Provide lib in flakes with buildPgxExtension (#358)
Browse files Browse the repository at this point in the history
Signed-off-by: Ana Hobden <[email protected]>
  • Loading branch information
Hoverbear authored Jan 3, 2022
1 parent 3aae527 commit 77314d5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
.idea/
/target
target/
*.iml
**/*.rs.bk
*.o
Expand Down
76 changes: 22 additions & 54 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,33 @@
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in
{
defaultPackage = forAllSystems (system: (import nixpkgs {
supportedPostgresVersions = [ 10 11 12 13 14 ];
nixpkgsWithOverlays = { system, nixpkgs, extraOverlays ? [ ] }: (import nixpkgs {
inherit system;
overlays = [
self.overlay
rust-overlay.overlay
(self: super:
{
rustc = self.rust-bin.stable.latest.rustc;
cargo = self.rust-bin.stable.latest.cargo;
rustdoc = self.rust-bin.stable.latest.rustdoc;
}
)
];
}).cargo-pgx);
(self: super: { inherit (self.rust-bin.stable.latest) rustc cargo rustdoc; })
] ++ extraOverlays;
});
releaseAndDebug = attr: call: args: {
"${attr}" = call args;
"${attr}_debug" = call (args // { release = false; });
};
in
{
lib = {
inherit supportedSystems supportedPostgresVersions forAllSystems nixpkgsWithOverlays;
buildPgxExtension = { pkgs, source, pgxPostgresVersion, release ? true }: pkgs.callPackage ./nix/extension.nix {
inherit source pgxPostgresVersion release naersk;
inherit (gitignore.lib) gitignoreSource;
};
};
defaultPackage = forAllSystems (system: (nixpkgsWithOverlays { inherit system nixpkgs; }).cargo-pgx);

packages = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
rust-overlay.overlay
(self: super:
{
rustc = self.rust-bin.stable.latest.rustc;
cargo = self.rust-bin.stable.latest.cargo;
rustdoc = self.rust-bin.stable.latest.rustdoc;
}
)
];
};
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
in
{
inherit (pkgs) cargo-pgx;
Expand All @@ -67,20 +61,7 @@

devShell = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
rust-overlay.overlay
(self: super:
{
rustc = self.rust-bin.stable.latest.rustc;
cargo = self.rust-bin.stable.latest.cargo;
rustdoc = self.rust-bin.stable.latest.rustdoc;
}
)
];
};
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
in
pkgs.mkShell {
inputsFrom = with pkgs; [
Expand Down Expand Up @@ -112,20 +93,7 @@

checks = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
rust-overlay.overlay
(self: super:
{
rustc = self.rust-bin.stable.latest.rustc;
cargo = self.rust-bin.stable.latest.cargo;
rustdoc = self.rust-bin.stable.latest.rustdoc;
}
)
];
};
pkgs = nixpkgsWithOverlays { inherit system nixpkgs; };
in
{
format = pkgs.runCommand "check-format"
Expand Down
6 changes: 4 additions & 2 deletions nix/templates/default/default.nix → nix/extension.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
, gitignoreSource
, pgxPostgresVersion ? 11
, release ? true
, source ? ./.
, runCommand
}:

let
Expand All @@ -34,15 +36,15 @@ let
else null;
maybeReleaseFlag = if release == true then "--release" else "";
pgxPostgresVersionString = builtins.toString pgxPostgresVersion;
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
cargoToml = (builtins.fromTOML (builtins.readFile "${source}/Cargo.toml"));
in

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

src = gitignoreSource ./.;
src = gitignoreSource source;

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

Expand Down
95 changes: 81 additions & 14 deletions nix/templates/default/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 77314d5

Please sign in to comment.