diff --git a/default.nix b/default.nix index e56dfbf39..3cb18c1b7 100644 --- a/default.nix +++ b/default.nix @@ -62,8 +62,10 @@ let { name = "postgresql-12"; postgresql = pkgs.postgresql_12.withPackages (p: [ p.postgis p.pg_safeupdate ]); } ]; + haskellPackages = pkgs.haskell.packages."${compiler}"; + # Dynamic derivation for PostgREST - postgrest = pkgs.lib.pipe (pkgs.haskell.packages."${compiler}".callCabal2nix name src { }) [ + postgrest = pkgs.lib.pipe (haskellPackages.callCabal2nix name src { }) [ # To allow ghc-datasize to be used. lib.disableLibraryProfiling # We are never going to use dynamic haskell libraries anyway. "Dynamic" refers to how @@ -84,9 +86,13 @@ rec { # Derivation for the PostgREST Haskell package, including the executable, # libraries and documentation. We disable running the test suite on Nix - # builds, as they require a database to be set up. - postgrestPackage = - lib.dontCheck postgrest; + # builds, as they require a database to be set up. We split the binary + # into a separate output, so that the default distribution via flake.nix + # has a much smaller closure size. + postgrestPackage = pkgs.lib.pipe postgrest [ + lib.dontCheck + lib.enableSeparateBinOutput + ]; # Profiled dynamic executable. postgrestProfiled = pkgs.lib.pipe postgrestPackage [ diff --git a/flake.nix b/flake.nix index 24f4c50f2..16ccc1d80 100644 --- a/flake.nix +++ b/flake.nix @@ -33,8 +33,8 @@ in { packages = genSystems (attrs: { - default = attrs.postgrestPackage; - profiled = attrs.postgrestProfiled; + default = attrs.postgrestPackage.bin; + profiled = attrs.postgrestProfiled.bin; } // nixpkgs.lib.optionalAttrs (attrs ? postgrestStatic) { static = attrs.postgrestStatic; }); @@ -42,7 +42,7 @@ apps = genSystems (attrs: { default = { type = "app"; - program = "${attrs.postgrestStatic or attrs.postgrestPackage}/bin/postgrest"; + program = "${attrs.postgrestStatic or attrs.postgrestPackage.bin}/bin/postgrest"; meta.description = "REST API for any Postgres database"; }; }); diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index f11f92d40..82de1e4d6 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -351,12 +351,13 @@ let rm -f result if [ -z "''${PGRST_BUILD_CABAL:-}" ]; then echo -n "Building postgrest (nix)... " - nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || { + # Using lib.getBin to also make this work with older checkouts, where .bin was not a thing, yet. + nix-build -E 'with import ./. {}; pkgs.lib.getBin postgrestPackage' > "$tmpdir"/build.log 2>&1 || { echo "failed, output:" cat "$tmpdir"/build.log exit 1 } - PGRST_CMD=./result/bin/postgrest + PGRST_CMD=$(echo ./result*/bin/postgrest) else echo -n "Building postgrest (cabal)... " postgrest-build