Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: Provide lib in flakes with buildPgxExtension #358

Merged
merged 7 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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