This adds a CI job to run our latest postgrest version against the NixOS VM test currently available in Nixpkgs. Now, this will not always be in sync, so has the potential to be failing. However, since the Nixpkgs VM test is really simple, this should only happen when we introduce a breaking change on a very fundamental level. The failing test will then be resolved once the new version is available in Nixpkgs and we have updated our lock file. This is essentially just a sanity check to make sure we're not breaking something fundamentally - and if we do, it's a head up for me to adjust the Nixpkgs tests accordingly. Those might otherwise break unnoticed since Nixpkgs does not have a good notification system for such breakages in place. We do use the chance to run the static executable in this test, which was previously not tested at all. It also gives us a first test whether NixOS VM tests work well in GitHub Actions.
179 lines
5.8 KiB
Nix
179 lines
5.8 KiB
Nix
{ system ? builtins.currentSystem
|
|
|
|
, compiler ? "ghc9123"
|
|
|
|
, # Commit of the Nixpkgs repository that we want to use.
|
|
# It defaults to reading the inputs from flake.lock, which serves
|
|
# as a compatibility layer for non-flake builds / default.nix / shell.nix.
|
|
nixpkgsVersion ? let
|
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
|
in
|
|
{
|
|
inherit (lock.nodes.nixpkgs.locked) owner repo rev;
|
|
tarballHash = lock.nodes.nixpkgs.locked.narHash;
|
|
}
|
|
|
|
, # Nix files that describe the Nixpkgs repository. We evaluate the expression
|
|
# using `import` below.
|
|
nixpkgs ? let inherit (nixpkgsVersion) owner repo rev tarballHash; in
|
|
builtins.fetchTarball {
|
|
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
|
sha256 = tarballHash;
|
|
}
|
|
}:
|
|
|
|
let
|
|
name =
|
|
"postgrest";
|
|
|
|
# PostgREST source files, filtered based on the rules in the .gitignore files
|
|
# and file extensions. We want to include as little as possible, as the files
|
|
# added here will increase the space used in the Nix store and trigger the
|
|
# build of new Nix derivations when changed.
|
|
src =
|
|
pkgs.lib.sourceFilesBySuffices
|
|
(pkgs.gitignoreSource ./.)
|
|
[ ".cabal" ".hs" ".lhs" "LICENSE" ];
|
|
|
|
allOverlays =
|
|
import nix/overlays;
|
|
|
|
overlays =
|
|
[
|
|
allOverlays.build-toolbox
|
|
allOverlays.checked-shell-script
|
|
allOverlays.gitignore
|
|
(allOverlays.haskell-packages { inherit compiler; })
|
|
];
|
|
|
|
# Evaluated expression of the Nixpkgs repository.
|
|
pkgs =
|
|
import nixpkgs { inherit overlays system; };
|
|
|
|
postgresqlVersions =
|
|
[
|
|
{ name = "pg-18"; postgresql = pkgs.postgresql_18.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
|
|
{ name = "pg-17"; postgresql = pkgs.postgresql_17.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
|
|
{ name = "pg-16"; postgresql = pkgs.postgresql_16.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
|
|
{ name = "pg-15"; postgresql = pkgs.postgresql_15.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
|
|
{ name = "pg-14"; postgresql = pkgs.postgresql_14.withPackages (p: [ p.postgis p.pg_safeupdate ]); }
|
|
];
|
|
|
|
haskellPackages = pkgs.haskell.packages."${compiler}";
|
|
|
|
# Dynamic derivation for PostgREST
|
|
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
|
|
# non-haskell deps are linked. All haskell dependencies are always statically linked.
|
|
lib.disableSharedLibraries
|
|
];
|
|
|
|
staticHaskellPackage = import nix/static.nix { inherit compiler name pkgs src; };
|
|
|
|
# Options passed to cabal in dev tools and tests
|
|
devCabalOptions =
|
|
"-f dev --test-show-detail=direct";
|
|
|
|
inherit (pkgs.haskell) lib;
|
|
|
|
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
|
runTest = postgrest: test: (nixos-lib.runTest {
|
|
hostPkgs = pkgs;
|
|
# Replace the top-level `pkgs.postgrest` attribute with our current version on this branch.
|
|
defaults.nixpkgs.overlays = [ (_: _: { inherit postgrest; }) ];
|
|
# Speeds up evaluation a little bit; documentation is really not required for tests.
|
|
defaults.documentation.enable = pkgs.lib.mkDefault false;
|
|
imports = [ test ];
|
|
}).config.result;
|
|
in
|
|
rec {
|
|
inherit nixpkgs pkgs;
|
|
|
|
# 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. 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
|
|
(haskellPackages.generateOptparseApplicativeCompletions [ "postgrest" ])
|
|
];
|
|
|
|
# Profiled dynamic executable.
|
|
postgrestProfiled = pkgs.lib.pipe postgrestPackage [
|
|
lib.enableExecutableProfiling
|
|
lib.enableLibraryProfiling
|
|
lib.dontHaddock
|
|
];
|
|
|
|
inherit (postgrest) env;
|
|
|
|
# Tooling for analyzing Haskell imports and exports.
|
|
hsie =
|
|
pkgs.callPackage nix/hsie {
|
|
inherit (pkgs.haskell.packages."${compiler}") ghcWithPackages;
|
|
};
|
|
|
|
# Used by CI on MacOS
|
|
inherit (pkgs) nix-build-uncached;
|
|
|
|
### Tools
|
|
|
|
cabalTools =
|
|
pkgs.callPackage nix/tools/cabalTools.nix { inherit devCabalOptions postgrest; };
|
|
|
|
withTools =
|
|
pkgs.callPackage nix/tools/withTools.nix { inherit postgresqlVersions postgrest; };
|
|
|
|
# Development tools.
|
|
devTools =
|
|
pkgs.callPackage nix/tools/devTools.nix { inherit tests style devCabalOptions hsie withTools; };
|
|
|
|
# Documentation tools.
|
|
docs =
|
|
pkgs.callPackage nix/tools/docs.nix { };
|
|
|
|
# Git tools.
|
|
gitTools =
|
|
pkgs.callPackage nix/tools/gitTools.nix { };
|
|
|
|
# Load testing tools.
|
|
loadtest =
|
|
pkgs.callPackage nix/tools/loadtest.nix { inherit withTools; };
|
|
|
|
# Utility for updating the pinned version of Nixpkgs.
|
|
nixpkgsTools =
|
|
pkgs.callPackage nix/tools/nixpkgsTools.nix { };
|
|
|
|
# Scripts for publishing new releases.
|
|
release =
|
|
pkgs.callPackage nix/tools/release.nix { };
|
|
|
|
# Linting and styling tools.
|
|
style =
|
|
pkgs.callPackage nix/tools/style.nix { inherit hsie; };
|
|
|
|
# Scripts for running tests.
|
|
tests =
|
|
pkgs.callPackage nix/tools/tests.nix {
|
|
inherit postgrest devCabalOptions withTools;
|
|
ghc = pkgs.haskell.compiler."${compiler}";
|
|
inherit (pkgs.haskell.packages."${compiler}") hpc-codecov;
|
|
inherit (pkgs.haskell.packages."${compiler}") weeder;
|
|
};
|
|
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux rec {
|
|
# Static executable.
|
|
inherit (staticHaskellPackage) postgrestStatic;
|
|
inherit (staticHaskellPackage) packagesStatic;
|
|
|
|
# Docker images and loading script.
|
|
docker =
|
|
pkgs.callPackage nix/tools/docker { postgrest = postgrestStatic; };
|
|
|
|
# NixOS VM tests
|
|
nixpkgs-nixos-test = runTest postgrestStatic (pkgs.path + "/nixos/tests/postgrest.nix");
|
|
}
|