diff --git a/.gitignore b/.gitignore index d0ba7f08d..76863da79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store .idea/ -/target +target/ *.iml **/*.rs.bk *.o diff --git a/flake.nix b/flake.nix index 2784dc325..087fcdf6c 100644 --- a/flake.nix +++ b/flake.nix @@ -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; @@ -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; [ @@ -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" diff --git a/nix/templates/default/default.nix b/nix/extension.nix similarity index 97% rename from nix/templates/default/default.nix rename to nix/extension.nix index e08e980d1..a12cf367b 100644 --- a/nix/templates/default/default.nix +++ b/nix/extension.nix @@ -22,6 +22,8 @@ , gitignoreSource , pgxPostgresVersion ? 11 , release ? true +, source ? ./. +, runCommand }: let @@ -34,7 +36,7 @@ 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 { @@ -42,7 +44,7 @@ naersk.lib."${targetPlatform.system}".buildPackage rec { 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 ]; diff --git a/nix/templates/default/flake.lock b/nix/templates/default/flake.lock index 0380c1491..c98c8e8d8 100644 --- a/nix/templates/default/flake.lock +++ b/nix/templates/default/flake.lock @@ -30,6 +30,44 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1635165013, + "narHash": "sha256-o/BdVjNwcB6jOmzZjOH703BesSkkS5O7ej3xhyO8hAY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "5b9e0ff9d3b551234b4f3eb3983744fa354b17f1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1635165013, + "narHash": "sha256-o/BdVjNwcB6jOmzZjOH703BesSkkS5O7ej3xhyO8hAY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "5b9e0ff9d3b551234b4f3eb3983744fa354b17f1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "naersk": { "inputs": { "nixpkgs": [ @@ -52,11 +90,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1640090545, - "narHash": "sha256-6qiF46uBGoSQmjDTFl8ilT+d1DuK39IRHlj0jE5gqZE=", + "lastModified": 1641194805, + "narHash": "sha256-LyPsFnE/yjzeQbqFVampztn6mKkWTD5Q2TRyrReqcZE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1dd151f0c0c216f416e9553af08f724a2499c795", + "rev": "c38ca58c0b4b5d9423609c58636988a9f81325d6", "type": "github" }, "original": { @@ -64,8 +102,39 @@ "type": "indirect" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1641194805, + "narHash": "sha256-LyPsFnE/yjzeQbqFVampztn6mKkWTD5Q2TRyrReqcZE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c38ca58c0b4b5d9423609c58636988a9f81325d6", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1641194805, + "narHash": "sha256-LyPsFnE/yjzeQbqFVampztn6mKkWTD5Q2TRyrReqcZE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c38ca58c0b4b5d9423609c58636988a9f81325d6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "pgx": { "inputs": { + "gitignore": "gitignore_2", "naersk": [ "naersk" ], @@ -75,22 +144,23 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1640192598, - "narHash": "sha256-1TycGkfjb7NJ4GnUZoEQOZ9534mlroRkjVblRgQi15k=", + "lastModified": 1641231667, + "narHash": "sha256-CCxLUvJ6TfBqnbytop4Kk08W3+pwMsZh9Vd1ps+QZXY=", "owner": "zombodb", "repo": "pgx", - "rev": "90db903c6e4bf9bf509a3ef036bc5e16a30a1e15", + "rev": "186355d9bd4c01799d9f153f8f4e7819658efdf3", "type": "github" }, "original": { "owner": "zombodb", - "ref": "develop", + "ref": "nix-lib", "repo": "pgx", "type": "github" } }, "root": { "inputs": { + "gitignore": "gitignore", "naersk": "naersk", "nixpkgs": "nixpkgs", "pgx": "pgx", @@ -100,10 +170,7 @@ "rust-overlay": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": [ - "pgx", - "nixpkgs" - ] + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1639534642, @@ -127,11 +194,11 @@ ] }, "locked": { - "lastModified": 1640140850, - "narHash": "sha256-XRfxdj6riiH+r5hPh6vxJ5rPQcsIiJ1g3XK/dMlrp3M=", + "lastModified": 1641177598, + "narHash": "sha256-ixQ72QmhIfb7bAzvLUn6GtjpoMA/N3V1PBwjZQQyc1k=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1efeb891b85c70ded412eb78a04bccb9badb14c6", + "rev": "d93e905bc0d36508590b6ec0e2e6e92d2cf8289a", "type": "github" }, "original": { diff --git a/nix/templates/default/flake.nix b/nix/templates/default/flake.nix index 247cb84ff..0a88cdbcd 100644 --- a/nix/templates/default/flake.nix +++ b/nix/templates/default/flake.nix @@ -9,7 +9,7 @@ naersk.inputs.nixpkgs.follows = "nixpkgs"; gitignore.url = "github:hercules-ci/gitignore.nix"; gitignore.inputs.nixpkgs.follows = "nixpkgs"; - pgx.url = "github:zombodb/pgx/develop"; + pgx.url = "github:zombodb/pgx"; pgx.inputs.nixpkgs.follows = "nixpkgs"; pgx.inputs.naersk.follows = "naersk"; }; @@ -17,55 +17,21 @@ outputs = { self, nixpkgs, rust-overlay, naersk, gitignore, pgx }: let cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); - supportedPostgresVersions = [ 10 11 12 13 14 ]; in { inherit (pgx) devShell; - defaultPackage = forAllSystems (system: (import nixpkgs { - inherit system; - overlays = [ pgx.overlay self.overlay ]; - })."${cargoToml.package.name}"); + defaultPackage = pgx.lib.forAllSystems (system: + let + pkgs = pgx.lib.nixpkgsWithOverlays { inherit system nixpkgs; extraOverlays = [ self.overlay ]; }; + in + pkgs."${cargoToml.package.name}"); - packages = forAllSystems (system: + packages = pgx.lib.forAllSystems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlay - pgx.overlay - rust-overlay.overlay - (self: super: - { - rustc = self.rust-bin.stable.latest.rustc; - cargo = self.rust-bin.stable.latest.cargo; - } - ) - ]; - }; + pkgs = pgx.lib.nixpkgsWithOverlays { inherit system nixpkgs; extraOverlays = [ self.overlay ]; }; in - { - "${cargoToml.package.name}" = pkgs."${cargoToml.package.name}"; - "${cargoToml.package.name}_debug" = pkgs."${cargoToml.package.name}_debug"; - "${cargoToml.package.name}_all" = pkgs.runCommandNoCC "allVersions" { } '' - mkdir -p $out - cp -r ${pkgs."${cargoToml.package.name}_10"} $out/${cargoToml.package.name}_10 - cp -r ${pkgs."${cargoToml.package.name}_11"} $out/${cargoToml.package.name}_11 - cp -r ${pkgs."${cargoToml.package.name}_12"} $out/${cargoToml.package.name}_12 - cp -r ${pkgs."${cargoToml.package.name}_13"} $out/${cargoToml.package.name}_13 - cp -r ${pkgs."${cargoToml.package.name}_14"} $out/${cargoToml.package.name}_14 - ''; - "${cargoToml.package.name}_all_debug" = pkgs.runCommandNoCC "allVersions" { } '' - mkdir -p $out - cp -r ${pkgs."${cargoToml.package.name}_10_debug"} $out/${cargoToml.package.name}_10 - cp -r ${pkgs."${cargoToml.package.name}_11_debug"} $out/${cargoToml.package.name}_11 - cp -r ${pkgs."${cargoToml.package.name}_12_debug"} $out/${cargoToml.package.name}_12 - cp -r ${pkgs."${cargoToml.package.name}_13_debug"} $out/${cargoToml.package.name}_13 - cp -r ${pkgs."${cargoToml.package.name}_14_debug"} $out/${cargoToml.package.name}_14 - ''; - } // (nixpkgs.lib.foldl' + (nixpkgs.lib.foldl' (x: y: x // y) { } (map @@ -75,18 +41,20 @@ "${cargoToml.package.name}_${versionString}" = pkgs."${cargoToml.package.name}_${versionString}"; "${cargoToml.package.name}_${versionString}_debug" = pkgs."${cargoToml.package.name}_${versionString}_debug"; }) - supportedPostgresVersions) + pgx.lib.supportedPostgresVersions) )); overlay = final: prev: { - "${cargoToml.package.name}" = final.callPackage ./. { - inherit naersk; - gitignoreSource = gitignore.lib.gitignoreSource; + "${cargoToml.package.name}" = pgx.lib.buildPgxExtension { + pkgs = final; + source = ./.; + pgxPostgresVersion = 11; }; - "${cargoToml.package.name}_debug" = final.callPackage ./. { - inherit naersk; + "${cargoToml.package.name}_debug" = pgx.lib.buildPgxExtension { + pkgs = final; + source = ./.; + pgxPostgresVersion = 11; release = false; - gitignoreSource = gitignore.lib.gitignoreSource; }; } // (nixpkgs.lib.foldl' (x: y: x // y) @@ -95,19 +63,19 @@ (version: let versionString = builtins.toString version; in { - "${cargoToml.package.name}_${versionString}" = final.callPackage ./. { - inherit naersk; + "${cargoToml.package.name}_${versionString}" = pgx.lib.buildPgxExtension { + pkgs = final; + source = ./.; pgxPostgresVersion = version; - gitignoreSource = gitignore.lib.gitignoreSource; }; - "${cargoToml.package.name}_${versionString}_debug" = final.callPackage ./. { - inherit naersk; - release = false; + "${cargoToml.package.name}_${versionString}_debug" = pgx.lib.buildPgxExtension { + pkgs = final; + source = ./.; pgxPostgresVersion = version; - gitignoreSource = gitignore.lib.gitignoreSource; + release = false; }; }) - supportedPostgresVersions) + pgx.lib.supportedPostgresVersions) ); nixosModule = { config, pkgs, lib, ... }: @@ -127,22 +95,9 @@ }; }; - checks = forAllSystems (system: + checks = pgx.lib.forAllSystems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlay - pgx.overlay - rust-overlay.overlay - (self: super: - { - rustc = self.rust-bin.stable.latest.rustc; - cargo = self.rust-bin.stable.latest.cargo; - } - ) - ]; - }; + pkgs = pgx.lib.nixpkgsWithOverlays { inherit system nixpkgs; extraOverlays = [ self.overlay ]; }; in { format = pkgs.runCommand "check-format"