mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-15 05:59:17 +03:00
postgresql: pass through JIT-enabled variant of non-JIT postgres and vice versa
This is useful if your postgresql version is dependant on `system.stateVersion` and not pinned down manually. Then it's not necessary to find out which version exactly is in use and define `package` manually, but just stay with what NixOS provides as default: $ nix-instantiate -A postgresql /nix/store/82fzmb77mz2b787dgj7mn4a8i4f6l6sn-postgresql-14.7.drv $ nix-instantiate -A postgresql_jit /nix/store/qsjkb72fcrrfpsszrwbsi9q9wgp39m50-postgresql-14.7.drv $ nix-instantiate -A postgresql.withJIT /nix/store/qsjkb72fcrrfpsszrwbsi9q9wgp39m50-postgresql-14.7.drv $ nix-instantiate -A postgresql.withJIT.withoutJIT /nix/store/82fzmb77mz2b787dgj7mn4a8i4f6l6sn-postgresql-14.7.drv I.e. you can use postgresql with JIT (for complex queries only[1]) like this: services.postgresql = { enable = true; enableJIT = true; }; Performing a new override instead of re-using the `_jit`-variants for that has the nice property that overlays for the original package apply to the JIT-enabled variant, i.e. with import ./. { overlays = [ (self: super: { postgresql = super.postgresql.overrideAttrs (_: { fnord = "snens"; }); }) ]; }; postgresql.withJIT.fnord still gives the string `snens` whereas `postgresql_jit` doesn't have the attribute `fnord` in its derivation. [1] https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-JIT-ABOVE-COST
This commit is contained in:
parent
2282fa73a1
commit
43dbeae02d
4 changed files with 57 additions and 8 deletions
|
@ -42,6 +42,8 @@ in
|
|||
|
||||
enable = mkEnableOption (lib.mdDoc "PostgreSQL Server");
|
||||
|
||||
enableJIT = mkEnableOption (lib.mdDoc "JIT support");
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
example = literalExpression "pkgs.postgresql_11";
|
||||
|
@ -435,19 +437,21 @@ in
|
|||
log_line_prefix = cfg.logLinePrefix;
|
||||
listen_addresses = if cfg.enableTCPIP then "*" else "localhost";
|
||||
port = cfg.port;
|
||||
jit = mkDefault (if cfg.enableJIT then "on" else "off");
|
||||
};
|
||||
|
||||
services.postgresql.package = let
|
||||
mkThrow = ver: throw "postgresql_${ver} was removed, please upgrade your postgresql version.";
|
||||
base = if versionAtLeast config.system.stateVersion "22.05" then pkgs.postgresql_14
|
||||
else if versionAtLeast config.system.stateVersion "21.11" then pkgs.postgresql_13
|
||||
else if versionAtLeast config.system.stateVersion "20.03" then pkgs.postgresql_11
|
||||
else if versionAtLeast config.system.stateVersion "17.09" then mkThrow "9_6"
|
||||
else mkThrow "9_5";
|
||||
in
|
||||
# Note: when changing the default, make it conditional on
|
||||
# ‘system.stateVersion’ to maintain compatibility with existing
|
||||
# systems!
|
||||
mkDefault (if versionAtLeast config.system.stateVersion "22.05" then pkgs.postgresql_14
|
||||
else if versionAtLeast config.system.stateVersion "21.11" then pkgs.postgresql_13
|
||||
else if versionAtLeast config.system.stateVersion "20.03" then pkgs.postgresql_11
|
||||
else if versionAtLeast config.system.stateVersion "17.09" then mkThrow "9_6"
|
||||
else mkThrow "9_5");
|
||||
mkDefault (if cfg.enableJIT then base.withJIT else base);
|
||||
|
||||
services.postgresql.dataDir = mkDefault "/var/lib/postgresql/${cfg.package.psqlSchema}";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue