Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix build is broken (2019/11/20) #22

Open
szg251 opened this issue Dec 1, 2019 · 3 comments
Open

Nix build is broken (2019/11/20) #22

szg251 opened this issue Dec 1, 2019 · 3 comments

Comments

@szg251
Copy link

szg251 commented Dec 1, 2019

I use postgresql-typed in one of my projects. When used with stack, it works perfectly, but when I tried to migrate to nix, it seems to be broken. The package itself is marked as broken in the nixpkgs. If I ignore the warning, I get the following error message:

test/Main.hs:1:1: error:
    Exception when trying to run compile-time code:
      Network.Socket.connect: <socket: 12>: does not exist (No such file or directory)
    Code: template-haskell-2.14.0.0:Language.Haskell.TH.Quote.quoteDec
            pgSQL "!CREATE TYPE myenum AS enum ('abc', 'DEF', 'XX_ye')"
  |
1 | {-# LANGUAGE OverloadedStrings, FlexibleInstances, MultiParamTypeClasses, DataKinds, DeriveDataTypeable, TypeFamilies, PatternGuards, StandaloneDeriving #-}
  | ^

builder for '/nix/store/ghbmalyqp9511ps05f6c7mvx5d6wwpnk-postgresql-typed-0.6.1.0.drv' failed with exit code 1

My guess is that, some post build scripts need a running postgres server.

Nixpkgs rev: 58fb23f72ad916c8bbfa3c3bc2d0c83c9cfcdd16

@albertov
Copy link

albertov commented Dec 1, 2019

Your guess is right. The building and running the tests require a running postgres server. A quick workaround is to disable the package's tests in a nix overlay.

Nix is used to test postgresql-typed in CI so you can also take a look at https://github.com/dylex/postgresql-typed/blob/master/nix/default.nix and

withPostgres = pg: drv:
let functions = ''
${trapMagic}
function initPG() {
${super.lib.optionalString super.stdenv.isDarwin "export TMPDIR=/tmp"}
${super.lib.optionalString (!super.stdenv.isDarwin) "export LANG=C.UTF-8"}
${super.lib.optionalString (!super.stdenv.isDarwin) "export LC_ALL=C.UTF-8"}
${super.lib.optionalString (!super.stdenv.isDarwin) "export LC_CTYPE=C.UTF-8"}
export TZ='UTC'
export PGHOST=$(mktemp -d)
export PGDATA=$PGHOST/db
export PGPORT=5433
export PGSOCK=$PGHOST/.s.PGSQL.$PGPORT
export PGDATABASE=templatepg
export PGUSER=templatepg
# We set these environment variables so postgresql-typed knows how
# to connect to the database at compile-time to make sure all SQL
# queries are well typed and well formed
export TPG_SOCK=$PGSOCK
export TPG_DB=$PGDATABASE
export TPG_USER=$PGUSER
#
${pg}/bin/initdb -E UTF8 $PGDATA
# avoid conflicts on travis and elsewhere
echo "port = $PGPORT" >> $PGDATA/postgresql.conf
${pg}/bin/postgres -D $PGDATA -k $PGHOST &
echo -n "Waiting for database to start up..."
while [[ ! -e $PGSOCK ]]; do sleep 0.1; done
${pg}/bin/createuser -h $PGHOST -U $(id -u --name) -s $PGUSER
${pg}/bin/createdb -h $PGHOST -O $PGUSER $PGDATABASE
echo "Created database PGDATABASE=$PGDATABASE at PGHOST=$PGHOST."
echo "Call killPG to stop and delete it. Call initPG to re-create it"
}
function killPG() {
echo "Killing postgres database at $PGHOST"
pg_ctl stop || true
echo "Waiting for postgres database to die ..."
while [[ -e $PGSOCK ]]; do sleep 0.1; done
echo "Postgres is dead, deleting its data dir"
rm -rf $PGHOST
}
function reinitPG {
killPG && initPG
}
# export the functions so they're available in the development nix-shell
# so the database can be re-created easly
export -f initPG
export -f killPG
export -f reinitPG
trap_prepend "killPG" EXIT
'';
in super.haskell.lib.overrideCabal drv (old: {
buildDepends = (old.buildDepends or []) ++ [ pg ];
preBuild = ''
${old.preBuild or ""}
${functions}
initPG
'';
shellHook = ''
${old.shellHook or ""}
${functions}
initPG
'';
postInstall = ''
killPG
${old.postInstall or ""}
'';
});
};
to see how a running postgres can be created to run the tests using Nix instead of disabling them.

@szg251
Copy link
Author

szg251 commented Dec 1, 2019

Thank you for the prompt reply. I'll try to start a postgres server with nix.

@ghost
Copy link

ghost commented Nov 14, 2020

See databrary for some notes about starting a postgres instance in nix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants