Created
August 11, 2025 05:30
-
-
Save izelnakri/bab7c5f6ad66e54d728f4ef280c7d62b to your computer and use it in GitHub Desktop.
Advanced multi node test/dev infrastructure on nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| description = "Advanced flake.nix for nix based development environment"; | |
| inputs.flake-utils.url = "github:numtide/flake-utils"; | |
| inputs.nixpkgs.url = "github:NixOS/nixpkgs"; | |
| outputs = { self, nixpkgs, flake-utils }: | |
| flake-utils.lib.eachDefaultSystem (system: | |
| let | |
| pkgs = import nixpkgs { system = "x86_64-linux"; }; | |
| in { | |
| # $ nix develop | |
| devShells.default = pkgs.mkShell rec { | |
| buildInputs = [ | |
| pkgs.process-compose | |
| pkgs.redis | |
| pkgs.postgresql | |
| pkgs.nginx | |
| ]; | |
| }; | |
| # $ nix build ".#" | |
| # or: $ nix run ".#" | |
| packages.default = pkgs.writeShellApplication { | |
| name = "multi-service"; | |
| runtimeInputs = [ | |
| pkgs.process-compose | |
| pkgs.redis | |
| pkgs.postgresql | |
| pkgs.nginx | |
| ]; | |
| # NOTE: Here process-compose to manage multiple processes running at the same time, I've process-compose.yml | |
| text = '' | |
| process-compose -f process-compose.yml | |
| ''; | |
| }; | |
| # $ nix run ".#checks.x86_64-linux.default" | |
| # or: $ nix run ".#checks.x86_64-linux.default.driverInteractive" # interactive control on python shell | |
| # or: $ nix flake check | |
| checks.default = pkgs.nixosTest { | |
| name = "multi-service-test"; | |
| nodes.izelsMachine = { config, pkgs, ... }: { | |
| services.redis.enable = true; | |
| services.postgresql.enable = true; | |
| services.nginx.enable = true; | |
| }; | |
| # nodes.anotherMachine = { config, pkgs, ... }: { | |
| # Here you can even have another machine with a our custom name "anotherMachine". in testScript can be | |
| # booted up with anotherMachine.succeed("someBinary") | |
| # } | |
| testScript = '' | |
| start_all() | |
| machine.wait_for_unit("redis") | |
| machine.wait_for_unit("postgresql") | |
| machine.wait_for_unit("nginx") | |
| machine.succeed("redis-cli ping") | |
| machine.succeed("psql -U postgres -c 'SELECT 1'") | |
| machine.succeed("curl -sI http://localhost | grep '200 OK'") | |
| ''; | |
| }; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment