1{ pkgs, lib, ... }:
2{
3 name = "nixseparatedebuginfod2";
4 # A binary cache with debug info and source for gnumake
5 nodes.cache =
6 { pkgs, ... }:
7 {
8 services.nginx = {
9 enable = true;
10 virtualHosts.default = {
11 default = true;
12 addSSL = false;
13 root = "/var/lib/thebinarycache";
14 };
15 };
16 networking.firewall.allowedTCPPorts = [ 80 ];
17 systemd.services.buildthebinarycache = {
18 before = [ "nginx.service" ];
19 wantedBy = [ "nginx.service" ];
20 script = ''
21 ${pkgs.nix}/bin/nix --extra-experimental-features nix-command copy --to file:///var/lib/thebinarycache?index-debug-info=true ${pkgs.gnumake.debug} ${pkgs.gnumake} ${pkgs.gnumake.src} ${pkgs.sl}
22 '';
23 serviceConfig = {
24 User = "nginx";
25 Group = "nginx";
26 StateDirectory = "thebinarycache";
27 Type = "oneshot";
28 };
29 };
30 };
31 # the machine where we need the debuginfo
32 nodes.machine = {
33 services.nixseparatedebuginfod2 = {
34 enable = true;
35 substituter = "http://cache";
36 };
37 environment.systemPackages = [
38 pkgs.valgrind
39 pkgs.gdb
40 pkgs.gnumake
41 ];
42 };
43 testScript = ''
44 start_all()
45 cache.wait_for_unit("nginx.service")
46 cache.wait_for_open_port(80)
47 machine.wait_for_unit("nixseparatedebuginfod2.service")
48 machine.wait_for_open_port(1950)
49
50 with subtest("check that the binary cache works"):
51 machine.succeed("nix-store --extra-substituters http://cache --option require-sigs false -r ${pkgs.sl}")
52
53 # test debuginfod-find
54 machine.succeed("debuginfod-find debuginfo /run/current-system/sw/bin/make")
55
56 # test that gdb can fetch source
57 out = machine.succeed("gdb /run/current-system/sw/bin/make --batch -x ${builtins.toFile "commands" ''
58 start
59 l
60 ''}")
61 print(out)
62 assert 'main (int argc, char **argv, char **envp)' in out
63
64 # test that valgrind can display location information
65 # this relies on the fact that valgrind complains about gnumake
66 # because we also ask valgrind to show leak kinds
67 # which are usually false positives.
68 out = machine.succeed("valgrind --leak-check=full --show-leak-kinds=all make --version 2>&1")
69 print(out)
70 assert 'main.c' in out
71 '';
72}