[Nix-dev] Depending on a service from inside an expression?

Tomas Hlavaty tomas.hlavaty at knowledgetools.de
Tue Apr 28 15:58:01 CEST 2015


Hi Mateusz,

Mateusz Kowalczyk <fuuzetsu at fuuzetsu.co.uk> writes:
> There is a project that as part of its tests has to create a postgresql
> database which means that the postgres server needs to be running.
>
> Is there an easy way to achieve this? How does one go about testing such
> packages to begin with?

I am currently setting something like that (hydra tests) for a nix
module (a systemd service) which requires postgresql.  What works for
me:

1) a nix package file for your program (say foo) so that your program
   compiles and installs

2) a nix env file (say fooEnv) for runtime-only dependencies (not
   detected by nix) which will be deployed as part of the service
   (because there is a limit on the PATH variable length)

3) a nix module file which defines the systemd service.  I have two
   modules:

   - foo-init which takes a long time to set up the database and other
     things

   - foo-service which is the actual service running the foo program

4) a nix vm file which defines a VM with that module plus postgresql
   module.  This is also useful for manually testing the VM.

5) a nix vmtest file which imports nixpkgs/nixos/tests/make-test.nix,
   creates the VM and runs the testScript

If your program doesn't run as a service, you would not need 3) I guess.

nixpkgs/nixos/tests/make-test.nix runs the tests in a fresh qemu machine
which is then discarded.

Cheers,

Tomas


More information about the nix-dev mailing list