From 9568c4605a04c291ab76756bcc0ea373ff4e98cf Mon Sep 17 00:00:00 2001 From: monacoremo <59358383+monacoremo@users.noreply.github.com> Date: Mon, 12 Jul 2021 12:53:00 +0200 Subject: [PATCH] nix: Update nixpkgs and static-haskell-nix --- default.nix | 3 +- nix/nixpkgs-version.nix | 8 ++-- nix/overlays/default.nix | 1 + nix/overlays/postgresql-legacy.nix | 20 +++++++++ nix/patches/default.nix | 12 ------ nix/patches/nixpkgs-gdb-fix-libintl.patch | 31 ------------- ...untime-dependencies-of-static-builds.patch | 43 +++++++------------ ...ql-notifications-openssl-linking-fix.patch | 28 ------------ ...ll-nix-postgrest-openssl-linking-fix.patch | 25 ----------- nix/static-haskell-package.nix | 11 ++--- postgrest.cabal | 2 +- src/PostgREST/OpenAPI.hs | 2 +- src/PostgREST/Request/ApiRequest.hs | 4 +- src/PostgREST/Request/DbRequestBuilder.hs | 3 +- test/io-tests/test_io.py | 2 +- 15 files changed, 52 insertions(+), 143 deletions(-) create mode 100644 nix/overlays/postgresql-legacy.nix delete mode 100644 nix/patches/nixpkgs-gdb-fix-libintl.patch delete mode 100644 nix/patches/static-haskell-nix-hasql-notifications-openssl-linking-fix.patch delete mode 100644 nix/patches/static-haskell-nix-postgrest-openssl-linking-fix.patch diff --git a/default.nix b/default.nix index 662c89c8c..1ea7b9af9 100644 --- a/default.nix +++ b/default.nix @@ -36,6 +36,7 @@ let allOverlays.ghr allOverlays.gitignore allOverlays.postgresql-default + allOverlays.postgresql-legacy (allOverlays.haskell-packages { inherit compiler; }) ]; @@ -92,7 +93,7 @@ rec { # Static executable. postgrestStatic = - lib.justStaticExecutables (lib.dontCheck (staticHaskellPackage name src)); + lib.doStrip (lib.justStaticExecutables (lib.dontCheck (staticHaskellPackage name src))); # Profiled dynamic executable. postgrestProfiled = diff --git a/nix/nixpkgs-version.nix b/nix/nixpkgs-version.nix index 817e1fe44..b02cf0fd9 100644 --- a/nix/nixpkgs-version.nix +++ b/nix/nixpkgs-version.nix @@ -1,6 +1,6 @@ -# Pinned version of Nixpkgs, generated with nixpkgs-upgrade. +# Pinned version of Nixpkgs, generated with postgrest-nixpkgs-upgrade. { - date = "2020-12-22"; - rev = "2a058487cb7a50e7650f1657ee0151a19c59ec3b"; - tarballHash = "1h8c0mk6jlxdmjqch6ckj30pax3hqh6kwjlvp2021x3z4pdzrn9p"; + date = "2021-07-12"; + rev = "c114cd459e1bac0d05e4e27c9ea43c99799cbbd1"; + tarballHash = "1hpspw8jbzq03k8a6izxnbqww42mihqaa6c8nszw30igiaqc98i2"; } diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix index 8ad1f714b..431636d9c 100644 --- a/nix/overlays/default.nix +++ b/nix/overlays/default.nix @@ -5,4 +5,5 @@ gitignore = import ./gitignore.nix; haskell-packages = import ./haskell-packages.nix; postgresql-default = import ./postgresql-default.nix; + postgresql-legacy = import ./postgresql-legacy.nix; } diff --git a/nix/overlays/postgresql-legacy.nix b/nix/overlays/postgresql-legacy.nix new file mode 100644 index 000000000..fe7034c41 --- /dev/null +++ b/nix/overlays/postgresql-legacy.nix @@ -0,0 +1,20 @@ +self: super: +# Overlay that adds legacy versions of PostgreSQL that are supported by +# PostgREST. +{ + # PostgreSQL 9.5 was removed from Nixpkgs with + # https://github.com/NixOS/nixpkgs/commit/72ab382fb6b729b0d654f2c03f5eb25b39f11fbb + # We pin its parent commit to get the last version that was available. + postgresql_9_5 = + let + rev = "55ac7d4580c9ab67848c98cb9519317a1cc399c8"; + tarballHash = "02ffj9f8s1hwhmxj85nx04sv64qb6jm7w0122a1dz9n32fymgklj"; + + pinnedPkgs = + builtins.fetchTarball { + url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz"; + sha256 = tarballHash; + }; + in + (import pinnedPkgs { }).pkgs.postgresql_9_5; +} diff --git a/nix/patches/default.nix b/nix/patches/default.nix index edc76a73d..9c9109cd8 100644 --- a/nix/patches/default.nix +++ b/nix/patches/default.nix @@ -21,16 +21,4 @@ # See: https://github.com/NixOS/nixpkgs/pull/87879 nixpkgs-openssl-split-runtime-dependencies-of-static-builds = ./nixpkgs-openssl-split-runtime-dependencies-of-static-builds.patch; - - # See: https://github.com/NixOS/nixpkgs/issues/104133 - nixpkgs-gdb-fix-libintl = - ./nixpkgs-gdb-fix-libintl.patch; - - # Fix how openssl is linked on static builds, see: - # https://github.com/nh2/static-haskell-nix/pull/91 - static-haskell-nix-postgrest-openssl-linking-fix = - ./static-haskell-nix-postgrest-openssl-linking-fix.patch; - - static-haskell-nix-hasql-notifications-openssl-linking-fix = - ./static-haskell-nix-hasql-notifications-openssl-linking-fix.patch; } diff --git a/nix/patches/nixpkgs-gdb-fix-libintl.patch b/nix/patches/nixpkgs-gdb-fix-libintl.patch deleted file mode 100644 index b38ed9b65..000000000 --- a/nix/patches/nixpkgs-gdb-fix-libintl.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 37cafab49907880838f777b068e9634d5206f61f Mon Sep 17 00:00:00 2001 -From: monacoremo <59358383+monacoremo@users.noreply.github.com> -Date: Tue, 22 Dec 2020 14:43:41 +0100 -Subject: [PATCH] Revert "gdb: 9.2 -> 10.1" - -This reverts commit 6d2cad8a4ed76e42407546bc6b4c717fd9e1a535. ---- - pkgs/development/tools/misc/gdb/default.nix | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/pkgs/development/tools/misc/gdb/default.nix b/pkgs/development/tools/misc/gdb/default.nix -index d9bac6e3c83..a4806634432 100644 ---- a/pkgs/development/tools/misc/gdb/default.nix -+++ b/pkgs/development/tools/misc/gdb/default.nix -@@ -26,11 +26,11 @@ assert pythonSupport -> python3 != null; - - stdenv.mkDerivation rec { - pname = targetPrefix + basename; -- version = "10.1"; -+ version = "9.2"; - - src = fetchurl { - url = "mirror://gnu/gdb/${basename}-${version}.tar.xz"; -- sha256 = "1h32dckz1y8fnyxh22iyw8h3hnhxr79v1ng85px3ljn1xv71wbzq"; -+ sha256 = "0mf5fn8v937qwnal4ykn3ji1y2sxk0fa1yfqi679hxmpg6pdf31n"; - }; - - postPatch = if stdenv.isDarwin then '' --- -2.28.0 - diff --git a/nix/patches/nixpkgs-openssl-split-runtime-dependencies-of-static-builds.patch b/nix/patches/nixpkgs-openssl-split-runtime-dependencies-of-static-builds.patch index bf5f61438..43b58f8d6 100644 --- a/nix/patches/nixpkgs-openssl-split-runtime-dependencies-of-static-builds.patch +++ b/nix/patches/nixpkgs-openssl-split-runtime-dependencies-of-static-builds.patch @@ -1,18 +1,8 @@ -From 2aabdaca408d22ce2b6aa078ba58a115f5bd7fe4 Mon Sep 17 00:00:00 2001 -From: Remo -Date: Fri, 15 May 2020 10:13:43 +0200 -Subject: [PATCH] openssl: split runtime dependencies of static builds into a - separate output - ---- - .../development/libraries/openssl/default.nix | 38 ++++++++++++++++--- - 1 file changed, 32 insertions(+), 6 deletions(-) - diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix -index 43170f25d38..6336a060911 100644 +index d4be8cc2428..3979698711f 100644 --- a/pkgs/development/libraries/openssl/default.nix +++ b/pkgs/development/libraries/openssl/default.nix -@@ -34,9 +34,22 @@ let +@@ -50,9 +50,21 @@ let substituteInPlace crypto/async/arch/async_posix.h \ --replace '!defined(__ANDROID__) && !defined(__OpenBSD__)' \ '!defined(__ANDROID__) && !defined(__OpenBSD__) && 0' @@ -28,15 +18,14 @@ index 43170f25d38..6336a060911 100644 ''; - outputs = [ "bin" "dev" "out" "man" ] ++ optional withDocs "doc"; -+ outputs = -+ [ "bin" "dev" "out" "man" ] ++ outputs = [ "bin" "dev" "out" "man" ] + ++ optional withDocs "doc" + # Separate output for the runtime dependencies of the static build. + ++ optional static "etc"; setOutputFlags = false; - separateDebugInfo = !(stdenv.hostPlatform.useLLVM or false) && stdenv.cc.isGNU; - -@@ -72,7 +85,17 @@ let + separateDebugInfo = + !stdenv.hostPlatform.isDarwin && +@@ -101,7 +113,17 @@ let configureFlags = [ "shared" # "shared" builds both shared and static libraries "--libdir=lib" @@ -52,19 +41,20 @@ index 43170f25d38..6336a060911 100644 + # prepended to it otherwise. + "--openssldir=/.$(etc)/etc/ssl" + ) - ] ++ stdenv.lib.optionals withCryptodev [ + ] ++ lib.optionals withCryptodev [ "-DHAVE_CRYPTODEV" "-DUSE_CRYPTODEV_DIGESTS" -@@ -103,6 +126,8 @@ let +@@ -131,6 +153,9 @@ let + if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib $out/lib/*.dll)" ]; then rm "$out/lib/"*.a fi - ++ + # 'etc' is a separate output on static builds only. + etc=$out - '' + - '' - mkdir -p $bin -@@ -117,14 +142,15 @@ let + '' + lib.optionalString (!stdenv.hostPlatform.isWindows) + # Fix bin/c_rehash's perl interpreter line + # +@@ -152,14 +177,15 @@ let mv $out/include $dev/ # remove dependency on Perl at runtime @@ -75,7 +65,7 @@ index 43170f25d38..6336a060911 100644 + rmdir $etc/etc/ssl/{certs,private} ''; - postFixup = stdenv.lib.optionalString (!stdenv.hostPlatform.isWindows) '' + postFixup = lib.optionalString (!stdenv.hostPlatform.isWindows) '' - # Check to make sure the main output doesn't depend on perl - if grep -r '${buildPackages.perl}' $out; then + # Check to make sure the main output and the static runtime dependencies @@ -84,6 +74,3 @@ index 43170f25d38..6336a060911 100644 echo "Found an erroneous dependency on perl ^^^" >&2 exit 1 fi --- -2.25.1 - diff --git a/nix/patches/static-haskell-nix-hasql-notifications-openssl-linking-fix.patch b/nix/patches/static-haskell-nix-hasql-notifications-openssl-linking-fix.patch deleted file mode 100644 index d4bf09e4a..000000000 --- a/nix/patches/static-haskell-nix-hasql-notifications-openssl-linking-fix.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 49ecb703d9d0bfd38eb69ba5cb63a8262bd03f96 Mon Sep 17 00:00:00 2001 -From: steve-chavez -Date: Thu, 11 Jun 2020 13:18:07 -0500 -Subject: [PATCH] Add hasql-notifications openssl linking fix - ---- - survey/default.nix | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/survey/default.nix b/survey/default.nix -index 828beaa..9c2d5f6 100644 ---- a/survey/default.nix -+++ b/survey/default.nix -@@ -1054,6 +1054,11 @@ let - super.squeal-postgresql - [ final.openssl ] - "--libs openssl"; -+ hasql-notifications = -+ addStaticLinkerFlagsWithPkgconfig -+ super.hasql-notifications -+ [ final.openssl ] -+ "--libs openssl"; - - xml-to-json = - addStaticLinkerFlagsWithPkgconfig --- -2.19.3 - diff --git a/nix/patches/static-haskell-nix-postgrest-openssl-linking-fix.patch b/nix/patches/static-haskell-nix-postgrest-openssl-linking-fix.patch deleted file mode 100644 index 56919a73f..000000000 --- a/nix/patches/static-haskell-nix-postgrest-openssl-linking-fix.patch +++ /dev/null @@ -1,25 +0,0 @@ -From bb4c1e27e391eff01591fe60830ff68a9ada41ef Mon Sep 17 00:00:00 2001 -From: Remo -Date: Wed, 22 Apr 2020 11:58:07 +0200 -Subject: [PATCH] Add postgrest libpq linking fix - ---- - survey/default.nix | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/survey/default.nix b/survey/default.nix -index b28606c..fd7cde7 100644 ---- a/survey/default.nix -+++ b/survey/default.nix -@@ -1052,6 +1052,11 @@ let - super.squeal-postgresql - [ final.openssl ] - "--libs openssl"; -+ postgrest = -+ addStaticLinkerFlagsWithPkgconfig -+ super.postgrest -+ [ final.openssl ] -+ "--libs openssl"; - - xml-to-json = - addStaticLinkerFlagsWithPkgconfig diff --git a/nix/static-haskell-package.nix b/nix/static-haskell-package.nix index ccfd6df54..98afd4d43 100644 --- a/nix/static-haskell-package.nix +++ b/nix/static-haskell-package.nix @@ -6,19 +6,18 @@ let # The nh2/static-haskell-nix project does all the hard work for us. static-haskell-nix = let - rev = "749707fc90b781c3e653e67917a7d571fe82ae7b"; + rev = "66fce684a20451514cb68d71bcb62fb246cb2080"; in builtins.fetchTarball { url = "https://github.com/nh2/static-haskell-nix/archive/${rev}.tar.gz"; - sha256 = "155spda2lww378bhx68w6dxwqd5y6s9kin3qbgl2m23r3vmk3m3w"; + sha256 = "0322s6hpdwfyw56galvcgla97rnxd2xigcmc0pkiahzs061dcykn"; }; patched-static-haskell-nix = patches.applyPatches "patched-static-haskell-nix" static-haskell-nix [ - patches.static-haskell-nix-postgrest-openssl-linking-fix - patches.static-haskell-nix-hasql-notifications-openssl-linking-fix + # No patches currently required. ]; patchedNixpkgs = @@ -26,7 +25,6 @@ let nixpkgs [ patches.nixpkgs-openssl-split-runtime-dependencies-of-static-builds - patches.nixpkgs-gdb-fix-libintl ]; extraOverrides = @@ -36,8 +34,7 @@ let # static-haskell-nix. Using callCabal2nix on the haskellPackages that # it returns would result in a dynamic build based on musl, and not the # fully static build that we want. - "${name}" = - prev.callCabal2nix name src { }; + "${name}" = prev.callCabal2nix name src { }; }; overlays = diff --git a/postgrest.cabal b/postgrest.cabal index bf88ceb16..310fb8c2a 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -85,7 +85,7 @@ library , gitrev >= 1.2 && < 1.4 , hasql >= 1.4 && < 1.5 , hasql-dynamic-statements == 0.3.1 - , hasql-notifications >= 0.1 && < 0.2 + , hasql-notifications >= 0.1 && < 0.3 , hasql-pool >= 0.5 && < 0.6 , hasql-transaction >= 0.7.2 && < 1.1 , heredoc >= 0.2 && < 0.3 diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 5b63adbed..8530128ac 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -88,7 +88,7 @@ makeProperty rels pks c = (colName c, Inline s) Relationship{relColumns, relCardinality=M2O _} -> [c] == relColumns _ -> False ) rels - fCol = colName <$> (headMay =<< (relForeignColumns <$> rel)) + fCol = colName <$> (headMay . relForeignColumns =<< rel) fTbl = tableName . relForeignTable <$> rel fTblCol = (,) <$> fTbl <*> fCol in diff --git a/src/PostgREST/Request/ApiRequest.hs b/src/PostgREST/Request/ApiRequest.hs index dab8da1b7..dbf73bf83 100644 --- a/src/PostgREST/Request/ApiRequest.hs +++ b/src/PostgREST/Request/ApiRequest.hs @@ -377,9 +377,9 @@ userApiRequest conf@AppConfig{..} dbStructure req reqBody headerRange = rangeRequested hdrs replaceLast x s = T.intercalate "." $ L.init (T.split (=='.') s) ++ [x] limitParams :: M.HashMap ByteString NonnegRange - limitParams = M.fromList [(toS (replaceLast "limit" k), restrictRange (readMaybe =<< (toS <$> v)) allRange) | (k,v) <- qParams, isJust v, endingIn ["limit"] k] + limitParams = M.fromList [(toS (replaceLast "limit" k), restrictRange (readMaybe . toS =<< v) allRange) | (k,v) <- qParams, isJust v, endingIn ["limit"] k] offsetParams :: M.HashMap ByteString NonnegRange - offsetParams = M.fromList [(toS (replaceLast "limit" k), maybe allRange rangeGeq (readMaybe =<< (toS <$> v))) | (k,v) <- qParams, isJust v, endingIn ["offset"] k] + offsetParams = M.fromList [(toS (replaceLast "limit" k), maybe allRange rangeGeq (readMaybe . toS =<< v)) | (k,v) <- qParams, isJust v, endingIn ["offset"] k] urlRange = M.unionWith f limitParams offsetParams where diff --git a/src/PostgREST/Request/DbRequestBuilder.hs b/src/PostgREST/Request/DbRequestBuilder.hs index 17d8af81f..abd44c325 100644 --- a/src/PostgREST/Request/DbRequestBuilder.hs +++ b/src/PostgREST/Request/DbRequestBuilder.hs @@ -63,8 +63,7 @@ readRequest schema rootTableName maxRows allRels apiRequest = mapLeft ApiRequestError $ treeRestrictRange maxRows =<< augmentRequestWithJoin schema rootRels =<< - addFiltersOrdersRanges apiRequest =<< - (initReadRequest rootName <$> pRequestSelect sel) + (addFiltersOrdersRanges apiRequest . initReadRequest rootName =<< pRequestSelect sel) where sel = fromMaybe "*" $ iSelect apiRequest -- default to all columns requested (SELECT *) for a non existent ?select querystring param (rootName, rootRels) = rootWithRels schema rootTableName allRels (iAction apiRequest) diff --git a/test/io-tests/test_io.py b/test/io-tests/test_io.py index 0cc2fd528..230e10321 100644 --- a/test/io-tests/test_io.py +++ b/test/io-tests/test_io.py @@ -207,7 +207,7 @@ def authheader(token): def jwtauthheader(claim, secret): "Authorization header with signed JWT." - return authheader(jwt.encode(claim, secret).decode("utf-8")) + return authheader(jwt.encode(claim, secret)) @pytest.mark.parametrize(