From e2fb65175228a992f196f3b1700a53e18602e7f6 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 25 Mar 2023 11:34:24 +0100 Subject: [PATCH] nixos/postgresql: fix enableJIT Make sure that JIT is actually available when using services.postgresql = { enable = true; enableJIT = true; package = pkgs.postgresql_15; }; The current behavior is counter-intuitive because the docs state that `enableJIT = true;` is sufficient even though it wasn't in that case because the declared package doesn't have the LLVM dependency. Fixed by using `package.withJIT` if `enableJIT = true;` and `package.jitSupport` is `false`. Also updated the postgresql-jit test to test for that case. --- nixos/modules/services/databases/postgresql.nix | 13 +++++++++++-- nixos/tests/postgresql-jit.nix | 6 ++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index 16f76248b3a0..3d55995aba05 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -7,9 +7,18 @@ let cfg = config.services.postgresql; postgresql = + let + # ensure that + # services.postgresql = { + # enableJIT = true; + # package = pkgs.postgresql_; + # }; + # works. + base = if cfg.enableJIT && !cfg.package.jitSupport then cfg.package.withJIT else cfg.package; + in if cfg.extraPlugins == [] - then cfg.package - else cfg.package.withPackages (_: cfg.extraPlugins); + then base + else base.withPackages (_: cfg.extraPlugins); toStr = value: if true == value then "yes" diff --git a/nixos/tests/postgresql-jit.nix b/nixos/tests/postgresql-jit.nix index 21682aad96da..baf26b8da2b3 100644 --- a/nixos/tests/postgresql-jit.nix +++ b/nixos/tests/postgresql-jit.nix @@ -7,9 +7,7 @@ with import ../lib/testing-python.nix { inherit system pkgs; }; let inherit (pkgs) lib; - packages = lib.filter - (lib.hasSuffix "_jit") - (builtins.attrNames (import ../../pkgs/servers/sql/postgresql pkgs)); + packages = builtins.attrNames (import ../../pkgs/servers/sql/postgresql pkgs); mkJitTest = packageName: makeTest { name = "${packageName}"; @@ -17,8 +15,8 @@ let nodes.machine = { pkgs, lib, ... }: { services.postgresql = { enable = true; + enableJIT = true; package = pkgs.${packageName}; - settings.jit = "on"; initialScript = pkgs.writeText "init.sql" '' create table demo (id int); insert into demo (id) select generate_series(1, 5);