1 # Testing out the substitute server with two machines in a local network. As a
2 # bonus, we'll also test a feature of the substitute server being able to
3 # advertise its service to the local network with Avahi.
5 import ../make-test-python.nix ({ pkgs, lib, ... }: let
7 inherit (builtins) toString;
11 meta.maintainers = with lib.maintainers; [ foo-dogsquared ];
14 commonConfig = { config, ... }: {
15 # We'll be using '--advertise' flag with the
16 # substitute server which requires Avahi.
27 server = { config, lib, pkgs, ... }: {
28 imports = [ commonConfig ];
36 generateKeyPair = true;
37 extraArgs = [ "--advertise" ];
41 networking.firewall.allowedTCPPorts = [ publishPort ];
44 client = { config, lib, pkgs, ... }: {
45 imports = [ commonConfig ];
51 # Force to only get all substitutes from the local server. We don't
52 # have anything in the Guix store directory and we cannot get
53 # anything from the official substitute servers anyways.
54 "--substitute-urls='http://server.local:${toString publishPort}'"
56 # Enable autodiscovery of the substitute servers in the local
57 # network. This machine shouldn't need to import the signing key from
58 # the substitute server since it is automatically done anyways.
70 scripts_dir = pathlib.Path("/etc/guix/scripts")
72 for machine in machines:
73 machine.wait_for_unit("multi-user.target")
74 machine.wait_for_unit("guix-daemon.service")
75 machine.wait_for_unit("avahi-daemon.service")
77 server.wait_for_unit("guix-publish.service")
78 server.wait_for_open_port(${toString publishPort})
79 server.succeed("curl http://localhost:${toString publishPort}/")
81 # Now it's the client turn to make use of it.
82 substitute_server = "http://server.local:${toString publishPort}"
83 client.systemctl("start network-online.target")
84 client.wait_for_unit("network-online.target")
85 response = client.succeed(f"curl {substitute_server}")
86 assert "Guix Substitute Server" in response
88 # Authorizing the server to be used as a substitute server.
89 client.succeed(f"curl -O {substitute_server}/signing-key.pub")
90 client.succeed("guix archive --authorize < ./signing-key.pub")
92 # Since we're using the substitute server with the `--advertise` flag, we
93 # might as well check it.
94 client.succeed("avahi-browse --resolve --terminate _guix_publish._tcp | grep '_guix_publish._tcp'")