How to pass optional arguments to package in shell.nix?

I’m using liquibase as one of the buildInputs in my nix shell but am not sure how to enable the optional argument postgresqlSupport for it so that the necessary jar is available to provide the org.postgresql.Driver on the classpath for relevant commands.

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
  baseDir = "${toString ./.}";

in mkShell {
  buildInputs = [
    liquibase { postgresqlSupport = true; }  # or something like that
  shellHook = ''
    echo "Welcome ${USER} to ${baseDir}"

The above fails, of course.

error: while evaluating the attribute 'buildInputs' of the derivation 'nix-shell' at /nix/store/n5i0hscx1cknwygcfipzn6wjb7s9b5wc-nixpkgs-21.03pre259075.9cb4d2f4903/nixpkgs/pkgs/build-support/mkshell/default.nix:28:3:
cannot coerce a set to a string, at /nix/store/n5i0hscx1cknwygcfipzn6wjb7s9b5wc-nixpkgs-21.03pre259075.9cb4d2f4903/nixpkgs/pkgs/build-support/mkshell/default.nix:28:3

What’s the right way to do this? I presume using callPackage is the way to go?
What would that look like?

1 Like
{ lib, stdenv
 # things which should be modifided with override

stdenv.mkDerivation rec {
  # things which should be modified with overrideAttrs

what you want is
(liquibase.override { postgresqlSupport = true; })

$ nix-build -E 'with import ./. {}; (liquibase.override { postgresqlSupport = false; })'
$ nix-build -E 'with import ./. {}; (liquibase.override { postgresqlSupport = true; })'

Word of caution, don’t forget the parenthesis

[ liquibase.override ({ postgresqlSupport = true; }) ]
# is the same as
[ (liquibase.override)
  ({ postgresqlSupport = true; })
# a list with two elements, a function and a set.
1 Like

Thanks @jonringer ! It turns out also that my version of nixpkgs hadn’t been updated in a while and the liquibase derivation’s default support for postgresql wasn’t included in the version I had.

1 Like