This demonstrates using the integration test framework NixOS provides - even on non-NixOS** systems provided nixpkgs is installed.
** Might confuse the reader (intended for novices like me) to go into much detail here, but when running the tests a NixOS instance is indeed spawned, it's just that your host doesn't need to run NixOS on bare metal to have that.
I needed that for github-actions to run an integration test of some haskell redis client.
Without the help of a very active community this wouldn't be feasible for a nix-novice like me to name a few:
- Josef Kemetmüller had the tip that answered my question regarding running integration tests on non-NixOS https://discourse.nixos.org/t/how-can-i-spawn-a-redis-instance-within-a-nix-build/5155/7 (documentation link)
- folks at mayflower provide an easy to adapt tutorial: https://nixos.mayflower.consulting/blog/2019/07/11/leveraging-nixos-tests-in-your-project/
- not to forget: the contributors of nix
Attached are my adaptions of default.nix, server.nix and test.nix (basically a retrofitted redis.nix - link also above - using perl instead of python) from the above tutorial. The config change suggested by Josef goes to ~/.config/nix/nix.conf
BUGS
My basic goal for now is reached though there is still work to do i. e. the server host runs but the redis instance therein not yet runs:
machine# [ 123.548193] byqcih968x56v5p9k2nbn8afzph3ibs0-unit-script-redis-pre-start[673]: install: cannot change owner and permissions of ‘/var/lib/redis’: No such file or directory
machine# [ 123.969505] systemd[1]: redis.service: Control process exited, code=exited, status=1/FAILURE
machine# [ 123.996381] systemd[1]: redis.service: Failed with result 'exit-code'.
machine# [ 124.010802] systemd[1]: Failed to start Redis Server.
machine# [ 124.031742] systemd[1]: redis.service: Consumed 218ms CPU time, no IP traffic.
machine: running command: systemctl --no-pager show "redis"
machine: exit status 0
(1.36 seconds)
http://sandervanderburg.blogspot.com/2013/06/setting-up-multi-user-nix-installation.html
https://nixos.org/nix/manual/#ssec-multi-user
https://chris-martin.github.io/talks/2018-monadic-party/slides/#(14)