It seems that there is no split in the derivation.
You can just add the postgresql derivation to environment.systemPackages (or wherever you need it) and the psql command should be available.
When I install postgresql into environment.systemPackages it also starts a postgres server daemon that I don’t want installer nor running since I use containers.
I’d rather just install the postgres-client so that I can connect to my containers etc.
I was hoping that since a couple of years had passed that potentially there was a solution already
Nobbz’s looks like the best but was hoping for something as simple as just adding a package like postgresql-client
Correct. Whenever you install anything via environment.systemPackages there is no possible way for a daemon to start. This will never happen and is useful for you to know. Often times people new to NixOS wonder why a service isn’t running after they installed it via environment.systemPackages, not realizing they need to “install” it via services.FOO.enable = true;.
The only downside to not having the client and server split is the space used but as postgresql_14 currently takes up around 25mb, that’s really not an issue at all which is why nobody has put in the effort to split the 2.
Apologies for the necropoast … but how about the use case where I’m using Nix to build a Docker image and I want to include psql (client) but not the postgres server?
but how about the use case where I’m using Nix to build a Docker image and I want to include psql (client) but not the postgres server?
I’d like to do the same thing. Currently the runtime closure postgresql package is over 300MB, while I can find an pure psql image on docker hub under 10MB
And it’s extensible!! You can use dockerTools.streamLayeredImage (or some equivalent) to layer images on top of each-other using the baseImage argument.
So in this case:
{
pkgs ? import <nixpkgs> {},
name ? "psql-client",
version ? "0.0.0",
# TODO supply some derivation that uses `psql` in ./script.nix
server ? pkgs.callPackage ./script.nix { inherit pkgs; }
}: let
baseImage = pkgs.dockerTools.pullImage {
# variables to update base image found using:
# xdg-open https://hub.docker.com/r/jbergknoff/postgresql-client/tags
# nix-shell -p nix-prefetch-docker
# nix-prefetch-docker --quiet --image-name jbergknoff/postgresql-client --image-tag latest --image-digest sha256:45e175ebb700cfd46e23a610477c3576550055ef40c394e663623946a5eced39
imageName = "jbergknoff/postgresql-client";
imageDigest = "sha256:45e175ebb700cfd46e23a610477c3576550055ef40c394e663623946a5eced39";
finalImageName = "postgresql-client";
finalImageTag = "latest";
sha256 = "0vxmbsi725yxa1i8ysl3scbsnf6shqvhf104i3phwnkkqp6sfk68";
os = "linux";
arch = "amd64";
};
in pkgs.dockerTools.streamLayeredImage {
name = "${name}-script-image";
tag = version;
inherit tag;
fromImage = baseImage;
contents = [ script ];
config = {
# your script can call psql
Cmd = [ "${pkgs.lib.getExe script}" ];
ExposedPorts = {
"5432/tcp" = {};
};
};
}