Skip to content

Commit

Permalink
Nix debug option (#349)
Browse files Browse the repository at this point in the history
* Add debug option to nix template

Signed-off-by: Ana Hobden <[email protected]>

* Slightly nicer nix code

Signed-off-by: Ana Hobden <[email protected]>

* Add gitignore for smaller closures

Signed-off-by: Ana Hobden <[email protected]>
  • Loading branch information
Hoverbear authored Dec 26, 2021
1 parent 90db903 commit 3aae527
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 28 deletions.
21 changes: 19 additions & 2 deletions cargo-pgx/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
{ lib, naersk, hostPlatform, fetchFromGitHub, postgresql_10, postgresql_11, postgresql_12, postgresql_13, pkg-config, openssl, rustfmt, libiconv, llvmPackages, }:
{ lib
, naersk
, hostPlatform
, fetchFromGitHub
, postgresql_10
, postgresql_11
, postgresql_12
, postgresql_13
, pkg-config
, openssl
, rustfmt
, libiconv
, llvmPackages
, gitignoreSource
, release ? true
,
}:

let
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
Expand All @@ -8,7 +24,8 @@ naersk.lib."${hostPlatform.system}".buildPackage rec {
name = cargoToml.package.name;
version = cargoToml.package.version;

src = ../.;
src = gitignoreSource ../.;
inherit release;

cargoBuildOptions = final: final ++ [ "--package" "cargo-pgx" ];
cargoTestOptions = final: final ++ [ "--package" "cargo-pgx" ];
Expand Down
21 changes: 21 additions & 0 deletions flake.lock

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

16 changes: 13 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
gitignore.url = "github:hercules-ci/gitignore.nix";
gitignore.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, rust-overlay, naersk }:
outputs = { self, nixpkgs, rust-overlay, naersk, gitignore }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
Expand Down Expand Up @@ -52,7 +54,15 @@
});

overlay = final: prev: {
cargo-pgx = final.callPackage ./cargo-pgx { inherit naersk; };
cargo-pgx = final.callPackage ./cargo-pgx {
inherit naersk;
gitignoreSource = gitignore.lib.gitignoreSource;
};
cargo-pgx_debug = final.callPackage ./cargo-pgx {
inherit naersk;
release = false;
gitignoreSource = gitignore.lib.gitignoreSource;
};
};

devShell = forAllSystems (system:
Expand Down Expand Up @@ -126,7 +136,7 @@
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.}
touch $out # it worked!
'';
pkgs-cargo-pgx = pkgs.cargo-pgx.out;
pkgs-cargo-pgx = pkgs.cargo-pgx_debug.out;
});

defaultTemplate = self.templates.default;
Expand Down
8 changes: 6 additions & 2 deletions nix/templates/default/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
, rustc
, llvmPackages
, gcc
, gitignoreSource
, pgxPostgresVersion ? 11
, release ? true
}:

let
Expand All @@ -30,15 +32,17 @@ let
else if (pgxPostgresVersion == 13) then postgresql_13
else if (pgxPostgresVersion == 14) then postgresql_14
else null;
maybeReleaseFlag = if release == true then "--release" else "";
pgxPostgresVersionString = builtins.toString pgxPostgresVersion;
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
in

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

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

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

Expand Down Expand Up @@ -115,7 +119,7 @@ naersk.lib."${targetPlatform.system}".buildPackage rec {
'';
postBuild = ''
export PGX_HOME=$out/.pgx
${cargo-pgx}/bin/cargo-pgx pgx schema --skip-build --release
${cargo-pgx}/bin/cargo-pgx pgx schema --skip-build ${maybeReleaseFlag}
cp -v ./sql/* $out/
cp -v ./${cargoToml.package.name}.control $out/${cargoToml.package.name}.control
'';
Expand Down
146 changes: 146 additions & 0 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 3aae527

Please sign in to comment.